public Task DeleteShareAsync(CloudFileShare share, DeleteShareSnapshotsOption deleteShareSnapshotsOption, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
 {
     return(share.DeleteAsync(deleteShareSnapshotsOption, accessCondition, options, operationContext, cancellationToken));
 }
Ejemplo n.º 2
0
        public override void ExecuteCmdlet()
        {
            CloudFileShare share;

            switch (this.ParameterSetName)
            {
            case Constants.ShareParameterSetName:
                share = this.Share;
                break;

            case Constants.ShareNameParameterSetName:
                share = this.BuildFileShareObjectFromName(this.Name);
                break;

            default:
                throw new PSArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid parameter set name: {0}", this.ParameterSetName));
            }

            if (ShouldProcess(share.Name, "Remove share"))
            {
                this.RunTask(async taskId =>
                {
                    if (share.IsSnapshot && IncludeAllSnapshot.IsPresent)
                    {
                        throw new PSArgumentException(string.Format(CultureInfo.InvariantCulture, "'IncludeAllSnapshot' should only be specified to delete a base share, and should not be specified to delete a Share snapshot: {0}", share.SnapshotQualifiedUri));
                    }

                    if (force || ShareIsEmpty(share) || ShouldContinue(string.Format("Remove share and all content in it: {0}", share.Name), ""))
                    {
                        DeleteShareSnapshotsOption deleteShareSnapshotsOption = DeleteShareSnapshotsOption.None;
                        bool retryDeleteSnapshot = false;

                        //Force means will delete the share anyway, so use 'IncludeSnapshots' to delete the share even has snapshot, or delete will fail when share has snapshot
                        // To delete a Share shapshot, must use 'None'
                        if (IncludeAllSnapshot.IsPresent)
                        {
                            deleteShareSnapshotsOption = DeleteShareSnapshotsOption.IncludeSnapshots;
                        }
                        else
                        {
                            retryDeleteSnapshot = true;
                        }

                        try
                        {
                            await this.Channel.DeleteShareAsync(share, deleteShareSnapshotsOption, null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken).ConfigureAwait(false);
                            retryDeleteSnapshot = false;
                        }
                        catch (StorageException e)
                        {
                            //If x-ms-delete-snapshots is not specified on the request and the share has associated snapshots, the File service returns status code 409 (Conflict).
                            if (!(e.IsConflictException() && retryDeleteSnapshot))
                            {
                                throw;
                            }
                        }

                        if (retryDeleteSnapshot)
                        {
                            if (force || await OutputStream.ConfirmAsync(string.Format("This share might have snapshots, remove the share and all snapshots?: {0}", share.Name)).ConfigureAwait(false))
                            {
                                deleteShareSnapshotsOption = DeleteShareSnapshotsOption.IncludeSnapshots;
                                await this.Channel.DeleteShareAsync(share, deleteShareSnapshotsOption, null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken).ConfigureAwait(false);
                            }
                            else
                            {
                                string result = string.Format("The remove operation of share '{0}' has been cancelled.", share.Name);
                                OutputStream.WriteVerbose(taskId, result);
                            }
                        }
                    }

                    if (this.PassThru)
                    {
                        this.OutputStream.WriteObject(taskId, share);
                    }
                });
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructs a web request to delete the share and all of the files within it.
        /// </summary>
        /// <param name="uri">The absolute URI to the share.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="snapshot">A <see cref="DateTimeOffset"/> specifying the snapshot timestamp, if the share is a snapshot.</param>

        /// <param name="deleteSnapshotsOption">A <see cref="DeleteShareSnapshotsOption"/> object indicating whether to only delete the share or delete the share and all snapshots.</param>
        /// <param name="accessCondition">The access condition to apply to the request.</param>
        /// <returns>A web request to use to perform the operation.</returns>
        public static StorageRequestMessage Delete(Uri uri, int?timeout, DateTimeOffset?snapshot, DeleteShareSnapshotsOption deleteSnapshotsOption, AccessCondition accessCondition, HttpContent content, OperationContext operationContext, ICanonicalizer canonicalizer, StorageCredentials credentials)
        {
            UriQueryBuilder shareBuilder = GetShareUriQueryBuilder();

            ShareHttpRequestMessageFactory.AddShareSnapshot(shareBuilder, snapshot);
            StorageRequestMessage request = HttpRequestMessageFactory.Delete(uri, timeout, shareBuilder, content, operationContext, canonicalizer, credentials);

            switch (deleteSnapshotsOption)
            {
            case DeleteShareSnapshotsOption.None:
                break;     // nop

            case DeleteShareSnapshotsOption.IncludeSnapshots:
                request.Headers.Add(
                    Constants.HeaderConstants.DeleteSnapshotHeader,
                    Constants.HeaderConstants.IncludeSnapshotsValue);
                break;
            }

            request.ApplyAccessCondition(accessCondition);
            return(request);
        }
 private RESTCommand <NullType> DeleteShareImpl(DeleteShareSnapshotsOption deleteSnapshotsOption, AccessCondition accessCondition, FileRequestOptions options)
 {
     throw new System.NotImplementedException();
 }
 public virtual Task <bool> DeleteIfExistsAsync(DeleteShareSnapshotsOption deleteSnapshotsOption, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Constructs a web request to delete the share and all of the files within it.
        /// </summary>
        /// <param name="uri">The absolute URI to the share.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="snapshot">A <see cref="DateTimeOffset"/> specifying the snapshot timestamp, if the share is a snapshot.</param>
        /// <param name="deleteSnapshotsOption">A <see cref="DeleteShareSnapshotsOption"/> object indicating whether to only delete the share or delete the share and all snapshots.</param>
        /// <param name="accessCondition">The access condition to apply to the request.</param>
        /// <param name="useVersionHeader">A flag indicating whether to set the x-ms-version HTTP header.</param>
        /// <param name="operationContext">An <see cref="OperationContext" /> object for tracking the current operation.</param>
        /// <returns>A web request to use to perform the operation.</returns>
        internal static HttpWebRequest Delete(Uri uri, int?timeout, DateTimeOffset?snapshot, DeleteShareSnapshotsOption deleteSnapshotsOption, AccessCondition accessCondition, bool useVersionHeader, OperationContext operationContext)
        {
            if ((snapshot != null) && (deleteSnapshotsOption != DeleteShareSnapshotsOption.None))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, SR.DeleteSnapshotsNotValidError, "deleteSnapshotsOption", "snapshot"));
            }

            UriQueryBuilder shareBuilder = GetShareUriQueryBuilder();

            ShareHttpWebRequestFactory.AddShareSnapshot(shareBuilder, snapshot);
            HttpWebRequest request = HttpWebRequestFactory.Delete(uri, shareBuilder, timeout, useVersionHeader, operationContext);

            switch (deleteSnapshotsOption)
            {
            case DeleteShareSnapshotsOption.None:
                break;     // nop

            case DeleteShareSnapshotsOption.IncludeSnapshots:
                request.Headers.Add(
                    Constants.HeaderConstants.DeleteSnapshotHeader,
                    Constants.HeaderConstants.IncludeSnapshotsValue);
                break;
            }

            request.ApplyAccessCondition(accessCondition);
            return(request);
        }
 public Task DeleteShareAsync(CloudFileShare share, DeleteShareSnapshotsOption deleteShareSnapshotsOption, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
 {
     return(TaskEx.FromResult(true));
 }