/// <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));
            }
        }
        /// <summary>
        /// Takes out a lock of any type or refreshes an existing lock of the resource identified by the request URI.
        /// </summary>
        /// <param name="requestUri">The <see cref="Uri"/> to request.</param>
        /// <param name="parameters">Parameters of the LOCK operation.</param>
        /// <returns>An instance of <see cref="LockResponse" />.</returns>
        public LockResponse Lock(Uri requestUri, LockParameters parameters)
        {
            Guard.NotNull(requestUri, "requestUri");

            var headerBuilder = new HeaderBuilder();

            if (parameters.ApplyTo.HasValue)
            {
                headerBuilder.Add(WebDavHeaders.Depth, DepthHeaderHelper.GetValueForLock(parameters.ApplyTo.Value));
            }
            if (parameters.Timeout.HasValue)
            {
                headerBuilder.Add(WebDavHeaders.Timeout, $"Second-{parameters.Timeout.Value.TotalSeconds}");
            }

            var headers     = headerBuilder.AddWithOverwrite(parameters.Headers).Build();
            var requestBody = LockRequestBuilder.BuildRequestBody(parameters);

            using (var content = new StringContent(requestBody))
            {
                var requestParams = new RequestParameters {
                    Headers = headers, Content = content
                };
                using (var response = _dispatcher.Send(requestUri, WebDavMethod.Lock, requestParams))
                {
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        return(new LockResponse((int)response.StatusCode, response.StatusDescription));
                    }

                    var responseContent = ReadContentAsString(response);
                    return(_lockResponseParser.Parse(responseContent, (int)response.StatusCode, response.StatusDescription));
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Takes out a lock of any type or refreshes an existing lock of the resource identified by the request URI.
        /// </summary>
        /// <param name="requestUri">The <see cref="System.Uri"/> to request.</param>
        /// <param name="parameters">Parameters of the LOCK operation.</param>
        /// <returns>An instance of <see cref="LockResponse" /></returns>
        public async Task <LockResponse> Lock([NotNull] Uri requestUri, [NotNull] LockParameters parameters)
        {
            Check.NotNull(requestUri, nameof(requestUri));
            Check.NotNull(parameters, nameof(parameters));

            var headers = new RequestHeaders();

            if (parameters.ApplyTo.HasValue)
            {
                headers.Add(new KeyValuePair <string, string>("Depth", DepthHeaderHelper.GetValueForLock(parameters.ApplyTo.Value)));
            }

            if (parameters.Timeout.HasValue)
            {
                headers.Add(new KeyValuePair <string, string>("Timeout", $"Second-{parameters.Timeout.Value.TotalSeconds}"));
            }

            string requestBody = LockRequestBuilder.BuildRequestBody(parameters);

            var requestParams = new RequestParameters {
                Headers = headers, Content = new StringContent(requestBody, DefaultEncoding, MediaTypeXml)
            };

            var response = await _dispatcher.Send(requestUri, WebDavMethod.Lock, requestParams, parameters.CancellationToken);

            if (!response.IsSuccessful)
            {
                return(new LockResponse(response.StatusCode, response.Description));
            }

            var responseContent = await ReadContentAsString(response.Content).ConfigureAwait(false);

            return(_lockResponseParser.Parse(responseContent, response.StatusCode, response.Description));
        }
        /// <summary>
        /// Retrieves properties defined on the resource identified by the request URI.
        /// </summary>
        /// <param name="requestUri">The <see cref="Uri"/> to request.</param>
        /// <param name="parameters">Parameters of the PROPFIND operation.</param>
        /// <returns>An instance of <see cref="PropfindResponse" />.</returns>
        public PropfindResponse PropFind(Uri requestUri, PropfindParameters parameters)
        {
            Guard.NotNull(requestUri, "requestUri");

            var applyTo = parameters.ApplyTo ?? ApplyTo.Propfind.ResourceAndChildren;
            var headers = new HeaderBuilder()
                          .Add(WebDavHeaders.Depth, DepthHeaderHelper.GetValueForPropfind(applyTo))
                          .AddWithOverwrite(parameters.Headers)
                          .Build();

            var requestBody = PropfindRequestBuilder.BuildRequest(parameters.RequestType, parameters.CustomProperties, parameters.Namespaces);

            using (var content = new StringContent(requestBody))
            {
                var requestParams = new RequestParameters
                {
                    Headers = headers,
                    Content = content
                };

                using (var response = _dispatcher.Send(requestUri, WebDavMethod.Propfind, requestParams))
                {
                    var responseContent = ReadContentAsString(response);
                    return(_propfindResponseParser.Parse(responseContent, (int)response.StatusCode, response.StatusDescription));
                }
            }
        }
Пример #5
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([NotNull] Uri sourceUri, [NotNull] Uri destUri, [NotNull] CopyParameters parameters)
        {
            Check.NotNull(sourceUri, nameof(sourceUri));
            Check.NotNull(destUri, nameof(destUri));
            Check.NotNull(parameters, nameof(parameters));

            var applyTo = parameters.ApplyTo ?? ApplyTo.Copy.ResourceAndAncestors;
            var headers = new RequestHeaders
            {
                new KeyValuePair <string, string>("Destination", GetAbsoluteUri(destUri).ToString()),
                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));
        }
Пример #6
0
        /// <summary>
        /// Takes out a lock of any type or refreshes an existing lock of the resource identified by the request URI.
        /// </summary>
        /// <param name="requestUri">The <see cref="Uri"/> to request.</param>
        /// <param name="parameters">Parameters of the LOCK operation.</param>
        /// <returns>An instance of <see cref="LockResponse" />.</returns>
        public async Task <LockResponse> Lock(Uri requestUri, LockParameters parameters)
        {
            Guard.NotNull(requestUri, "requestUri");

            var headerBuilder = new HeaderBuilder();

            if (parameters.ApplyTo.HasValue)
            {
                headerBuilder.Add(WebDavHeaders.Depth, DepthHeaderHelper.GetValueForLock(parameters.ApplyTo.Value));
            }
            if (parameters.Timeout.HasValue)
            {
                headerBuilder.Add(WebDavHeaders.Timeout, $"Second-{parameters.Timeout.Value.TotalSeconds}");
            }

            var headers       = headerBuilder.AddWithOverwrite(parameters.Headers).Build();
            var requestBody   = LockRequestBuilder.BuildRequestBody(parameters);
            var requestParams = new RequestParameters {
                Headers = headers, Content = new StringContent(requestBody), ContentType = parameters.ContentType
            };
            var response = await _dispatcher.Send(requestUri, WebDavMethod.Lock, requestParams, parameters.CancellationToken).ConfigureAwait(false);

            if (!response.IsSuccessStatusCode)
            {
                return(new LockResponse((int)response.StatusCode, response.ReasonPhrase));
            }

            var responseContent = await ReadContentAsString(response.Content).ConfigureAwait(false);

            return(_lockResponseParser.Parse(responseContent, (int)response.StatusCode, response.ReasonPhrase));
        }
Пример #7
0
        /// <summary>
        /// Retrieves properties defined on the resource identified by the request URI.
        /// </summary>
        /// <param name="requestUri">The <see cref="Uri"/> to request.</param>
        /// <param name="parameters">Parameters of the PROPFIND operation.</param>
        /// <returns>An instance of <see cref="PropfindResponse" />.</returns>
        public async Task <PropfindResponse> Propfind(Uri requestUri, PropfindParameters parameters)
        {
            Guard.NotNull(requestUri, "requestUri");

            var applyTo = parameters.ApplyTo ?? ApplyTo.Propfind.ResourceAndChildren;
            var headers = new HeaderBuilder()
                          .Add(WebDavHeaders.Depth, DepthHeaderHelper.GetValueForPropfind(applyTo))
                          .AddWithOverwrite(parameters.Headers)
                          .Build();

            HttpContent requestBody = null;

            if (parameters.RequestType != PropfindRequestType.AllPropertiesImplied)
            {
                var content = PropfindRequestBuilder.BuildRequest(parameters.RequestType, parameters.CustomProperties, parameters.Namespaces);
                requestBody = new StringContent(content);
            }

            var requestParams = new RequestParameters {
                Headers = headers, Content = requestBody, ContentType = parameters.ContentType
            };
            var response = await _dispatcher.Send(requestUri, WebDavMethod.Propfind, requestParams, parameters.CancellationToken).ConfigureAwait(false);

            var responseContent = await ReadContentAsString(response.Content).ConfigureAwait(false);

            return(_propfindResponseParser.Parse(responseContent, (int)response.StatusCode, response.ReasonPhrase));
        }
Пример #8
0
        /// <summary>
        /// Retrieves properties defined on the resource identified by the request URI.
        /// </summary>
        /// <param name="requestUri">The <see cref="System.Uri"/> to request.</param>
        /// <param name="parameters">Parameters of the PROPFIND operation.</param>
        /// <returns>An instance of <see cref="PropfindResponse" /></returns>
        public async Task <PropfindResponse> Propfind(Uri requestUri, PropfindParameters parameters)
        {
            Guard.NotNull(requestUri, "requestUri");

            var applyTo = parameters.ApplyTo ?? ApplyTo.Propfind.ResourceAndChildren;
            var headers = new RequestHeaders
            {
                new KeyValuePair <string, string>("Depth", DepthHeaderHelper.GetValueForPropfind(applyTo))
            };
            var requestBody   = PropfindRequestBuilder.BuildRequestBody(parameters.CustomProperties, parameters.Namespaces);
            var requestParams = new RequestParameters {
                Headers = headers, Content = new StringContent(requestBody)
            };
            var response = await _dispatcher.Send(requestUri, WebDavMethod.Propfind, requestParams, parameters.CancellationToken);

            var responseContent = await ReadContentAsString(response.Content).ConfigureAwait(false);

            return(_propfindResponseParser.Parse(responseContent, response.StatusCode, response.Description));
        }
Пример #9
0
        /// <summary>
        /// Retrieves properties defined on the resource identified by the request URI.
        /// </summary>
        /// <param name="requestUri">The <see cref="System.Uri"/> to request.</param>
        /// <param name="parameters">Parameters of the PROPFIND operation.</param>
        /// <returns>An instance of <see cref="PropfindResponse" /></returns>
        public async Task <PropfindResponse> Propfind([NotNull] Uri requestUri, [NotNull] PropfindParameters parameters)
        {
            Check.NotNull(requestUri, nameof(requestUri));
            Check.NotNull(parameters, nameof(parameters));

            var applyTo = parameters.ApplyTo ?? ApplyTo.Propfind.ResourceAndChildren;
            var headers = new RequestHeaders
            {
                new KeyValuePair <string, string>("Depth", DepthHeaderHelper.GetValueForPropfind(applyTo))
            };

            HttpContent requestContent = parameters.RequestType != PropfindRequestType.AllPropertiesImplied
                ? new StringContent(PropfindRequestBuilder.BuildRequestBody(parameters.RequestType, parameters.CustomProperties, parameters.Namespaces), DefaultEncoding, MediaTypeXml)
                : null;

            var requestParams = new RequestParameters {
                Headers = headers, Content = requestContent, ContentType = MediaTypeXml
            };
            var response = await _dispatcher.Send(requestUri, WebDavMethod.Propfind, requestParams, parameters.CancellationToken);

            var responseContent = await ReadContentAsString(response.Content).ConfigureAwait(false);

            return(_propfindResponseParser.Parse(responseContent, response.StatusCode, response.Description));
        }