public static async Task TransferLocalDirectoryToAzureBlobDirectory(CloudStorageAccount account) { string localDirectoryPath = Upload.GetSourcePath(); CloudBlobDirectory blobDirectory = Upload.GetBlobDirectory(account); TransferCheckpoint checkpoint = null; DirectoryTransferContext context = Perf.GetDirectoryTransferContext(checkpoint); CancellationTokenSource cancellationSource = new CancellationTokenSource(); Console.WriteLine("\nTransfer started...\nPress 'c' to temporarily cancel your transfer...\n"); Stopwatch stopWatch = Stopwatch.StartNew(); Task task; ConsoleKeyInfo keyinfo; UploadDirectoryOptions options = new UploadDirectoryOptions() { Recursive = true }; try { task = TransferManager.UploadDirectoryAsync(localDirectoryPath, blobDirectory, options, context, cancellationSource.Token); while (!task.IsCompleted) { if (Console.KeyAvailable) { keyinfo = Console.ReadKey(true); if (keyinfo.Key == ConsoleKey.C) { cancellationSource.Cancel(); } } } await task; } catch (Exception e) { Console.WriteLine("\nThe transfer is canceled: {0}", e.Message); } if (cancellationSource.IsCancellationRequested) { Console.WriteLine("\nTransfer will resume in 3 seconds..."); Thread.Sleep(3000); checkpoint = context.LastCheckpoint; context = Perf.GetDirectoryTransferContext(checkpoint); Console.WriteLine("\nResuming transfer...\n"); await TransferManager.UploadDirectoryAsync(localDirectoryPath, blobDirectory, options, context); } stopWatch.Stop(); Console.WriteLine("\nTransfer operation completed in " + stopWatch.Elapsed.TotalSeconds + " seconds."); ExecuteChoice(account); }
public static async Task TransferAzureBlobToAzureBlob(CloudStorageAccount account) { CloudBlockBlob sourceBlob = Upload.GetBlob(account); CloudBlockBlob destinationBlob = Upload.GetBlob(account); TransferCheckpoint checkpoint = null; SingleTransferContext context = Perf.GetSingleTransferContext(checkpoint); CancellationTokenSource cancellationSource = new CancellationTokenSource(); Console.WriteLine("\nTransfer started...\nPress 'c' to temporarily cancel your transfer...\n"); Stopwatch stopWatch = Stopwatch.StartNew(); Task task; ConsoleKeyInfo keyinfo; try { task = TransferManager.CopyAsync(sourceBlob, destinationBlob, true, null, context, cancellationSource.Token); while (!task.IsCompleted) { if (Console.KeyAvailable) { keyinfo = Console.ReadKey(true); if (keyinfo.Key == ConsoleKey.C) { cancellationSource.Cancel(); } } } await task; } catch (Exception e) { Console.WriteLine("\nThe transfer is canceled: {0}", e.Message); } if (cancellationSource.IsCancellationRequested) { Console.WriteLine("\nTransfer will resume in 3 seconds..."); Thread.Sleep(3000); checkpoint = context.LastCheckpoint; context = Perf.GetSingleTransferContext(checkpoint); Console.WriteLine("\nResuming transfer...\n"); await TransferManager.CopyAsync(sourceBlob, destinationBlob, false, null, context, cancellationSource.Token); } stopWatch.Stop(); Console.WriteLine("\nTransfer operation completed in " + stopWatch.Elapsed.TotalSeconds + " seconds."); ExecuteChoice(account); }