本文整理汇总了C#中Microsoft.Azure.Common.Authentication.Models.AzureSubscription.SetProperty方法的典型用法代码示例。如果您正苦于以下问题:C# AzureSubscription.SetProperty方法的具体用法?C# AzureSubscription.SetProperty怎么用?C# AzureSubscription.SetProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Azure.Common.Authentication.Models.AzureSubscription
的用法示例。
在下文中一共展示了AzureSubscription.SetProperty方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: CanConvertValidAzureSubscriptions
public void CanConvertValidAzureSubscriptions(string account, string name, string environment, string storageAccount, string expectedAccountName)
{
var oldSubscription = new AzureSubscription()
{
Account = account,
Environment = environment,
Id = Guid.NewGuid(),
Name = name
};
oldSubscription.SetProperty(AzureSubscription.Property.StorageAccount, storageAccount);
oldSubscription.SetProperty(AzureSubscription.Property.Tenants, Guid.NewGuid().ToString());
var subscription = (PSAzureSubscription) oldSubscription;
Assert.Equal(oldSubscription.Name, subscription.SubscriptionName);
Assert.Equal(oldSubscription.Id.ToString(), subscription.SubscriptionId);
Assert.Equal(oldSubscription.GetProperty(AzureSubscription.Property.Tenants), subscription.TenantId);
Assert.Equal(expectedAccountName, subscription.CurrentStorageAccountName);
Assert.Equal(storageAccount, subscription.CurrentStorageAccount);
Assert.NotNull(subscription.ToString());
}
示例3: ToAzureSubscription
internal static AzureSubscription ToAzureSubscription(this Subscription other, AzureContext context)
{
var subscription = new AzureSubscription();
subscription.Account = context.Account != null ? context.Account.Id : null;
subscription.Environment = context.Environment != null ? context.Environment.Name : EnvironmentName.AzureCloud;
subscription.Id = new Guid(other.SubscriptionId);
subscription.Name = other.DisplayName;
subscription.SetProperty(AzureSubscription.Property.Tenants,
context.Tenant.Id.ToString());
return subscription;
}
示例4: ListServiceManagementSubscriptions
private IEnumerable<AzureSubscription> ListServiceManagementSubscriptions(AzureAccount account, AzureEnvironment environment, SecureString password, ShowDialog promptBehavior, string[] tenants)
{
List<AzureSubscription> result = new List<AzureSubscription>();
if (!environment.IsEndpointSet(AzureEnvironment.Endpoint.ServiceManagement))
{
return result;
}
foreach (var tenant in tenants)
{
try
{
var tenantAccount = new AzureAccount();
CopyAccount(account, tenantAccount);
var tenantToken = AzureSession.AuthenticationFactory.Authenticate(tenantAccount, environment, tenant, password, ShowDialog.Never);
if (string.Equals(tenantAccount.Id, account.Id, StringComparison.InvariantCultureIgnoreCase))
{
tenantAccount = account;
}
tenantAccount.SetOrAppendProperty(AzureAccount.Property.Tenants, new string[] { tenant });
using (var subscriptionClient = AzureSession.ClientFactory.CreateCustomClient<SubscriptionClient>(
new TokenCloudCredentials(tenantToken.AccessToken),
environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ServiceManagement)))
{
var subscriptionListResult = subscriptionClient.Subscriptions.List();
foreach (var subscription in subscriptionListResult.Subscriptions)
{
// only add the subscription if it's actually in this tenant
if (subscription.ActiveDirectoryTenantId == tenant)
{
AzureSubscription psSubscription = new AzureSubscription
{
Id = new Guid(subscription.SubscriptionId),
Name = subscription.SubscriptionName,
Environment = environment.Name
};
psSubscription.SetProperty(AzureSubscription.Property.Tenants,
subscription.ActiveDirectoryTenantId);
psSubscription.Account = tenantAccount.Id;
tenantAccount.SetOrAppendProperty(AzureAccount.Property.Subscriptions,
new string[] { psSubscription.Id.ToString() });
result.Add(psSubscription);
}
}
}
AddOrSetAccount(tenantAccount);
}
catch (CloudException cEx)
{
WriteOrThrowAadExceptionMessage(cEx);
}
catch (AadAuthenticationException aadEx)
{
WriteOrThrowAadExceptionMessage(aadEx);
}
}
return result;
}
示例5: MergeSubscriptionProperties
private AzureSubscription MergeSubscriptionProperties(AzureSubscription subscription1, AzureSubscription subscription2)
{
if (subscription1 == null || subscription2 == null)
{
throw new ArgumentNullException("subscription1");
}
if (subscription1.Id != subscription2.Id)
{
throw new ArgumentException("Subscription Ids do not match.");
}
AzureSubscription mergedSubscription = new AzureSubscription
{
Id = subscription1.Id,
Name = subscription1.Name,
Environment = subscription1.Environment,
Account = subscription1.Account ?? subscription2.Account
};
// Merge all properties
foreach (AzureSubscription.Property property in Enum.GetValues(typeof(AzureSubscription.Property)))
{
string propertyValue = subscription1.GetProperty(property) ?? subscription2.GetProperty(property);
if (propertyValue != null)
{
mergedSubscription.Properties[property] = propertyValue;
}
}
// Merge RegisteredResourceProviders
var registeredProviders = subscription1.GetPropertyAsArray(AzureSubscription.Property.RegisteredResourceProviders)
.Union(subscription2.GetPropertyAsArray(AzureSubscription.Property.RegisteredResourceProviders), StringComparer.CurrentCultureIgnoreCase);
mergedSubscription.SetProperty(AzureSubscription.Property.RegisteredResourceProviders, registeredProviders.ToArray());
// Merge Tenants
var tenants = subscription1.GetPropertyAsArray(AzureSubscription.Property.Tenants)
.Union(subscription2.GetPropertyAsArray(AzureSubscription.Property.Tenants), StringComparer.CurrentCultureIgnoreCase);
mergedSubscription.SetProperty(AzureSubscription.Property.Tenants, tenants.ToArray());
return mergedSubscription;
}
示例6: ToAzureSubscription
public AzureSubscription ToAzureSubscription(List<AzureEnvironment> envs)
{
AzureSubscription subscription = new AzureSubscription();
try
{
subscription.Id = new Guid(this.SubscriptionId);
}
catch (Exception ex)
{
throw new ArgumentException("Subscription ID is not a valid GUID.", ex);
}
subscription.Name = Name;
// Logic to detect what is the subscription environment rely's on having ManagementEndpoint (i.e. RDFE endpoint) set already on the subscription
List<AzureEnvironment> allEnvs = envs.Union(AzureEnvironment.PublicEnvironments.Values).ToList();
AzureEnvironment env = allEnvs.FirstOrDefault(e => e.IsEndpointSetToValue(AzureEnvironment.Endpoint.ServiceManagement, this.ManagementEndpoint));
if (env != null)
{
subscription.Environment = env.Name;
}
else
{
subscription.Environment = EnvironmentName.AzureCloud;
}
if (!string.IsNullOrEmpty(this.ManagementCertificate))
{
subscription.Account = this.ManagementCertificate;
subscription.SetProperty(AzureSubscription.Property.SupportedModes,
AzureModule.AzureServiceManagement.ToString());
}
if (!string.IsNullOrEmpty(this.ActiveDirectoryUserId))
{
subscription.Account = this.ActiveDirectoryUserId;
}
if (!string.IsNullOrEmpty(this.ActiveDirectoryTenantId))
{
subscription.SetProperty(AzureSubscription.Property.Tenants, ActiveDirectoryTenantId);
}
if (this.IsDefault)
{
subscription.SetProperty(AzureSubscription.Property.Default, "True");
}
if (!string.IsNullOrEmpty(this.CloudStorageAccount))
{
subscription.Properties.Add(AzureSubscription.Property.StorageAccount, this.CloudStorageAccount);
}
if (this.RegisteredResourceProviders.Count() > 0)
{
StringBuilder providers = new StringBuilder();
subscription.Properties.Add(AzureSubscription.Property.RegisteredResourceProviders,
string.Join(",", RegisteredResourceProviders));
}
return subscription;
}
示例7: AccountMatchingIgnoresCase
public void AccountMatchingIgnoresCase()
{
var profile = new AzureProfile();
string accountName = "[email protected]";
string accountNameCase = "[email protected]";
var subscriptionId = Guid.NewGuid();
var tenantId = Guid.NewGuid();
var account = new AzureAccount
{
Id = accountName,
Type = AzureAccount.AccountType.User
};
account.SetProperty(AzureAccount.Property.Subscriptions, subscriptionId.ToString());
account.SetProperty(AzureAccount.Property.Tenants, tenantId.ToString());
var subscription = new AzureSubscription
{
Id = subscriptionId,
Account = accountNameCase,
Environment = EnvironmentName.AzureCloud
};
subscription.SetProperty(AzureSubscription.Property.Default, "true");
subscription.SetProperty(AzureSubscription.Property.Tenants, tenantId.ToString());
profile.Accounts.Add(accountName, account);
profile.Subscriptions.Add(subscriptionId, subscription);
Assert.NotNull(profile.Context);
Assert.NotNull(profile.Context.Account);
Assert.NotNull(profile.Context.Environment);
Assert.NotNull(profile.Context.Subscription);
Assert.Equal(account, profile.Context.Account);
Assert.Equal(subscription, profile.Context.Subscription);
}