private WebDavResourceNode SortResourceTree(WebDavResourceNode root)
        {
            var children = new List <WebDavResourceNode>();

            foreach (var child in root.Children)
            {
                children.Add(SortResourceTree(child));
            }
            var sortedChildren = children.OrderByDescending(c => c.LastModifiedDate).ToList();
            var newNode        = new WebDavResourceNode(root.Uri, root.RelUri, root.ETag, root.LastModifiedDate, root.ContentLength, root.IsCollection, sortedChildren);

            return(newNode);
        }
        private static WebDavResourceNode BuildResourcesTree(Dictionary <string, WebDavResourceNode> folderMap, IReadOnlyCollection <WebDavResource> resources)
        {
            WebDavResourceNode root = null;

            foreach (var resource in resources)
            {
                var(parentUri, relUri) = SplitUri(resource.Uri);
                var parentEntry = GetParentEntry(folderMap, parentUri);

                if (parentEntry == null)
                {
                    root = folderMap[resource.Uri];
                    continue;
                }

                var entry = resource.IsCollection ? folderMap[resource.Uri] : new WebDavResourceNode(resource);
                entry.RelUri = relUri;
                var parentFolder = folderMap[parentUri];
                parentFolder.Children.Add(entry);
            }
            return(root);
        }