Represents parameters for the PROPFIND WebDAV method.
Ejemplo n.º 1
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 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));
                }
            }
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
0
        public bool IsDirectoryExist(string webDavLocation)
        {
            webDavLocation = webDavLocation.Replace("\\", "/").Trim('/');
            var webDavFile = new Uri($"{this.BaseAddress}{webDavLocation}");

            var propFind1 = new PropfindParameters();
            var propFind  = this.PropFind(webDavFile, propFind1);

            if (!propFind.IsSuccessful)
            {
                if (propFind.StatusCode == 404)
                {
                    return(false);
                }

                throw new ApplicationException($"Unable read file props: --> {propFind.StatusCode} {propFind.Description}");
            }
            return(propFind.Resources[0].IsCollection);
        }
Ejemplo n.º 4
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));
        }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Retrieves properties defined on the resource identified by the request URI.
 /// </summary>
 /// <param name="requestUri">A string that represents the request URI.</param>
 /// <param name="parameters">Parameters of the PROPFIND operation.</param>
 /// <returns>An instance of <see cref="PropfindResponse" />.</returns>
 public PropfindResponse PropFind(string requestUri, PropfindParameters parameters)
 {
     return(PropFind(CreateUri(requestUri), parameters));
 }