本文整理汇总了C#中Microsoft.WindowsAzure.CloudStorageAccount.CreateIfNotExist方法的典型用法代码示例。如果您正苦于以下问题:C# CloudStorageAccount.CreateIfNotExist方法的具体用法?C# CloudStorageAccount.CreateIfNotExist怎么用?C# CloudStorageAccount.CreateIfNotExist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.CloudStorageAccount
的用法示例。
在下文中一共展示了CloudStorageAccount.CreateIfNotExist方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
ServicePointManager.DefaultConnectionLimit = 32;
var container = new CloudStorageAccount(new StorageCredentialsAccountAndKey(args[1], args[2]), true).CreateCloudBlobClient().GetContainerReference(args[3]);
container.CreateIfNotExist();
var cloudHashes = new Dictionary<string, string>();
foreach (CloudBlob blob in container.ListBlobs(new BlobRequestOptions { UseFlatBlobListing = true }))
{
cloudHashes[blob.Uri.ToString().Substring(container.Uri.ToString().Length + 1)] = blob.Properties.ContentMD5;
}
var localHashes = new Dictionary<string, string>();
foreach (var file in Directory.EnumerateFiles(args[0], "*", SearchOption.AllDirectories))
{
localHashes[file.Substring(args[0].Length + 1).Replace('\\', '/')] = GetMd5(file);
}
foreach (var name in cloudHashes.Keys.Where(n => localHashes.ContainsKey(n) && (localHashes[n] != cloudHashes[n])))
{
Console.WriteLine("Uploading {0}", name);
UploadWithMd5(container, name, Path.Combine(args[0], name));
}
foreach (var name in localHashes.Keys.Where(n => !cloudHashes.ContainsKey(n)))
{
Console.WriteLine("Uploading {0}", name);
UploadWithMd5(container, name, Path.Combine(args[0], name));
}
foreach (var name in cloudHashes.Keys.Where(n => !localHashes.ContainsKey(n)))
{
Console.WriteLine("Deleting {0}", name);
semaphore.WaitOne();
var blob = container.GetBlobReference(name);
Interlocked.Increment(ref count);
blob.BeginDelete((ar) => {
blob.EndDelete(ar);
semaphore.Release();
Interlocked.Decrement(ref count);
}, null);
}
while (count > 0) Thread.Sleep(TimeSpan.FromSeconds(1));
}