コード例 #1
0
        /// <summary>
        /// Called when this folder is being moved or renamed.
        /// </summary>
        /// <param name="destFolder">Destination folder.</param>
        /// <param name="destName">New name of this folder.</param>
        /// <param name="multistatus">Information about child items that failed to move.</param>
        public override async Task MoveToAsync(IItemCollectionAsync destFolder, string destName, MultistatusException multistatus)
        {
            // in this function we move item by item, because we want to check if each item is not locked.
            if (!(destFolder is DavFolder))
            {
                throw new DavException("Target folder doesn't exist", DavStatus.CONFLICT);
            }

            DavFolder targetFolder = (DavFolder)destFolder;

            if (IsRecursive(targetFolder))
            {
                throw new DavException("Cannot move folder to its subtree.", DavStatus.FORBIDDEN);
            }

            string newDirPath = System.IO.Path.Combine(targetFolder.FullPath, destName);
            string targetPath = targetFolder.Path + EncodeUtil.EncodeUrlPart(destName);

            try
            {
                // Remove item with the same name at destination if it exists.
                IHierarchyItemAsync item = await context.GetHierarchyItemAsync(targetPath);

                if (item != null)
                {
                    await item.DeleteAsync(multistatus);
                }

                await targetFolder.CreateFolderAsync(destName);
            }
            catch (DavException ex)
            {
                // Continue the operation but report error with destination path to client.
                multistatus.AddInnerException(targetPath, ex);
                return;
            }

            // Move child items.
            bool         movedSuccessfully = true;
            IFolderAsync createdFolder     = (IFolderAsync)await context.GetHierarchyItemAsync(targetPath);

            foreach (DavHierarchyItem item in (await GetChildrenAsync(new PropertyName[0], null, null, new List <OrderProperty>())).Page)
            {
                try
                {
                    await item.MoveToAsync(createdFolder, item.Name, multistatus);
                }
                catch (DavException ex)
                {
                    // Continue the operation but report error with child item to client.
                    multistatus.AddInnerException(item.Path, ex);
                    movedSuccessfully = false;
                }
            }

            if (movedSuccessfully)
            {
                await DeleteAsync(multistatus);
            }
        }
コード例 #2
0
        /// <summary>Creates folder on server only.</summary>
        /// <param name="folderMetadata">The folder metadata.</param>
        /// <param name="folderName">The directory name.</param>
        /// <returns>The <see cref="FolderMetadata"/>.</returns>
        public FolderMetadata CreateFolderOnServer(FolderMetadata folderMetadata, string folderName)
        {
            IFolderAsync newFolder = folderMetadata.ServerFolder.CreateFolderAsync(folderName).GetAwaiter().GetResult();

            string      id        = this.LocationMapper.GetIdentifierFromServerUri(newFolder.Href);
            string      localPath = this.LocationMapper.GetLocalUrlFromIdentifier(id);
            LocalFolder localItem = this.LocalStorage.GetFolder(localPath);

            return(this.CreateFolderMetadata(id, localItem, newFolder));
        }
コード例 #3
0
        /// <summary>Creates folder metadata.</summary>
        /// <param name="itemIdentifier">The item identifier.</param>
        /// <param name="localItem">The local item.</param>
        /// <param name="serverItem">The server item.</param>
        /// <returns>The <see cref="FolderMetadata"/>.</returns>
        private FolderMetadata CreateFolderMetadata(
            string itemIdentifier,
            LocalFolder localItem,
            IFolderAsync serverItem = null)
        {
            string parentIdentifier = this.LocationMapper.GetParentIdentifier(itemIdentifier);
            string name             = this.GetItemDisplayName(itemIdentifier, serverItem);

            return(new FolderMetadata(itemIdentifier, parentIdentifier, name, localItem, serverItem));
        }
コード例 #4
0
 /// <summary>Initializes a new instance of the <see cref="FolderMetadata"/> class.</summary>
 /// <param name="identifier">The identifier.</param>
 /// <param name="parentIdentifier">The parent identifier.</param>
 /// <param name="name">The name.</param>
 /// <param name="localItem">The local item.</param>
 /// <param name="serverItem">The server item.</param>
 public FolderMetadata(
     string identifier,
     string parentIdentifier,
     string name,
     LocalFolder localItem,
     IFolderAsync serverItem = null)
     : base(identifier, parentIdentifier, name, localItem, serverItem)
 {
     this.LocalFolder  = localItem;
     this.ServerFolder = serverItem;
 }
コード例 #5
0
ファイル: DavFolder.cs プロジェクト: islamailani/Aventis
        /// <summary>
        /// Called when this folder is being copied.
        /// </summary>
        /// <param name="destFolder">Destination parent folder.</param>
        /// <param name="destName">New folder name.</param>
        /// <param name="deep">Whether children items shall be copied.</param>
        /// <param name="multistatus">Information about child items that failed to copy.</param>
        public override async Task CopyToAsync(IItemCollectionAsync destFolder, string destName, bool deep, MultistatusException multistatus)
        {
            DavFolder targetFolder = destFolder as DavFolder;

            if (targetFolder == null)
            {
                throw new DavException("Target folder doesn't exist", DavStatus.CONFLICT);
            }

            if (IsRecursive(targetFolder))
            {
                throw new DavException("Cannot copy to subfolder", DavStatus.FORBIDDEN);
            }

            string newDirLocalPath = System.IO.Path.Combine(targetFolder.FullPath, destName);
            string targetPath      = targetFolder.Path + EncodeUtil.EncodeUrlPart(destName);

            // Create folder at the destination.
            try
            {
                if (!Directory.Exists(newDirLocalPath))
                {
                    await targetFolder.CreateFolderAsync(destName);
                }
            }
            catch (DavException ex)
            {
                // Continue, but report error to client for the target item.
                multistatus.AddInnerException(targetPath, ex);
            }

            // Copy children.
            IFolderAsync createdFolder = (IFolderAsync)await context.GetHierarchyItemAsync(targetPath);

            foreach (DavHierarchyItem item in await GetChildrenAsync(new PropertyName[0]))
            {
                if (!deep && item is DavFolder)
                {
                    continue;
                }

                try
                {
                    await item.CopyToAsync(createdFolder, item.Name, deep, multistatus);
                }
                catch (DavException ex)
                {
                    // If a child item failed to copy we continue but report error to client.
                    multistatus.AddInnerException(item.Path, ex);
                }
            }
            await context.socketService.NotifyRefreshAsync(targetFolder.Path);
        }
コード例 #6
0
        /// <summary>Gets folder's local and remote state. </summary>
        /// <param name="itemIdentifier">The item identifier.</param>
        /// <returns>The <see cref="FolderMetadata"/>.</returns>
        public FolderMetadata GetFolderMetadata(string itemIdentifier)
        {
            try
            {
                Uri          serverUri  = this.LocationMapper.GetServerUriFromIdentifier(itemIdentifier);
                IFolderAsync serverItem = this.session.OpenFolderAsync(serverUri).GetAwaiter().GetResult();

                string      localPath = this.LocationMapper.GetLocalUrlFromIdentifier(itemIdentifier);
                LocalFolder localItem = this.LocalStorage.GetFolder(localPath);
                return(this.CreateFolderMetadata(itemIdentifier, localItem, serverItem));
            }
            catch (NotFoundException)
            {
                string      localPath = this.LocationMapper.GetLocalUrlFromIdentifier(itemIdentifier);
                LocalFolder localItem = this.LocalStorage.GetFolder(localPath);
                return(this.CreateFolderMetadata(itemIdentifier, localItem));
            }
        }
コード例 #7
0
        protected static async Task FindLocksDownAsync(IHierarchyItemAsync root, bool skipShared)
        {
            IFolderAsync folder = root as IFolderAsync;

            if (folder != null)
            {
                foreach (IHierarchyItemAsync child in (await folder.GetChildrenAsync(new PropertyName[0], null, null, null)).Page)
                {
                    DavHierarchyItem dbchild = child as DavHierarchyItem;
                    if (await dbchild.ItemHasLockAsync(skipShared))
                    {
                        MultistatusException mex = new MultistatusException();
                        mex.AddInnerException(dbchild.Path, new LockedException());
                        throw mex;
                    }

                    await FindLocksDownAsync(child, skipShared);
                }
            }
        }
コード例 #8
0
ファイル: DavFolder.cs プロジェクト: islamailani/Aventis
        /// <summary>
        /// Called when this folder is being moved or renamed.
        /// </summary>
        /// <param name="destFolder">Destination folder.</param>
        /// <param name="destName">New name of this folder.</param>
        /// <param name="multistatus">Information about child items that failed to move.</param>
        public override async Task MoveToAsync(IItemCollectionAsync destFolder, string destName, MultistatusException multistatus)
        {
            await RequireHasTokenAsync();

            DavFolder targetFolder = destFolder as DavFolder;

            if (targetFolder == null)
            {
                throw new DavException("Target folder doesn't exist", DavStatus.CONFLICT);
            }

            if (IsRecursive(targetFolder))
            {
                throw new DavException("Cannot move folder to its subtree.", DavStatus.FORBIDDEN);
            }

            string newDirPath = System.IO.Path.Combine(targetFolder.FullPath, destName);
            string targetPath = targetFolder.Path + EncodeUtil.EncodeUrlPart(destName);

            try
            {
                // Remove item with the same name at destination if it exists.
                IHierarchyItemAsync item = await context.GetHierarchyItemAsync(targetPath);

                if (item != null)
                {
                    await item.DeleteAsync(multistatus);
                }

                await targetFolder.CreateFolderAsync(destName);
            }
            catch (DavException ex)
            {
                // Continue the operation but report error with destination path to client.
                multistatus.AddInnerException(targetPath, ex);
                return;
            }

            // Move child items.
            bool         movedSuccessfully = true;
            IFolderAsync createdFolder     = (IFolderAsync)await context.GetHierarchyItemAsync(targetPath);

            foreach (DavHierarchyItem item in await GetChildrenAsync(new PropertyName[0]))
            {
                try
                {
                    await item.MoveToAsync(createdFolder, item.Name, multistatus);
                }
                catch (DavException ex)
                {
                    // Continue the operation but report error with child item to client.
                    multistatus.AddInnerException(item.Path, ex);
                    movedSuccessfully = false;
                }
            }

            if (movedSuccessfully)
            {
                await DeleteAsync(multistatus);
            }
            // Refresh client UI.
            await context.socketService.NotifyDeleteAsync(Path);

            await context.socketService.NotifyRefreshAsync(GetParentPath(targetPath));
        }