本文整理汇总了C#中Microsoft.Azure.Common.Authentication.ProfileClient.InitializeProfile方法的典型用法代码示例。如果您正苦于以下问题:C# ProfileClient.InitializeProfile方法的具体用法?C# ProfileClient.InitializeProfile怎么用?C# ProfileClient.InitializeProfile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Azure.Common.Authentication.ProfileClient
的用法示例。
在下文中一共展示了ProfileClient.InitializeProfile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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"));
}
示例2: InitializeAzureProfile
private void InitializeAzureProfile(AzureProfile profile, string parameterSet, AzureProfileSettings settings)
{
var savedCache = AzureSession.TokenCache;
AzureSession.TokenCache = DefaultMemoryTokenCache;
try
{
var profileClient = new ProfileClient(profile);
if (settings.Environment == null)
{
settings.Environment = AzureEnvironment.PublicEnvironments["AzureCloud"];
}
switch (parameterSet)
{
case CertificateParameterSet:
profileClient.InitializeProfile(settings.Environment, new Guid(settings.SubscriptionId),
settings.Certificate,
settings.StorageAccount);
break;
case CredentialsParameterSet:
var userAccount = new AzureAccount
{
Id = settings.Credential.UserName,
Type = AzureAccount.AccountType.User
};
profileClient.InitializeProfile(settings.Environment, new Guid(settings.SubscriptionId),
userAccount,
settings.Credential.Password, settings.StorageAccount);
break;
case AccessTokenParameterSet:
profileClient.InitializeProfile(settings.Environment, new Guid(settings.SubscriptionId),
settings.AccessToken,
settings.AccountId, settings.StorageAccount);
break;
case ServicePrincipalParameterSet:
var servicePrincipalAccount = new AzureAccount
{
Id = settings.Credential.UserName,
Type = AzureAccount.AccountType.ServicePrincipal,
};
servicePrincipalAccount.SetOrAppendProperty(AzureAccount.Property.Tenants, settings.Tenant);
profileClient.InitializeProfile(settings.Environment, new Guid(settings.SubscriptionId),
servicePrincipalAccount,
settings.Credential.Password, settings.StorageAccount);
break;
case EmptyParameterSet:
if (!profile.Environments.ContainsKey(settings.Environment.Name))
{
profile.Environments.Add(settings.Environment.Name, settings.Environment);
}
break;
}
}
finally
{
AzureSession.TokenCache = savedCache;
}
}
示例3: NewProfileFromCertificateReturnsProfile
public void NewProfileFromCertificateReturnsProfile()
{
MemoryDataStore dataStore = new MemoryDataStore();
AzureSession.DataStore = dataStore;
AzureProfile newProfile = new AzureProfile();
ProfileClient client1 = new ProfileClient(newProfile);
var subscriptionId = Guid.NewGuid();
var certificate = new X509Certificate2(Convert.FromBase64String(dummyCertificate));
client1.InitializeProfile(AzureEnvironment.PublicEnvironments["AzureCloud"],
subscriptionId, certificate, null);
Assert.Equal("AzureCloud", newProfile.DefaultSubscription.Environment);
Assert.Equal(subscriptionId, newProfile.DefaultSubscription.Id);
Assert.Equal(certificate.Thumbprint, newProfile.DefaultSubscription.Account);
Assert.False(newProfile.DefaultSubscription.Properties.ContainsKey(AzureSubscription.Property.StorageAccount));
}
示例4: NewProfileFromADWithMismatchSubscriptionThrows
public void NewProfileFromADWithMismatchSubscriptionThrows()
{
SetMocks(new[] { rdfeSubscription1, rdfeSubscription2 }.ToList(), new[] { csmSubscription1 }.ToList());
MemoryDataStore dataStore = new MemoryDataStore();
AzureSession.DataStore = dataStore;
AzureProfile newProfile = new AzureProfile();
ProfileClient client1 = new ProfileClient(newProfile);
var newAccount = new AzureAccount { Id = "foo" };
newAccount.Properties[AzureAccount.Property.Tenants] = "123";
Assert.Throws<ArgumentException>(() => client1.InitializeProfile(AzureEnvironment.PublicEnvironments["AzureCloud"],
Guid.NewGuid(), newAccount, null, null));
}
示例5: NewProfileWithAccessTokenReturnsProfile
public void NewProfileWithAccessTokenReturnsProfile()
{
//SetMocks(new[] { rdfeSubscription1, rdfeSubscription2 }.ToList(), new[] { csmSubscription1 }.ToList());
MemoryDataStore dataStore = new MemoryDataStore();
AzureSession.DataStore = dataStore;
AzureProfile newProfile = new AzureProfile();
ProfileClient client1 = new ProfileClient(newProfile);
client1.InitializeProfile(AzureEnvironment.PublicEnvironments["AzureCloud"],
new Guid(csmSubscription1.SubscriptionId), "accessToken", "accountId", null);
Assert.Equal("AzureCloud", newProfile.DefaultSubscription.Environment);
Assert.Equal(new Guid(csmSubscription1.SubscriptionId), newProfile.DefaultSubscription.Id);
Assert.Equal("accountId", newProfile.DefaultSubscription.Account);
Assert.Equal(AzureAccount.AccountType.AccessToken, newProfile.Context.Account.Type);
Assert.Equal("accessToken", newProfile.Context.Account.Properties[AzureAccount.Property.AccessToken]);
Assert.False(newProfile.DefaultSubscription.Properties.ContainsKey(AzureSubscription.Property.StorageAccount));
}
示例6: NewProfileFromADReturnsProfile
public void NewProfileFromADReturnsProfile()
{
SetMocks(new[] { rdfeSubscription1, rdfeSubscription2 }.ToList(), new[] { csmSubscription1 }.ToList());
MemoryDataStore dataStore = new MemoryDataStore();
AzureSession.DataStore = dataStore;
AzureProfile newProfile = new AzureProfile();
ProfileClient client1 = new ProfileClient(newProfile);
var newAccount = new AzureAccount {Id = "foo"};
newAccount.Properties[AzureAccount.Property.Tenants] = "123";
client1.InitializeProfile(AzureEnvironment.PublicEnvironments["AzureCloud"],
new Guid(csmSubscription1.SubscriptionId), newAccount, null, null);
Assert.Equal("AzureCloud", newProfile.DefaultSubscription.Environment);
Assert.Equal(new Guid(csmSubscription1.SubscriptionId), newProfile.DefaultSubscription.Id);
Assert.Equal(newAccount.Id, newProfile.DefaultSubscription.Account);
Assert.False(newProfile.DefaultSubscription.Properties.ContainsKey(AzureSubscription.Property.StorageAccount));
}
示例7: InitializeAzureProfile
private void InitializeAzureProfile(AzureProfile profile, string parameterSet, AzureProfileSettings settings)
{
var profileClient = new ProfileClient(profile);
if (settings.Environment == null)
{
settings.Environment = AzureEnvironment.PublicEnvironments["AzureCloud"];
}
switch (parameterSet)
{
case CertificateParameterSet:
profileClient.InitializeProfile(settings.Environment, new Guid(settings.SubscriptionId), settings.Certificate,
settings.StorageAccount);
break;
case CredentialsParameterSet:
var userAccount = new AzureAccount
{
Id = settings.Credential.UserName,
Type = AzureAccount.AccountType.User
};
profileClient.InitializeProfile(settings.Environment, new Guid(settings.SubscriptionId), userAccount,
settings.Credential.Password, settings.StorageAccount);
break;
case AccessTokenParameterSet:
profileClient.InitializeProfile(settings.Environment, new Guid(settings.SubscriptionId), settings.AccessToken,
settings.AccountId, settings.StorageAccount);
break;
case ServicePrincipalParameterSet:
var servicePrincipalAccount = new AzureAccount
{
Id = settings.Credential.UserName,
Type = AzureAccount.AccountType.ServicePrincipal
};
profileClient.InitializeProfile(settings.Environment, new Guid(settings.SubscriptionId), servicePrincipalAccount,
settings.Credential.Password, settings.StorageAccount);
break;
}
}