Represents parameters for the COPY WebDAV method.
        /// <summary>
        /// Creates a duplicate of the source resource identified by the source URI in the destination resource identified by the destination URI.
        /// </summary>
        /// <param name="sourceUri">The source <see cref="Uri"/>.</param>
        /// <param name="destUri">The destination <see cref="Uri"/>.</param>
        /// <param name="parameters">Parameters of the COPY operation.</param>
        /// <returns>An instance of <see cref="WebDavResponse" /></returns>
        public WebDavResponse Copy(Uri sourceUri, Uri destUri, CopyParameters parameters)
        {
            Guard.NotNull(sourceUri, "sourceUri");
            Guard.NotNull(destUri, "destUri");

            var applyTo       = parameters.ApplyTo ?? ApplyTo.Copy.ResourceAndAncestors;
            var headerBuilder = new HeaderBuilder()
                                .Add(WebDavHeaders.Destination, GetAbsoluteUri(destUri).AbsoluteUri)
                                .Add(WebDavHeaders.Depth, DepthHeaderHelper.GetValueForCopy(applyTo))
                                .Add(WebDavHeaders.Overwrite, parameters.Overwrite ? "T" : "F");

            if (!string.IsNullOrEmpty(parameters.DestLockToken))
            {
                headerBuilder.Add(WebDavHeaders.If, IfHeaderHelper.GetHeaderValue(parameters.DestLockToken));
            }

            var headers       = headerBuilder.AddWithOverwrite(parameters.Headers).Build();
            var requestParams = new RequestParameters {
                Headers = headers
            };

            using (var response = _dispatcher.Send(sourceUri, WebDavMethod.Copy, requestParams))
            {
                return(new WebDavResponse((int)response.StatusCode, response.StatusDescription));
            }
        }
Пример #2
0
        /// <summary>
        /// Creates a duplicate of the source resource identified by the source URI in the destination resource identified by the destination URI.
        /// </summary>
        /// <param name="sourceUri">The source <see cref="T:System.Uri"/>.</param>
        /// <param name="destUri">The destination <see cref="T:System.Uri"/>.</param>
        /// <param name="parameters">Parameters of the COPY operation.</param>
        /// <returns>An instance of <see cref="WebDavResponse" /></returns>
        public async Task <WebDavResponse> Copy(Uri sourceUri, Uri destUri, CopyParameters parameters)
        {
            Guard.NotNull(sourceUri, "sourceUri");
            Guard.NotNull(destUri, "destUri");

            var applyTo = parameters.ApplyTo ?? ApplyTo.Copy.ResourceAndAncestors;
            var headers = new RequestHeaders
            {
                new KeyValuePair <string, string>("Destination", GetAbsoluteUri(destUri).AbsoluteUri),
                new KeyValuePair <string, string>("Depth", DepthHeaderHelper.GetValueForCopy(applyTo)),
                new KeyValuePair <string, string>("Overwrite", parameters.Overwrite ? "T" : "F")
            };

            if (!string.IsNullOrEmpty(parameters.DestLockToken))
            {
                headers.Add(new KeyValuePair <string, string>("If", IfHeaderHelper.GetHeaderValue(parameters.DestLockToken)));
            }

            var requestParams = new RequestParameters {
                Headers = headers
            };
            var response = await _dispatcher.Send(sourceUri, WebDavMethod.Copy, requestParams, parameters.CancellationToken);

            return(new WebDavResponse(response.StatusCode, response.Description));
        }
 /// <summary>
 /// Creates a duplicate of the source resource identified by the source URI in the destination resource identified by the destination URI.
 /// </summary>
 /// <param name="sourceUri">A string that represents the source URI.</param>
 /// <param name="destUri">A string that represents the destination URI.</param>
 /// <param name="parameters">Parameters of the COPY operation.</param>
 /// <returns>An instance of <see cref="WebDavResponse" />.</returns>
 public WebDavResponse Copy(string sourceUri, string destUri, CopyParameters parameters)
 {
     return(Copy(CreateUri(sourceUri), CreateUri(destUri), parameters));
 }