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


C# Authentication.ProfileClient类代码示例

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


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

示例1: PublishSubscriptionToAzureSubscription

        private static AzureSubscription PublishSubscriptionToAzureSubscription(
            ProfileClient azureProfileClient, 
            PublishDataPublishProfile profile,
            PublishDataPublishProfileSubscription s,
            string environment)
        {
            var certificate = GetCertificate(profile, s);

            if (string.IsNullOrEmpty(environment))
            {
                var azureEnvironment = azureProfileClient.GetEnvironment(environment, s.ServiceManagementUrl ?? profile.Url, null);
                if (azureEnvironment != null)
                {
                    environment = azureEnvironment.Name;
                }
                else
                {
                    environment = EnvironmentName.AzureCloud;
                }
            }
            
            return new AzureSubscription
            {
                Id = new Guid(s.Id),
                Name = s.Name,
                Environment = environment,
                Account = certificate.Thumbprint
            };
        }
开发者ID:docschmidt,项目名称:azure-powershell,代码行数:29,代码来源:PublishSettingsImporter.cs

示例2: ImportAzureSubscription

 public static IEnumerable<AzureSubscription> ImportAzureSubscription(Stream stream, ProfileClient azureProfileClient, string environment)
 {
     var publishData = DeserializePublishData(stream);
     PublishDataPublishProfile profile = publishData.Items.Single();
     stream.Close();
     return profile.Subscription.Select(s => PublishSubscriptionToAzureSubscription(azureProfileClient, profile, s, environment));
 }
开发者ID:docschmidt,项目名称:azure-powershell,代码行数:7,代码来源:PublishSettingsImporter.cs

示例3: BaseSetup

        public void BaseSetup()
        {
            if (AzureSession.DataStore != null && !(AzureSession.DataStore is MemoryDataStore))
            {
                AzureSession.DataStore = new MemoryDataStore();
            }
            currentProfile = new AzureSMProfile();

            if (currentProfile.Context.Subscription == null)
            {
                var newGuid = Guid.NewGuid();
                var client = new ProfileClient(currentProfile);
                client.AddOrSetAccount(new AzureAccount
                    {
                        Id = "test",
                        Type = AzureAccount.AccountType.User,
                        Properties = new Dictionary<AzureAccount.Property, string>
                        {
                            {AzureAccount.Property.Subscriptions, newGuid.ToString()}
                        }
                    });
               client.AddOrSetSubscription( new AzureSubscription { Id = newGuid, Name = "test", Environment = EnvironmentName.AzureCloud, Account = "test" });
               client.SetSubscriptionAsDefault(newGuid, "test");
           }
            AzureSession.AuthenticationFactory = new MockTokenAuthenticationFactory();
        }
开发者ID:docschmidt,项目名称:azure-powershell,代码行数:26,代码来源:SMTestBase.cs

示例4: BeginProcessing

        protected override void BeginProcessing()
        {
            base.BeginProcessing();

            ProfileClient = new ProfileClient(Profile);
            ProfileClient.WarningLog = WriteWarning;
            ProfileClient.DebugLog = WriteDebug;
        }
开发者ID:shuainie,项目名称:azure-powershell,代码行数:8,代码来源:SubscriptionCmdletBase.cs

示例5: ProfileMigratesOldData

        public void ProfileMigratesOldData()
        {
            MemoryDataStore dataStore = new MemoryDataStore();
            dataStore.VirtualStore[oldProfileDataPath] = oldProfileData;
            AzureSession.DataStore = dataStore;
            currentProfile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            ProfileClient client = new ProfileClient(currentProfile);

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

示例6: NewProfileFromCertificateWithNullsThrowsArgumentNullException

 public void NewProfileFromCertificateWithNullsThrowsArgumentNullException()
 {
     MemoryDataStore dataStore = new MemoryDataStore();
     AzureSession.DataStore = dataStore;
     AzureProfile newProfile = new AzureProfile();
     ProfileClient client1 = new ProfileClient(newProfile);
     Assert.Throws<ArgumentNullException>(() =>
         client1.InitializeProfile(null, Guid.NewGuid(), new X509Certificate2(), "foo"));
     Assert.Throws<ArgumentNullException>(() =>
         client1.InitializeProfile(AzureEnvironment.PublicEnvironments["AzureCloud"], Guid.NewGuid(), null, "foo"));
 }
开发者ID:safeermohammed,项目名称:azure-sdk-for-net,代码行数:11,代码来源:ProfileClientTests.cs

示例7: ProfileSerializeDeserializeWorks

        public void ProfileSerializeDeserializeWorks()
        {
            var dataStore = new MockDataStore();
            var currentProfile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            AzureSession.DataStore = dataStore;
            var client = new ProfileClient(currentProfile);
            var tenant = Guid.NewGuid().ToString();
            var environment = new AzureEnvironment
            {
                Name = "testCloud",
                Endpoints = { { AzureEnvironment.Endpoint.ActiveDirectory, "http://contoso.com" } }
            };
            var account = new AzureAccount
            {
                Id = "[email protected]",
                Type = AzureAccount.AccountType.User,
                Properties = { { AzureAccount.Property.Tenants, tenant } }
            };
            var sub = new AzureSubscription
            {
                Account = account.Id,
                Environment = environment.Name,
                Id = new Guid(),
                Name = "Contoso Test Subscription",
                Properties = { { AzureSubscription.Property.Tenants, tenant } }
            };

            client.AddOrSetEnvironment(environment);
            client.AddOrSetAccount(account);
            client.AddOrSetSubscription(sub);

            AzureProfile deserializedProfile;
            // Round-trip the exception: Serialize and de-serialize with a BinaryFormatter
            BinaryFormatter bf = new BinaryFormatter();
            using (MemoryStream ms = new MemoryStream())
            {
                // "Save" object state
                bf.Serialize(ms, currentProfile);

                // Re-use the same stream for de-serialization
                ms.Seek(0, 0);

                // Replace the original exception with de-serialized one
                deserializedProfile = (AzureProfile)bf.Deserialize(ms);
            }
            Assert.NotNull(deserializedProfile);
            var jCurrentProfile = JsonConvert.SerializeObject(currentProfile);
            var jDeserializedProfile = JsonConvert.SerializeObject(deserializedProfile);
            Assert.Equal(jCurrentProfile, jDeserializedProfile);
        }
开发者ID:theadriangreen,项目名称:azure-sdk-for-net,代码行数:50,代码来源:ProfileTests.cs

示例8: ProfileSaveDoesNotSerializeContext

        public void ProfileSaveDoesNotSerializeContext()
        {
            var dataStore = new MockDataStore();
            var currentProfile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            AzureSession.DataStore = dataStore;
            var client = new ProfileClient(currentProfile);
            var tenant = Guid.NewGuid().ToString();
            var environment = new AzureEnvironment
            {
                Name = "testCloud",
                Endpoints = { { AzureEnvironment.Endpoint.ActiveDirectory, "http://contoso.com" } }
            };
            var account = new AzureAccount
            {
                Id = "[email protected]",
                Type = AzureAccount.AccountType.User,
                Properties = { { AzureAccount.Property.Tenants, tenant } }
            };
            var sub = new AzureSubscription
            {
                Account = account.Id,
                Environment = environment.Name,
                Id = new Guid(),
                Name = "Contoso Test Subscription",
                Properties = { { AzureSubscription.Property.Tenants, tenant } }
            };

            client.AddOrSetEnvironment(environment);
            client.AddOrSetAccount(account);
            client.AddOrSetSubscription(sub);

            currentProfile.Save();

            var profileFile = currentProfile.ProfilePath;
            string profileContents = dataStore.ReadFileAsText(profileFile);
            var readProfile = JsonConvert.DeserializeObject<Dictionary<string, object>>(profileContents);
            Assert.False(readProfile.ContainsKey("Context"));
            AzureProfile parsedProfile = new AzureProfile();
            var serializer = new JsonProfileSerializer();
            Assert.True(serializer.Deserialize(profileContents, parsedProfile));
            Assert.NotNull(parsedProfile);
            Assert.NotNull(parsedProfile.Environments);
            Assert.True(parsedProfile.Environments.ContainsKey(environment.Name));
            Assert.NotNull(parsedProfile.Accounts);
            Assert.True(parsedProfile.Accounts.ContainsKey(account.Id));
            Assert.NotNull(parsedProfile.Subscriptions);
            Assert.True(parsedProfile.Subscriptions.ContainsKey(sub.Id));
        }
开发者ID:theadriangreen,项目名称:azure-sdk-for-net,代码行数:48,代码来源:ProfileTests.cs

示例9: GetAzureProfile

        // Gets the customer's Azure account and subscription information
        private static AzureProfile GetAzureProfile()
        {
            AzureProfile profile = new AzureProfile();
            ProfileClient profileClient = new ProfileClient(profile);
            AzureAccount azureAccount = new AzureAccount() {Type = AzureAccount.AccountType.User};

            // Prompts the user for their credentials and retrieves their account/subscription info
            profileClient.AddAccountAndLoadSubscriptions(azureAccount, profile.Environments[EnvironmentName.AzureCloud], null);

            // By default, the first subscription is chosen
            if (profileClient.Profile.Subscriptions.Count > 1)
            {
                SelectSubscription(profileClient.Profile);
            }

            return profileClient.Profile;
        }
开发者ID:neerajay,项目名称:azure-batch-samples,代码行数:18,代码来源:Program.cs

示例10: GetAccessTokenCredentials

        public static IHDInsightSubscriptionCredentials GetAccessTokenCredentials(this IAzureHDInsightCommonCommandBase command, 
            AzureSubscription currentSubscription, AzureAccount azureAccount, AzureEnvironment environment)
        {
            ProfileClient profileClient = new ProfileClient(new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)));
            AzureContext azureContext = new AzureContext(currentSubscription, azureAccount, environment);

            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:shuainie,项目名称:azure-powershell,代码行数:22,代码来源:AzureHDInsightCommandExtensions.cs

示例11: RemoveAzureAccountRemovesSubscriptions

        public void RemoveAzureAccountRemovesSubscriptions()
        {
            MemoryDataStore dataStore = new MemoryDataStore();
            AzureSession.DataStore = dataStore;
            currentProfile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            ProfileClient client = new ProfileClient(currentProfile);
            client.Profile.Subscriptions[azureSubscription1.Id] = azureSubscription1;
            client.Profile.Subscriptions[azureSubscription2.Id] = azureSubscription2;
            client.Profile.Accounts[azureAccount.Id] = azureAccount;
            azureSubscription3withoutUser.Account = "test2";
            client.Profile.Accounts["test2"] = new AzureAccount
            {
                Id = "test2",
                Type = AzureAccount.AccountType.User,
                Properties = new Dictionary<AzureAccount.Property, string>
                {
                    {AzureAccount.Property.Subscriptions, azureSubscription3withoutUser.Id.ToString()}
                }
            };
            client.Profile.Subscriptions[azureSubscription3withoutUser.Id] = azureSubscription3withoutUser;
            client.Profile.Environments[azureEnvironment.Name] = azureEnvironment;
            List<string> log = new List<string>();
            client.WarningLog = log.Add;

            Assert.Equal(3, client.Profile.Subscriptions.Count);

            client.RemoveAccount("test2");

            Assert.Equal(2, client.Profile.Subscriptions.Count);
            Assert.Equal(0, log.Count);
        }
开发者ID:safeermohammed,项目名称:azure-sdk-for-net,代码行数:31,代码来源:ProfileClientTests.cs

示例12: RefreshSubscriptionsMergesFromServer

        public void RefreshSubscriptionsMergesFromServer()
        {
            SetMocks(new[] { rdfeSubscription1, rdfeSubscription2 }.ToList(), new[] { csmSubscription1, csmSubscription1withDuplicateId }.ToList());
            MemoryDataStore dataStore = new MemoryDataStore();
            AzureSession.DataStore = dataStore;
            currentProfile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            ProfileClient client = new ProfileClient(currentProfile);
            client.AddOrSetEnvironment(azureEnvironment);
            client.Profile.Accounts[azureAccount.Id] = azureAccount;
            client.AddOrSetSubscription(azureSubscription1);

            var subscriptions = client.RefreshSubscriptions(azureEnvironment);

            Assert.Equal(4, subscriptions.Count);
            Assert.Equal(4, subscriptions.Count(s => s.Account == "test"));
            Assert.Equal(1, subscriptions.Count(s => s.Id == azureSubscription1.Id));
            Assert.Equal(1, subscriptions.Count(s => s.Id == new Guid(rdfeSubscription1.SubscriptionId)));
            Assert.Equal(2, subscriptions.First(s => s.Id == new Guid(rdfeSubscription1.SubscriptionId)).GetPropertyAsArray(AzureSubscription.Property.SupportedModes).Count());
            Assert.Equal(1, subscriptions.Count(s => s.Id == new Guid(rdfeSubscription2.SubscriptionId)));
            Assert.Equal(1, subscriptions.Count(s => s.Id == new Guid(csmSubscription1.SubscriptionId)));
        }
开发者ID:safeermohammed,项目名称:azure-sdk-for-net,代码行数:21,代码来源:ProfileClientTests.cs

示例13: RemoveAzureAccountRemovesDefaultSubscriptionAndWritesWarning

        public void RemoveAzureAccountRemovesDefaultSubscriptionAndWritesWarning()
        {
            MemoryDataStore dataStore = new MemoryDataStore();
            AzureSession.DataStore = dataStore;
            ProfileClient client = new ProfileClient(currentProfile);

            client.Profile.Subscriptions[azureSubscription1.Id] = azureSubscription1;
            client.Profile.Subscriptions[azureSubscription2.Id] = azureSubscription2;
            client.Profile.Accounts[azureAccount.Id] = azureAccount;
            azureSubscription3withoutUser.Account = "test2";
            client.Profile.Accounts["test2"] = new AzureAccount
            {
                Id = "test2",
                Type = AzureAccount.AccountType.User,
                Properties = new Dictionary<AzureAccount.Property, string>
                {
                    {AzureAccount.Property.Subscriptions, azureSubscription3withoutUser.Id.ToString()}
                }
            };
            client.Profile.Subscriptions[azureSubscription3withoutUser.Id] = azureSubscription3withoutUser;
            client.Profile.Environments[azureEnvironment.Name] = azureEnvironment;
            List<string> log = new List<string>();
            client.WarningLog = log.Add;

            Assert.Equal(3, client.Profile.Subscriptions.Count);

            var account = client.RemoveAccount("test");

            Assert.Equal(1, client.Profile.Subscriptions.Count);
            Assert.Equal("test", account.Id);
            Assert.Equal(2, account.GetPropertyAsArray(AzureAccount.Property.Subscriptions).Length);
            Assert.Equal(1, log.Count);
            Assert.Equal(
                "The default subscription is being removed. Use Select-AzureSubscription -Default <subscriptionName> to select a new default subscription.",
                log[0]);
        }
开发者ID:safeermohammed,项目名称:azure-sdk-for-net,代码行数:36,代码来源:ProfileClientTests.cs

示例14: RemoveAzureSubscriptionChecksAndRemoves

        public void RemoveAzureSubscriptionChecksAndRemoves()
        {
            MemoryDataStore dataStore = new MemoryDataStore();
            AzureSession.DataStore = dataStore;
            currentProfile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            ProfileClient client = new ProfileClient(currentProfile);

            client.Profile.Accounts[azureAccount.Id] = azureAccount;
            client.AddOrSetEnvironment(azureEnvironment);
            client.AddOrSetSubscription(azureSubscription1);
            client.SetSubscriptionAsDefault(azureSubscription1.Name, azureSubscription1.Account);

            Assert.Equal(1, client.Profile.Subscriptions.Count);

            List<string> log = new List<string>();
            client.WarningLog = log.Add;

            var subscription = client.RemoveSubscription(azureSubscription1.Name);

            Assert.Equal(0, client.Profile.Subscriptions.Count);
            Assert.Equal(azureSubscription1.Name, subscription.Name);
            Assert.Equal(1, log.Count);
            Assert.Equal(
                "The default subscription is being removed. Use Select-AzureSubscription -Default <subscriptionName> to select a new default subscription.",
                log[0]);
            Assert.Throws<ArgumentException>(() => client.RemoveSubscription("bad"));
            Assert.Throws<ArgumentNullException>(() => client.RemoveSubscription(null));
        }
开发者ID:safeermohammed,项目名称:azure-sdk-for-net,代码行数:28,代码来源:ProfileClientTests.cs

示例15: RefreshSubscriptionsUpdatesAccounts

        public void RefreshSubscriptionsUpdatesAccounts()
        {
            SetMocks(new[] { rdfeSubscription1, rdfeSubscription2 }.ToList(), new[] { csmSubscription1, csmSubscription1withDuplicateId }.ToList());
            MemoryDataStore dataStore = new MemoryDataStore();
            AzureSession.DataStore = dataStore;
            currentProfile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile));
            ProfileClient client = new ProfileClient(currentProfile);
            client.AddOrSetEnvironment(azureEnvironment);
            client.Profile.Accounts[azureAccount.Id] = azureAccount;
            client.AddOrSetSubscription(azureSubscription1);

            var subscriptions = client.RefreshSubscriptions(azureEnvironment);

            Assert.True(client.Profile.Accounts[azureAccount.Id].HasSubscription(new Guid(rdfeSubscription1.SubscriptionId)));
            Assert.True(client.Profile.Accounts[azureAccount.Id].HasSubscription(new Guid(rdfeSubscription2.SubscriptionId)));
            Assert.True(client.Profile.Accounts[azureAccount.Id].HasSubscription(new Guid(csmSubscription1.SubscriptionId)));
            Assert.True(client.Profile.Accounts[azureAccount.Id].HasSubscription(new Guid(csmSubscription1withDuplicateId.SubscriptionId)));
        }
开发者ID:safeermohammed,项目名称:azure-sdk-for-net,代码行数:18,代码来源:ProfileClientTests.cs


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