Пример #1
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([NotNull] Uri requestUri, [NotNull] ProppatchParameters 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)));
            }

            string requestBody = ProppatchRequestBuilder.BuildRequestBody(
                parameters.PropertiesToSet,
                parameters.PropertiesToRemove,
                parameters.Namespaces);

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

            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));
        }
        /// <summary>
        /// Sets and/or removes 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 PROPPATCH operation.</param>
        /// <returns>An instance of <see cref="ProppatchResponse" />.</returns>
        public ProppatchResponse Proppatch(Uri requestUri, ProppatchParameters 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 requestBody = ProppatchRequestBuilder.BuildRequestBody(
                parameters.PropertiesToSet,
                parameters.PropertiesToRemove,
                parameters.Namespaces);

            using (var content = new StringContent(requestBody))
            {
                var requestParams = new RequestParameters {
                    Headers = headers, Content = content
                };
                using (var response = _dispatcher.Send(requestUri, WebDavMethod.Proppatch, requestParams))
                {
                    var responseContent = ReadContentAsString(response);
                    return(_proppatchResponseParser.Parse(responseContent, (int)response.StatusCode, response.StatusDescription));
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Sets and/or removes 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 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 headerBuilder = new HeaderBuilder();

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

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

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

            return(_proppatchResponseParser.Parse(responseContent, (int)response.StatusCode, response.ReasonPhrase));
        }