当前位置: 首页>>代码示例>>C#>>正文


C# ProfileClient类代码示例

本文整理汇总了C#中ProfileClient的典型用法代码示例。如果您正苦于以下问题:C# ProfileClient类的具体用法?C# ProfileClient怎么用?C# ProfileClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ProfileClient类属于命名空间,在下文中一共展示了ProfileClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetClient

        internal IHDInsightClient GetClient(bool ignoreSslErrors = false)
        {
            this.CurrentSubscription.ArgumentNotNull("CurrentSubscription");

            ProfileClient client = new ProfileClient(new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)));

            var subscriptionCredentials = this.GetSubscriptionCredentials(
                this.CurrentSubscription,
                client.GetEnvironmentOrDefault(this.CurrentSubscription.Environment),
                client.Profile);

            if (this.Endpoint.IsNotNull())
            {
                subscriptionCredentials.Endpoint = this.Endpoint;               
            }

            var clientInstance = ServiceLocator.Instance.Locate<IAzureHDInsightClusterManagementClientFactory>().Create(subscriptionCredentials, ignoreSslErrors);
            clientInstance.SetCancellationSource(this.tokenSource);
            if (this.Logger.IsNotNull())
            {
                clientInstance.AddLogWriter(this.Logger);
            }

            return clientInstance;
        }
开发者ID:Azure,项目名称:azure-powershell,代码行数:25,代码来源:AzureHDInsightClusterCommandBase.cs

示例2: ClearAzureProfileClearsDefaultProfile

        public void ClearAzureProfileClearsDefaultProfile()
        {
            ClearAzureProfileCommand cmdlt = new ClearAzureProfileCommand();
            // Setup
            var profile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            AzurePSCmdlet.CurrentProfile = profile;
            ProfileClient client = new ProfileClient(profile);
            client.AddOrSetAccount(azureAccount);
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription1);
            client.Profile.Save();

            cmdlt.CommandRuntime = commandRuntimeMock;
            cmdlt.Force = new SwitchParameter(true);

            // Act
            cmdlt.InvokeBeginProcessing();
            cmdlt.ExecuteCmdlet();
            cmdlt.InvokeEndProcessing();

            // Verify
            client = new ProfileClient(new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)));
            Assert.Equal(0, client.Profile.Subscriptions.Count);
            Assert.Equal(0, client.Profile.Accounts.Count);
            Assert.Equal(2, client.Profile.Environments.Count); //only default environments
        }
开发者ID:pelagos,项目名称:azure-powershell,代码行数:26,代码来源:ProfileCmdltsTests.cs

示例3: GetClient

        internal IJobSubmissionClient GetClient(string cluster)
        {
            cluster.ArgumentNotNull("ClusterEndpoint");
            IJobSubmissionClient client = null;
            ProfileClient profileClient = new ProfileClient(new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)));

            string currentEnvironmentName = this.CurrentSubscription == null ? null : this.CurrentSubscription.Environment;

            var clientCredential = this.GetJobSubmissionClientCredentials(
                this.CurrentSubscription,
                profileClient.GetEnvironmentOrDefault(currentEnvironmentName),
                cluster,
                profileClient.Profile);
            if (clientCredential != null)
            {
                client = ServiceLocator.Instance.Locate<IAzureHDInsightJobSubmissionClientFactory>().Create(clientCredential);
                client.SetCancellationSource(this.tokenSource);
                if (this.Logger.IsNotNull())
                {
                    client.AddLogWriter(this.Logger);
                }

                return client;
            }

            throw new InvalidOperationException("Expected either a Subscription or Credential parameter.");
        }
开发者ID:shuainie,项目名称:azure-powershell,代码行数:27,代码来源:AzureHDInsightJobCommandExecutorBase.cs

示例4: CreateAzureSMProfile

 public static AzureSMProfile CreateAzureSMProfile(string storageAccount)
 {
     var profile = new AzureSMProfile();
     var client = new ProfileClient(profile);
     var tenantId = Guid.NewGuid();
     var subscriptionId = Guid.NewGuid();
     var account = new AzureAccount
     {
         Id = "[email protected]",
         Type = AzureAccount.AccountType.User
     };
     account.SetProperty(AzureAccount.Property.Tenants, tenantId.ToString());
     account.SetProperty(AzureAccount.Property.Subscriptions, subscriptionId.ToString());
     var subscription = new AzureSubscription()
     {
         Id = subscriptionId,
         Name = "Test Subscription 1",
         Environment = EnvironmentName.AzureCloud,
         Account = account.Id,
     };
     subscription.SetProperty(AzureSubscription.Property.Tenants, tenantId.ToString());
     subscription.SetProperty(AzureSubscription.Property.StorageAccount, storageAccount);
     client.AddOrSetAccount(account);
     client.AddOrSetSubscription(subscription);
     client.SetSubscriptionAsDefault(subscriptionId, account.Id);
     return profile;
 }
开发者ID:rohmano,项目名称:azure-powershell,代码行数:27,代码来源:CommonDataCmdletTests.cs

示例5: AzureHDInsightSubscriptionResolverSimulator

        internal AzureHDInsightSubscriptionResolverSimulator()
        {
            var certificate = new X509Certificate2(Convert.FromBase64String(IntegrationTestBase.TestCredentials.Certificate), string.Empty);
            AzureSession.DataStore.AddCertificate(certificate);
            ProfileClient profileClient = new ProfileClient(new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)));
            profileClient.Profile.Accounts[certificate.Thumbprint] = new AzureAccount
            {
                Id = certificate.Thumbprint,
                Type = AzureAccount.AccountType.Certificate,
                Properties =
                    new Dictionary<AzureAccount.Property, string>
                    {
                        {
                            AzureAccount.Property.Subscriptions,
                            IntegrationTestBase.TestCredentials.SubscriptionId.ToString()
                        }
                    }
            };
            profileClient.Profile.Save();

            this.knownSubscriptions = new AzureSubscription[]
                {
                    new AzureSubscription()
                        {
                            Id = IntegrationTestBase.TestCredentials.SubscriptionId,
                            Account = certificate.Thumbprint,
                            Environment = EnvironmentName.AzureCloud
                        }, 
                };
        }
开发者ID:docschmidt,项目名称:azure-powershell,代码行数:30,代码来源:AzureHDInsightSubscriptionResolverSimulator.cs

示例6: GetCurrentSubscription

        public static AzureSubscription GetCurrentSubscription()
        {
            string certificateThumbprint1 = "jb245f1d1257fw27dfc402e9ecde37e400g0176r";
            var newSubscription = new AzureSubscription()
            {
                Id = IntegrationTestBase.TestCredentials.SubscriptionId,
                // Use fake certificate thumbprint
                Account = certificateThumbprint1,
                Environment = "AzureCloud"
            };
            newSubscription.Properties[AzureSubscription.Property.Default] = "True";

            ProfileClient profileClient = new ProfileClient(new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)));
            profileClient.Profile.Accounts[certificateThumbprint1] = 
                new AzureAccount()
                {
                    Id = certificateThumbprint1,
                    Type = AzureAccount.AccountType.Certificate
                };
            profileClient.Profile.Subscriptions[newSubscription.Id] = newSubscription;
            
            profileClient.Profile.Save();
            
            return profileClient.Profile.Subscriptions[newSubscription.Id];
        }
开发者ID:shuainie,项目名称:azure-powershell,代码行数:25,代码来源:IntegrationTestBase.cs

示例7: GetAccessTokenCredentials

        public static IHDInsightSubscriptionCredentials GetAccessTokenCredentials(this IAzureHDInsightCommonCommandBase command, 
            AzureSubscription currentSubscription, AzureAccount azureAccount, AzureEnvironment environment)
        {
            ProfileClient profileClient = new ProfileClient();
            AzureContext azureContext = new AzureContext
            {
                Subscription = currentSubscription,
                Environment = environment,
                Account = azureAccount
            };

            var cloudCredentials = AzureSession.AuthenticationFactory.GetSubscriptionCloudCredentials(azureContext) as AccessTokenCredential;
            if (cloudCredentials != null)
            {
                var field= typeof(AccessTokenCredential).GetField("token", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance);
                var accessToken = field.GetValue(cloudCredentials) as IAccessToken;
                if (accessToken != null)
                {
                    return new HDInsightAccessTokenCredential()
                    {
                        SubscriptionId = currentSubscription.Id,
                        AccessToken = accessToken.AccessToken
                    };
                }
            }
            return null;
        }
开发者ID:Indhukrishna,项目名称:azure-powershell,代码行数:27,代码来源:AzureHDInsightCommandExtensions.cs

示例8: RemovesAzureEnvironment

        public void RemovesAzureEnvironment()
        {
            var commandRuntimeMock = new Mock<ICommandRuntime>();
            commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny<string>(), It.IsAny<string>())).Returns(true);

            const string name = "test";
            ProfileClient client = new ProfileClient();
            client.AddOrSetEnvironment(new AzureEnvironment
            {
                Name = name
            });
            client.Profile.Save();

            var cmdlet = new RemoveAzureEnvironmentCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                Force = true,
                Name = name
            };

            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();

            client = new ProfileClient();
            Assert.False(client.Profile.Environments.ContainsKey(name));
        }
开发者ID:randorfer,项目名称:azure-powershell,代码行数:27,代码来源:RemoveAzureEnvironmentTests.cs

示例9: SetAzureSubscriptionDerivesEnvironmentFromEnvironmentParameterOnAdd

        public void SetAzureSubscriptionDerivesEnvironmentFromEnvironmentParameterOnAdd()
        {
            SetAzureSubscriptionCommand cmdlt = new SetAzureSubscriptionCommand();
            // Setup
            ProfileClient client = new ProfileClient();
            client.AddOrSetEnvironment(azureEnvironment);
            client.Profile.Save();

            cmdlt.CommandRuntime = commandRuntimeMock.Object;
            cmdlt.SubscriptionId = Guid.NewGuid().ToString();
            cmdlt.SubscriptionName = "NewSubscriptionName";
            cmdlt.CurrentStorageAccountName = "NewCloudStorage";
            cmdlt.Environment = azureEnvironment.Name;
            cmdlt.Certificate = SampleCertificate;

            // Act
            cmdlt.InvokeBeginProcessing();
            cmdlt.ExecuteCmdlet();
            cmdlt.InvokeEndProcessing();

            // Verify
            client = new ProfileClient();
            var newSubscription = client.Profile.Subscriptions[new Guid(cmdlt.SubscriptionId)];
            Assert.Equal(cmdlt.SubscriptionName, newSubscription.Name);
            Assert.Equal(cmdlt.Environment, newSubscription.Environment);
            Assert.Equal(cmdlt.CurrentStorageAccountName, newSubscription.GetProperty(AzureSubscription.Property.StorageAccount));
        }
开发者ID:jeffwilcox,项目名称:azure-sdk-tools,代码行数:27,代码来源:ProfileCmdltsTests.cs

示例10: GetClient

        internal IHDInsightClient GetClient()
        {
            this.CurrentSubscription.ArgumentNotNull("CurrentSubscription");

            ProfileClient client = new ProfileClient();

            var subscriptionCredentials = this.GetSubscriptionCredentials(
                this.CurrentSubscription,
                client.GetEnvironmentOrDefault(this.CurrentSubscription.Environment),
                client.Profile);

            if (this.Endpoint.IsNotNull())
            {
                subscriptionCredentials.Endpoint = this.Endpoint;               
            }

            var clientInstance = ServiceLocator.Instance.Locate<IAzureHDInsightClusterManagementClientFactory>().Create(subscriptionCredentials);
            clientInstance.SetCancellationSource(this.tokenSource);
            if (this.Logger.IsNotNull())
            {
                clientInstance.AddLogWriter(this.Logger);
            }

            return clientInstance;
        }
开发者ID:Indhukrishna,项目名称:azure-powershell,代码行数:25,代码来源:AzureHDInsightClusterCommandBase.cs

示例11: SetsAzureEnvironment

        // TODO: fix flaky test
        //[Trait(Category.AcceptanceType, Category.CheckIn)]
        public void SetsAzureEnvironment()
        {
            Mock<ICommandRuntime> commandRuntimeMock = new Mock<ICommandRuntime>();
            string name = "Katal";
            ProfileClient client = new ProfileClient(new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)));
            client.AddOrSetEnvironment(new AzureEnvironment { Name = name });

            SetAzureEnvironmentCommand cmdlet = new SetAzureEnvironmentCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                Name = "KATaL",
                PublishSettingsFileUrl = "http://microsoft.com",
                ServiceEndpoint = "endpoint.net",
                ManagementPortalUrl = "management portal url",
                StorageEndpoint = "endpoint.net",
                GalleryEndpoint = "galleryendpoint"
            };

            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny<PSAzureEnvironment>()), Times.Once());
            client = new ProfileClient(new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)));
            AzureEnvironment env = client.Profile.Environments["KaTaL"];
            Assert.Equal(env.Name.ToLower(), cmdlet.Name.ToLower());
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.PublishSettingsFileUrl], cmdlet.PublishSettingsFileUrl);
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.ServiceManagement], cmdlet.ServiceEndpoint);
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.ManagementPortalUrl], cmdlet.ManagementPortalUrl);
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.Gallery], "galleryendpoint");
        }
开发者ID:docschmidt,项目名称:azure-powershell,代码行数:33,代码来源:SetAzureEnvironmentTests.cs

示例12: AddsAzureEnvironment

        public void AddsAzureEnvironment()
        {
            var profile = new AzureProfile();
            Mock<ICommandRuntime> commandRuntimeMock = new Mock<ICommandRuntime>();
            AddAzureEnvironmentCommand cmdlet = new AddAzureEnvironmentCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                Name = "Katal",
                PublishSettingsFileUrl = "http://microsoft.com",
                ServiceEndpoint = "endpoint.net",
                ManagementPortalUrl = "management portal url",
                StorageEndpoint = "endpoint.net",
                GalleryEndpoint = "http://galleryendpoint.com",
                Profile = profile
            };
            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny<PSAzureEnvironment>()), Times.Once());
            ProfileClient client = new ProfileClient(profile);
            AzureEnvironment env = client.GetEnvironmentOrDefault("KaTaL");
            Assert.Equal(env.Name, cmdlet.Name);
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.PublishSettingsFileUrl], cmdlet.PublishSettingsFileUrl);
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.ServiceManagement], cmdlet.ServiceEndpoint);
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.ManagementPortalUrl], cmdlet.ManagementPortalUrl);
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.Gallery], "http://galleryendpoint.com");
        }
开发者ID:nityasharma,项目名称:azure-powershell,代码行数:28,代码来源:AddAzureEnvironmentTests.cs

示例13: SetAzureSubscriptionAddsSubscriptionWithCertificate

        public void SetAzureSubscriptionAddsSubscriptionWithCertificate()
        {
            SetAzureSubscriptionCommand cmdlt = new SetAzureSubscriptionCommand();
            // Setup
            cmdlt.CommandRuntime = commandRuntimeMock.Object;
            cmdlt.SubscriptionId = Guid.NewGuid().ToString();
            cmdlt.SubscriptionName = "NewSubscriptionName";
            cmdlt.CurrentStorageAccountName = "NewCloudStorage";
            cmdlt.Certificate = SampleCertificate;

            // Act
            cmdlt.InvokeBeginProcessing();
            cmdlt.ExecuteCmdlet();
            cmdlt.InvokeEndProcessing();

            // Verify
            ProfileClient client = new ProfileClient();
            var newSubscription = client.Profile.Subscriptions[new Guid(cmdlt.SubscriptionId)];
            var newAccount = client.Profile.Accounts[SampleCertificate.Thumbprint];
            Assert.Equal(cmdlt.SubscriptionName, newSubscription.Name);
            Assert.Equal(EnvironmentName.AzureCloud, newSubscription.Environment);
            Assert.Equal(cmdlt.CurrentStorageAccountName, newSubscription.GetProperty(AzureSubscription.Property.StorageAccount));
            
            Assert.Equal(newAccount.Id, newSubscription.Account);
            Assert.Equal(AzureAccount.AccountType.Certificate, newAccount.Type);
            Assert.Equal(SampleCertificate.Thumbprint, newAccount.Id);
            Assert.Equal(cmdlt.SubscriptionId, newAccount.GetProperty(AzureAccount.Property.Subscriptions));
        }
开发者ID:djrosanova,项目名称:azure-sdk-tools,代码行数:28,代码来源:ProfileCmdltsTests.cs

示例14: EnvironmentSetupHelper

        public EnvironmentSetupHelper()
        {
            var datastore = new MemoryDataStore();
            AzureSession.DataStore = datastore;
            var profile = new AzureSMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            var rmprofile = new AzureRMProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            rmprofile.Environments.Add("foo", AzureEnvironment.PublicEnvironments.Values.FirstOrDefault());
            rmprofile.Context = new AzureContext(new AzureSubscription(), new AzureAccount(), rmprofile.Environments["foo"], new AzureTenant());
            rmprofile.Context.Subscription.Environment = "foo";
            if (AzureRmProfileProvider.Instance.Profile == null)
            {
                AzureRmProfileProvider.Instance.Profile = rmprofile;
            }

            AzureSession.DataStore = datastore;
            ProfileClient = new ProfileClient(profile);

            // Ignore SSL errors
            System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) => true;

            AdalTokenCache.ClearCookies();

            // Set RunningMocked
            TestMockSupport.RunningMocked = HttpMockServer.GetCurrentMode() == HttpRecorderMode.Playback;
        }
开发者ID:Azure,项目名称:azure-powershell,代码行数:25,代码来源:EnvironmentSetupHelper.cs

示例15: ProfileMigratesOldData

        public void ProfileMigratesOldData()
        {
            MockDataStore dataStore = new MockDataStore();
            dataStore.VirtualStore[oldProfileDataPath] = oldProfileData;
            ProfileClient.DataStore = dataStore;
            ProfileClient client = new ProfileClient();

            Assert.False(dataStore.FileExists(oldProfileDataPath));
            Assert.True(dataStore.FileExists(newProfileDataPath));
        }
开发者ID:djrosanova,项目名称:azure-sdk-tools,代码行数:10,代码来源:ProfileClientTests.cs


注:本文中的ProfileClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。