示例#1
0
        // </Snippet_CopyBlob>

        //-------------------------------------------------
        // Stop a blob copy operation
        //-------------------------------------------------
        private static async Task StopBlobCopyAsync(BlobContainerClient container)
        {
            try
            {
                // Get the name of the first blob in the container to use as the source.
                string blobName = container.GetBlobs().FirstOrDefault().Name;

                // Create a BlobClient representing the source blob to copy.
                BlobClient sourceBlob = container.GetBlobClient(blobName);

                // Ensure that the source blob exists.
                if (await sourceBlob.ExistsAsync())
                {
                    // Get a BlobClient representing the destination blob with a unique name.
                    BlobClient destBlob =
                        container.GetBlobClient(Guid.NewGuid() + "-" + sourceBlob.Name);

                    // Start the copy operation.
                    destBlob.StartCopyFromUri(sourceBlob.Uri);

                    // <Snippet_StopBlobCopy>
                    // Get the destination blob's properties to check the copy status.
                    BlobProperties destProperties = destBlob.GetProperties();

                    // Check the copy status. If the status is pending, abort the copy operation.
                    if (destProperties.CopyStatus == CopyStatus.Pending)
                    {
                        await destBlob.AbortCopyFromUriAsync(destProperties.CopyId);

                        Console.WriteLine($"Copy operation {destProperties.CopyId} has been aborted.");
                    }
                    // </Snippet_StopBlobCopy>
                    else
                    {
                        Console.WriteLine($"Copy status: {destProperties.CopyStatus}");
                        Console.WriteLine($"Copy progress: {destProperties.CopyProgress}");
                        Console.WriteLine($"Completion time: {destProperties.CopyCompletedOn}");
                        Console.WriteLine($"Total bytes: {destProperties.ContentLength}");
                    }
                }
            }
            catch (RequestFailedException ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
                throw;
            }
        }
示例#2
0
        public async Task <bool> AbortCopyBlobFromUri(string copyOperationId, string blobName, string containerName, CancellationToken cancellationToken)
        {
            BlobClient client =
                BlobStorageManager.GetBlobClient(
                    azureStorageOptions: _azureStorageOptions,
                    containerName: containerName,
                    blobName: blobName);

            try
            {
                Azure.Response response = await client.AbortCopyFromUriAsync(copyId : copyOperationId, cancellationToken : cancellationToken);

                return(response.Status == (int)HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                throw new BlobServiceException(
                          message: ex.Message,
                          blobName: blobName,
                          containerName: containerName,
                          methodName: nameof(AbortCopyBlobFromUri),
                          innerException: ex);
            }
        }