Пример #1
0
        internal async Task DeleteCloudAsyncTrack2(long taskId, IStorageBlobManagement localChannel, BlobBaseClient blob, Track2Models.DeleteSnapshotsOption deleteSnapshotsOption)
        {
            var responds = await blob.DeleteAsync(deleteSnapshotsOption, this.BlobRequestConditions, CmdletCancellationToken).ConfigureAwait(false);

            string result = String.Format(Resources.RemoveBlobSuccessfully, blob.Name, blob.BlobContainerName);

            OutputStream.WriteVerbose(taskId, result);

            if (PassThru)
            {
                OutputStream.WriteObject(taskId, true);
            }
        }
Пример #2
0
        /// <summary>
        /// remove the azure blob with Track2 SDK
        /// </summary>
        /// <param name="blob">BlobBaseClient object</param>
        /// <param name="isValidBlob">whether the Cloudblob parameter is validated</param>
        /// <returns>true if the blob is removed successfully, false if user cancel the remove operation</returns>
        internal async Task RemoveAzureBlobTrack2(long taskId, IStorageBlobManagement localChannel, BlobBaseClient blob, bool isValidBlob)
        {
            if (!isValidBlob)
            {
                ValidatePipelineCloudBlobTrack2(blob);
            }

            Track2Models.DeleteSnapshotsOption deleteSnapshotsOption = Track2Models.DeleteSnapshotsOption.None;
            bool retryDeleteSnapshot = false;

            if (Util.GetSnapshotTimeFromBlobUri(blob.Uri) != null)
            {
                if (deleteSnapshot)
                {
                    throw new ArgumentException(String.Format(Resources.CannotDeleteSnapshotForSnapshot, blob.Name, Util.GetSnapshotTimeFromBlobUri(blob.Uri)));
                }
            }
            else if (!string.IsNullOrEmpty(Util.GetVersionIdFromBlobUri(blob.Uri)))
            {
                if (deleteSnapshot)
                {
                    throw new ArgumentException(String.Format(Resources.CannotDeleteSnapshotForBlobVersion, blob.Name, Util.GetVersionIdFromBlobUri(blob.Uri)));
                }
            }
            else
            {
                if (deleteSnapshot)
                {
                    deleteSnapshotsOption = Track2Models.DeleteSnapshotsOption.OnlySnapshots;
                }
                else if (force)
                {
                    deleteSnapshotsOption = Track2Models.DeleteSnapshotsOption.IncludeSnapshots;
                }
                else
                {
                    retryDeleteSnapshot = true;
                }
            }

            try
            {
                await DeleteCloudAsyncTrack2(taskId, localChannel, blob, deleteSnapshotsOption).ConfigureAwait(false);

                retryDeleteSnapshot = false;
            }
            catch (global::Azure.RequestFailedException e) when(e.Status == 409)
            {
                if (retryDeleteSnapshot)
                {
                    //If x-ms-delete-snapshots is not specified on the request and the blob has associated snapshots, the Blob service returns status code 409 (Conflict).
                    retryDeleteSnapshot = true;
                }
                else
                {
                    throw;
                }
            }

            if (retryDeleteSnapshot)
            {
                string message = string.Format(Resources.ConfirmRemoveBlobWithSnapshot, blob.Name, blob.BlobContainerName);

                if (await OutputStream.ConfirmAsync(message).ConfigureAwait(false))
                {
                    deleteSnapshotsOption = Track2Models.DeleteSnapshotsOption.IncludeSnapshots;
                    await DeleteCloudAsyncTrack2(taskId, localChannel, blob, deleteSnapshotsOption).ConfigureAwait(false);
                }
                else
                {
                    string result = String.Format(Resources.RemoveBlobCancelled, blob.Name, blob.BlobContainerName);
                    OutputStream.WriteVerbose(taskId, result);
                }
            }
        }