コード例 #1
0
        /// <summary>
        /// Creates a new collection resource at the location specified by the request URI.
        /// </summary>
        /// <param name="requestUri">The <see cref="Uri"/> to request.</param>
        /// <param name="parameters">Parameters of the MKCOL operation.</param>
        /// <returns>An instance of <see cref="WebDavResponse" />.</returns>
        public async Task <WebDavResponse> Mkcol(Uri requestUri, MkColParameters parameters)
        {
            Guard.NotNull(requestUri, "requestUri");

            var headerBuilder = new HeaderBuilder();

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

            var headers       = headerBuilder.AddWithOverwrite(parameters.Headers).Build();
            var requestParams = new RequestParameters {
                Headers = headers
            };
            var response = await _dispatcher.Send(requestUri, WebDavMethod.Mkcol, requestParams, parameters.CancellationToken).ConfigureAwait(false);

            return(new WebDavResponse((int)response.StatusCode, response.ReasonPhrase));
        }
コード例 #2
0
        /// <summary>
        /// Deletes 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 DELETE operation.</param>
        /// <returns>An instance of <see cref="WebDavResponse" /></returns>
        public async Task <WebDavResponse> Delete(Uri requestUri, DeleteParameters parameters)
        {
            Guard.NotNull(requestUri, "requestUri");

            var headerBuilder = new HeaderBuilder();

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

            var headers       = headerBuilder.AddWithOverwrite(parameters.Headers).Build();
            var requestParams = new RequestParameters {
                Headers = headers
            };
            var response = await _dispatcher.Send(requestUri, HttpMethod.Delete, requestParams, parameters.CancellationToken);

            return(new WebDavResponse(response.StatusCode, response.Description));
        }
コード例 #3
0
ファイル: WebDavClient.cs プロジェクト: StefH/WebDAV-Client
        /// <summary>
        /// Deletes 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 DELETE operation.</param>
        /// <returns>An instance of <see cref="WebDavResponse" /></returns>
        public async Task <WebDavResponse> Delete([NotNull] Uri requestUri, [NotNull] DeleteParameters parameters)
        {
            Check.NotNull(requestUri, nameof(requestUri));
            Check.NotNull(parameters, nameof(parameters));

            var headers = new RequestHeaders();

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

            var requestParams = new RequestParameters {
                Headers = headers
            };

            var response = await _dispatcher.Send(requestUri, HttpMethod.Delete, requestParams, parameters.CancellationToken);

            return(new WebDavResponse(response.StatusCode, response.Description));
        }
コード例 #4
0
        /// <summary>
        /// Deletes the resource identified by the request URI.
        /// </summary>
        public WebDavResponse Delete(Uri requestUri, DeleteParameters parameters)
        {
            Guard.NotNull(requestUri, "requestUri");

            var headerBuilder = new HeaderBuilder();

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

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

            using (var response = _dispatcher.Send(requestUri, HttpMethod.Delete, requestParams))
            {
                return(new WebDavResponse(response));
            }
        }
コード例 #5
0
        /// <summary>
        /// Requests the resource to be stored under the request URI.
        /// </summary>
        /// <param name="requestUri">The <see cref="Uri"/> to request.</param>
        /// <param name="content">The content to pass to the request.</param>
        /// <param name="parameters">Parameters of the PUT operation.</param>
        /// <returns>An instance of <see cref="WebDavResponse" />.</returns>
        public WebDavResponse PutFile(Uri requestUri, HttpContent content, PutFileParameters parameters)
        {
            Guard.NotNull(requestUri, "requestUri");
            Guard.NotNull(content, "content");

            var headerBuilder = new HeaderBuilder();

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

            var headers       = headerBuilder.AddWithOverwrite(parameters.Headers).Build();
            var requestParams = new RequestParameters {
                Headers = headers, Content = content, ContentType = parameters.ContentType, OperationProgress = parameters.OperationProgress
            };

            using (var response = _dispatcher.Send(requestUri, HttpMethod.Put, requestParams))
            {
                return(new WebDavResponse(response));
            }
        }
コード例 #6
0
        /// <summary>
        /// Sets and/or removes 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 PROPPATCH operation.</param>
        /// <returns>An instance of <see cref="ProppatchResponse" /></returns>
        public async Task <ProppatchResponse> Proppatch(Uri requestUri, ProppatchParameters parameters)
        {
            Guard.NotNull(requestUri, "requestUri");

            var headers = new RequestHeaders();

            if (!string.IsNullOrEmpty(parameters.LockToken))
            {
                headers.Add(new KeyValuePair <string, string>("If", IfHeaderHelper.GetHeaderValue(parameters.LockToken)));
            }
            var requestBody = ProppatchRequestBuilder.BuildRequestBody(
                parameters.PropertiesToSet,
                parameters.PropertiesToRemove,
                parameters.Namespaces);
            var requestParams = new RequestParameters {
                Headers = headers, Content = new StringContent(requestBody)
            };
            var response = await _dispatcher.Send(requestUri, WebDavMethod.Proppatch, requestParams, parameters.CancellationToken);

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

            return(_proppatchResponseParser.Parse(responseContent, response.StatusCode, response.Description));
        }
コード例 #7
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="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 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 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
            };
            var response = await _dispatcher.Send(sourceUri, WebDavMethod.Copy, requestParams, parameters.CancellationToken).ConfigureAwait(false);

            return(new WebDavResponse((int)response.StatusCode, response.ReasonPhrase));
        }