예제 #1
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>
        /// 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="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));
        }