/// <inheritdoc />
 public Task <IWebDavResult> PropFindAsync(string path, propfind request, CancellationToken cancellationToken)
 {
     if (_propFindHandler == null)
     {
         throw new NotSupportedException();
     }
     return(_propFindHandler.PropFindAsync(path, request, cancellationToken));
 }
        public async Task <IActionResult> PropFindAsync(
            string path,
            [FromBody] propfind request,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            var result = await _dispatcher.Class1.PropFindAsync(path ?? string.Empty, request, cancellationToken);

            return(new WebDavIndirectResult(_dispatcher, result, _responseLogger));
        }
示例#3
0
        internal Task <IActionResult> QuearyManualControllerCall(HttpContext context, string filePath, IServiceProvider serviceProvider, CancellationToken ct = default(CancellationToken))
        {
            switch (context.Request.Method.ToUpperInvariant())
            {
            case "OPTIONS":
                return(QueryOptionsAsync(filePath, ct));

            case "MKCOL":
                return(MkColAsync(filePath, ct));

            case "GET":
                return(GetAsync(filePath, ct));

            case "PUT":
                return(PutAsync(filePath, ct));

            case "DELETE":
                return(DeleteAsync(filePath, ct));

            case "PROPFIND":
                propfind request = null;
                return(PropFindAsync(filePath, request, ct));

            case "PROPPATCH":
                propertyupdate propUp = null;
                return(PropPatchAsync(filePath, propUp, ct));

            case "HEAD":
                return(HeadAsync(filePath, ct));

            case "COPY":
                string copyDestination = context.Request.Headers["Destination"];
                return(CopyAsync(filePath, copyDestination, ct));

            case "MOVE":
                string moveDestination = context.Request.Headers["Destination"];
                return(MoveAsync(filePath, moveDestination, ct));

            case "LOCK":
                Stream       body = context.Request.Body;
                MemoryStream mem  = new MemoryStream();
                body.CopyTo(mem);
                body.Dispose();
                byte[] raw  = mem.ToArray();
                string json = Encoding.UTF8.GetString(raw);    //?
                return(LockAsync(filePath, null, ct));

            case "UNLOCK":
                string lockToken = context.Request.Headers["Lock-Token"];
                return(this.UnlockAsync(filePath, lockToken));

            default:
                return(null);
            }
        }
示例#4
0
        public async Task <IActionResult> PropFindAsync(
            string path,
            [FromBody] propfind request,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            var routeData = HttpContext.GetRouteData();
            var baseUrl   = Url.RouteUrl((object)null);
            //var a = HttpContext. .GetLeftPart(UriPartial.Authority);
            var result = await _dispatcher.Class1.PropFindAsync(path ?? string.Empty, request, cancellationToken).ConfigureAwait(false);

            return(new WebDavIndirectResult(_dispatcher, result, _responseLogger));
        }
        /// <inheritdoc />
        public async Task <IWebDavResult> PropFindAsync(string path, propfind request, CancellationToken cancellationToken)
        {
            var selectionResult = await FileSystem.SelectAsync(path, cancellationToken).ConfigureAwait(false);

            if (selectionResult.IsMissing)
            {
                if (_context.RequestHeaders.IfNoneMatch != null)
                {
                    throw new WebDavException(WebDavStatusCode.PreconditionFailed);
                }

                throw new WebDavException(WebDavStatusCode.NotFound);
            }

            await _context.RequestHeaders
            .ValidateAsync(selectionResult.TargetEntry, cancellationToken).ConfigureAwait(false);

            var entries = new List <IEntry>();

            if (selectionResult.ResultType == SelectionResultType.FoundDocument)
            {
                entries.Add(selectionResult.Document);
            }
            else
            {
                Debug.Assert(selectionResult.Collection != null, "selectionResult.Collection != null");
                Debug.Assert(selectionResult.ResultType == SelectionResultType.FoundCollection, "selectionResult.ResultType == SelectionResultType.FoundCollection");
                entries.Add(selectionResult.Collection);
                var collector = selectionResult.Collection as IRecusiveChildrenCollector;
                var depth     = _context.RequestHeaders.Depth ?? (collector == null ? DepthHeader.One : DepthHeader.Infinity);
                if (depth == DepthHeader.One)
                {
                    entries.AddRange(await selectionResult.Collection.GetChildrenAsync(cancellationToken).ConfigureAwait(false));
                }
                else if (depth == DepthHeader.Infinity)
                {
                    if (collector == null)
                    {
                        // Cannot recursively collect the children with infinite depth
                        return(new WebDavResult <error>(WebDavStatusCode.Forbidden, new error()
                        {
                            ItemsElementName = new[] { ItemsChoiceType.propfindfinitedepth, },
                            Items = new[] { new object(), },
                        }));
                    }

                    var remainingDepth = depth.OrderValue - (depth != DepthHeader.Infinity ? 1 : 0);
                    using (var entriesEnumerator = collector.GetEntries(remainingDepth).GetEnumerator())
                    {
                        while (await entriesEnumerator.MoveNext(cancellationToken).ConfigureAwait(false))
                        {
                            entries.Add(entriesEnumerator.Current);
                        }
                    }
                }
            }

            if (request == null)
            {
                return(await HandleAllPropAsync(entries, cancellationToken).ConfigureAwait(false));
            }

            Debug.Assert(request.ItemsElementName != null, "request.ItemsElementName != null");
            switch (request.ItemsElementName[0])
            {
            case ItemsChoiceType1.allprop:
                return(await HandleAllPropAsync(request, entries, cancellationToken).ConfigureAwait(false));

            case ItemsChoiceType1.prop:
                Debug.Assert(request.Items != null, "request.Items != null");
                Debug.Assert(request.Items[0] != null, "request.Items[0] != null");
                return(await HandlePropAsync((prop)request.Items[0], entries, cancellationToken).ConfigureAwait(false));

            case ItemsChoiceType1.propname:
                return(await HandlePropNameAsync(entries, cancellationToken).ConfigureAwait(false));
            }

            throw new WebDavException(WebDavStatusCode.Forbidden);
        }
        private Task <IWebDavResult> HandleAllPropAsync([NotNull] propfind request, [NotNull][ItemNotNull] IEnumerable <IEntry> entries, CancellationToken cancellationToken)
        {
            var include = request.ItemsElementName.Select((x, i) => Tuple.Create(x, i)).Where(x => x.Item1 == ItemsChoiceType1.include).Select(x => (include)request.Items[x.Item2]).FirstOrDefault();

            return(HandleAllPropAsync(include, entries, cancellationToken));
        }
        /// <inheritdoc />
        public async Task <ITarget> GetAsync(RemoteCollectionTarget collection, string name, CancellationToken cancellationToken)
        {
            var requestData = new propfind()
            {
                ItemsElementName = new[] { ItemsChoiceType1.prop, },
                Items            = new object[]
                {
                    new prop()
                    {
                        Any = new[]
                        {
                            new XElement(Props.Live.ResourceTypeProperty.PropertyName),
                        },
                    },
                },
            };

            multistatus result;

            var targetUrl = collection.DestinationUrl.Append(name, false);

            using (var httpRequest = new HttpRequestMessage(_propFindHttpMethod, targetUrl)
            {
                Headers =
                {
                    { "Depth", DepthHeader.Zero.Value },
                },
                Content = CreateContent(_propFindSerializer, requestData),
            })
            {
                using (var httpResponse = await Client.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false))
                {
                    if (httpResponse.StatusCode == HttpStatusCode.NotFound)
                    {
                        return(new RemoteMissingTarget(collection, targetUrl, name, this));
                    }

                    var resultDoc = await ReadResponseAsync(httpResponse).ConfigureAwait(false);

                    if (resultDoc == null)
                    {
                        throw new RemoteTargetException("The destination server didn't return a response", targetUrl);
                    }

                    result = Parse(targetUrl, httpResponse, resultDoc);
                }
            }

            if (result.response == null || result.response.Length == 0)
            {
                throw new RemoteTargetException("The destination server didn't return a response", targetUrl);
            }
            if (result.response.Length != 1)
            {
                throw new RemoteTargetException("Received more than one multi-status response", targetUrl);
            }

            var response = result.response[0];

            var hrefs = response.GetHrefs().Select(x => new Uri(x, UriKind.RelativeOrAbsolute)).ToList();

            if (hrefs.Count == 0)
            {
                hrefs.Add(targetUrl);
            }

            var statusIndex    = Array.IndexOf(response.ItemsElementName, ItemsChoiceType2.status);
            var responseStatus = GetStatusCode(
                response.error,
                statusIndex == -1 ? null : (string)response.Items[statusIndex],
                targetUrl,
                hrefs);

            if (responseStatus == (int)WebDavStatusCode.NotFound)
            {
                return(new RemoteMissingTarget(collection, targetUrl, name, this));
            }

            var propStatIndex = Array.IndexOf(response.ItemsElementName, ItemsChoiceType2.propstat);

            if (propStatIndex == -1)
            {
                throw new RemoteTargetException("No result returned", hrefs);
            }

            var propStat   = (propstat)response.Items[propStatIndex];
            var location   = string.IsNullOrEmpty(propStat.location?.href) ? targetUrl : new Uri(propStat.location.href, UriKind.RelativeOrAbsolute);
            var propStatus = GetStatusCode(propStat.error, propStat.status, location, hrefs);

            if (propStatus == (int)WebDavStatusCode.NotFound)
            {
                return(new RemoteMissingTarget(collection, targetUrl, name, this));
            }

            var resourceType = propStat
                               .prop.Any
                               .SingleOrDefault(x => x.Name == Props.Live.ResourceTypeProperty.PropertyName);
            var collectionElement = resourceType?.Element(WebDavXml.Dav + "collection");

            if (collectionElement == null)
            {
                return(new RemoteDocumentTarget(collection, name, targetUrl, this));
            }

            return(new RemoteCollectionTarget(collection, name, collection.DestinationUrl.AppendDirectory(name), false, this));
        }