示例#1
0
        /// <summary>
        /// Move file in another space on the server.
        /// </summary>
        /// <param name="file">File info to move.</param>
        /// <param name="destinationPath">Destination path on the server.</param>
        /// <returns>True or false operation result.</returns>
        public async Task <bool> MoveAsync(File file, string destinationPath)
        {
            var link = await _linkManager.GetItemLink(file.FullPath, false);

            if (link != null)
            {
                var remapped = await _linkManager.RemapLink(link, destinationPath);

                if (remapped)
                {
                    _itemCache.Invalidate(file.Path, destinationPath);
                }
                return(remapped);
            }

            var qry = file.Files
                      .AsParallel()
                      .WithDegreeOfParallelism(Math.Min(MaxInnerParallelRequests, file.Files.Count))
                      .Select(async pfile =>
            {
                var moveres = await Account.RequestRepo.Move(pfile.FullPath, destinationPath);
                _itemCache.Forget(file.Path, pfile.FullPath);
                return(moveres);
            });

            _itemCache.Forget(file.Path, file.FullPath);
            _itemCache.Invalidate(destinationPath);

            bool res = (await Task.WhenAll(qry))
                       .All(r => r.IsSuccess);

            return(res);
        }
示例#2
0
        /// <summary>
        /// Remove file or folder.
        /// </summary>
        /// <param name="fullPath">Full file or folder name.</param>
        /// <returns>True or false result operation.</returns>
        private async Task <bool> Remove(string fullPath)
        {
            //TODO: refact
            var link = await _linkManager.GetItemLink(fullPath, false);

            if (link != null)
            {
                //if folder is linked - do not delete inner files/folders if client deleting recursively
                //just try to unlink folder
                _linkManager.RemoveLink(fullPath);

                _itemCache.Invalidate(WebDavPath.Parent(fullPath));
                return(true);
            }

            var res = await Account.RequestRepo.Remove(fullPath);

            if (res.IsSuccess)
            {
                //remove inner links
                var innerLinks = _linkManager.GetChilds(fullPath);
                _linkManager.RemoveLinks(innerLinks);

                _itemCache.Invalidate(fullPath);
                _itemCache.Forget(WebDavPath.Parent(fullPath), fullPath); //_itemCache.Invalidate(WebDavPath.Parent(fullPath));
            }
            return(res.IsSuccess);
        }