本文整理汇总了C#中IServiceManagement.ToContextChannel方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceManagement.ToContextChannel方法的具体用法?C# IServiceManagement.ToContextChannel怎么用?C# IServiceManagement.ToContextChannel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceManagement
的用法示例。
在下文中一共展示了IServiceManagement.ToContextChannel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCurrentCloudStorageAccount
public static CloudStorageAccount GetCurrentCloudStorageAccount(IServiceManagement channel, SubscriptionData subscriptionData)
{
if (String.IsNullOrEmpty(subscriptionData.CurrentStorageAccount))
{
return null;
}
if (subscriptionData.CurrentCloudStorageAccount != null)
{
return subscriptionData.CurrentCloudStorageAccount;
}
CloudStorageAccount currentStorage = null;
using (new OperationContextScope(channel.ToContextChannel()))
{
var storageService = channel.GetStorageService(subscriptionData.SubscriptionId, subscriptionData.CurrentStorageAccount);
var storageServiceKeys = channel.GetStorageKeys(subscriptionData.SubscriptionId, subscriptionData.CurrentStorageAccount);
if (storageService != null && storageServiceKeys != null)
{
string connectionString = General.BuildConnectionString("https", storageService.ServiceName, storageServiceKeys.StorageServiceKeys.Primary, storageService.StorageServiceProperties.Endpoints[0].Replace("http://", "https://"), storageService.StorageServiceProperties.Endpoints[2].Replace("http://", "https://"), storageService.StorageServiceProperties.Endpoints[1].Replace("http://", "https://"));
currentStorage = CloudStorageAccount.Parse(connectionString);
}
}
subscriptionData.CurrentCloudStorageAccount = currentStorage;
return currentStorage;
}
示例2: RemoveVHD
public static void RemoveVHD(IServiceManagement channel, string subscriptionId, Uri mediaLink)
{
var accountName = mediaLink.Host.Split('.')[0];
var blobEndpoint = new Uri(mediaLink.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped));
StorageService storageService;
using (new OperationContextScope(channel.ToContextChannel()))
{
storageService = channel.GetStorageKeys(subscriptionId, accountName);
}
var storageAccountCredentials = new StorageCredentials(accountName, storageService.StorageServiceKeys.Primary);
var client = new CloudBlobClient(blobEndpoint, storageAccountCredentials);
var blob = client.GetBlobReferenceFromServer(mediaLink);
blob.DeleteIfExists();
}