本文整理汇总了C#中Microsoft.WindowsAzure.Storage.CloudStorageAccount.GetContainerReference方法的典型用法代码示例。如果您正苦于以下问题:C# CloudStorageAccount.GetContainerReference方法的具体用法?C# CloudStorageAccount.GetContainerReference怎么用?C# CloudStorageAccount.GetContainerReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.CloudStorageAccount
的用法示例。
在下文中一共展示了CloudStorageAccount.GetContainerReference方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
// Header.
Console.WriteLine("");
Console.WriteLine(" Windows Azure VHD Size v1.0 (2013-12-18) - Sandrino Di Mattia");
Console.WriteLine(" Usage: wazvhdsize.exe <accountName> <accountKey> <vhdUrl|containerName>");
Console.WriteLine("");
// Validate args.
if (args.Length != 3)
{
Console.WriteLine(" Invalid number of arguments.");
Console.WriteLine("");
return;
}
// Get the uri.
var uri = args[2];
Console.WriteLine(" Processing: {0}", uri);
Console.WriteLine("");
try
{
// Init client and blob list.
var client = new CloudStorageAccount(new StorageCredentials(args[0], args[1]), false).CreateCloudBlobClient();
var isBlobUri = false;
var blobs = new List<CloudPageBlob>();
// It's an uri.
if (uri.StartsWith("http://") || uri.StartsWith("https://"))
{
var blob = client.GetBlobReferenceFromServer(new Uri(uri)) as CloudPageBlob;
if (blob == null)
throw new FileNotFoundException("Unable to find the Page Blob.");
blobs.Add(blob);
isBlobUri = true;
}
else
{
// It's a container.
var container = client.GetContainerReference(uri);
if (!container.Exists())
throw new InvalidOperationException("Container does not exist: " + uri);
blobs.AddRange(container.ListBlobs().OfType<CloudPageBlob>());
}
// Show blob sizes.
foreach (var blob in blobs)
{
if (!isBlobUri)
Console.WriteLine(" Blob: {0}", blob.Uri);
// Display length.
Console.WriteLine(" > Size: {0} ({1} bytes)", PageBlobExtensions.GetFormattedDiskSize(blob.Properties.Length), blob.Properties.Length);
// Calculate size.
var size = blob.GetActualDiskSize();
Console.WriteLine(" > Actual/Billable Size: {0} ({1} bytes)", PageBlobExtensions.GetFormattedDiskSize(size), size);
Console.WriteLine("");
}
}
catch (Exception ex)
{
Console.WriteLine(" Error:");
Console.WriteLine(" {0}", ex);
}
}