本文整理汇总了C#中Microsoft.Azure.Commands.Common.Authentication.Models.AzureContext.SetCurrentStorageAccount方法的典型用法代码示例。如果您正苦于以下问题:C# AzureContext.SetCurrentStorageAccount方法的具体用法?C# AzureContext.SetCurrentStorageAccount怎么用?C# AzureContext.SetCurrentStorageAccount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Azure.Commands.Common.Authentication.Models.AzureContext
的用法示例。
在下文中一共展示了AzureContext.SetCurrentStorageAccount方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteCmdlet
/// <summary>
/// Executes the set subscription cmdlet operation.
/// </summary>
public override void ExecuteCmdlet()
{
AzureSubscription subscription = null;
if (!string.IsNullOrEmpty(SubscriptionId) && string.IsNullOrEmpty(SubscriptionName))
{
subscription = ProfileClient.GetSubscription(new Guid(SubscriptionId));
Environment = subscription.Environment;
}
else if (string.IsNullOrEmpty(SubscriptionId) && !string.IsNullOrEmpty(SubscriptionName))
{
subscription = ProfileClient.GetSubscription(SubscriptionName);
Environment = subscription.Environment;
}
else
{
subscription = new AzureSubscription();
subscription.Id = new Guid(SubscriptionId);
subscription.Name = SubscriptionName;
}
AzureEnvironment environment = ProfileClient.GetEnvironment(Environment, ServiceEndpoint, ResourceManagerEndpoint);
if (environment == null)
{
var profileClient = new ProfileClient(Profile);
environment = profileClient.GetEnvironment(Environment, ServiceEndpoint, ResourceManagerEndpoint);
}
if (environment == null)
{
throw new ArgumentException("ServiceEndpoint and ResourceManagerEndpoint values do not "+
"match existing environment. Please use Environment parameter.");
}
else
{
subscription.Environment = environment.Name;
}
if (ServiceEndpoint != null || ResourceManagerEndpoint != null)
{
WriteWarning("Please use Environment parameter to specify subscription environment. This "+
"warning will be converted into an error in the upcoming release.");
}
if (Certificate != null)
{
ProfileClient.ImportCertificate(Certificate);
subscription.Account = Certificate.Thumbprint;
AzureAccount account = new AzureAccount
{
Id = Certificate.Thumbprint,
Type = AzureAccount.AccountType.Certificate
};
account.SetOrAppendProperty(AzureAccount.Property.Subscriptions, subscription.Id.ToString());
ProfileClient.AddOrSetAccount(account);
if (subscription.Account == null)
{
subscription.Account = account.Id;
}
}
if (subscription.Account == null)
{
throw new ArgumentException("Certificate is required for creating a new subscription.");
}
if (!string.IsNullOrEmpty(CurrentStorageAccountName) || Context != null)
{
ProfileClient.GetAccount(subscription.Account);
if (Profile.Context != null && Profile.Context.Subscription != null &&
Profile.Context.Subscription.Id == subscription.Id)
{
GeneralUtilities.ClearCurrentStorageAccount();
}
var context = new AzureContext(subscription, ProfileClient.GetAccount(subscription.Account), ProfileClient.GetEnvironmentOrDefault(subscription.Environment));
if (Context != null)
{
context.SetCurrentStorageAccount(this);
}
else
{
var client = AzureSession.ClientFactory.CreateClient<StorageManagementClient>(context,
AzureEnvironment.Endpoint.ServiceManagement);
var account = StorageUtilities.GenerateCloudStorageAccount(client, CurrentStorageAccountName);
context.SetCurrentStorageAccount(account.ToString(true));
}
}
subscription = ProfileClient.AddOrSetSubscription(subscription);
if (PassThru)
{
WriteObject(subscription);
}
}