/// <summary> /// Update dead properties. /// Currently on description is supported. /// </summary> /// <param name="setProps">Dead properties to be set.</param> /// <param name="delProps">Dead properties to be deleted.</param> /// <param name="multistatus">Multistatus with details for every failed property.</param> public override async Task UpdatePropertiesAsync(IList <PropertyValue> setProps, IList <PropertyName> delProps, MultistatusException multistatus) { foreach (PropertyValue prop in setProps) { if (prop.QualifiedName == PrincipalProperties.Description) { groupPrincipal.Description = prop.Value; } else { //Property is not supported. Tell client about this. multistatus.AddInnerException( Path, prop.QualifiedName, new DavException("Property was not found.", DavStatus.NOT_FOUND)); } } //We cannot delete any properties from group, because it is windows object. foreach (PropertyName propertyName in delProps) { multistatus.AddInnerException( Path, propertyName, new DavException( "It is not allowed to remove properties on principal objects.", DavStatus.FORBIDDEN)); } Context.PrincipalOperation(groupPrincipal.Save); }
/// <summary> /// Updates dead properties. /// </summary> /// <param name="setProps">Properties to set.</param> /// <param name="delProps">Properties to delete.</param> /// <param name="multistatus">Here we report problems with properties.</param> public override async Task UpdatePropertiesAsync(IList <PropertyValue> setProps, IList <PropertyName> delProps, MultistatusException multistatus) { foreach (PropertyValue prop in setProps) { if (prop.QualifiedName == PrincipalProperties.FullName) { userPrincipal.DisplayName = prop.Value; } else if (prop.QualifiedName == PrincipalProperties.Description) { userPrincipal.Description = prop.Value; } else { multistatus.AddInnerException( Path, prop.QualifiedName, new DavException("The property was not found", DavStatus.NOT_FOUND)); } } foreach (PropertyName p in delProps) { multistatus.AddInnerException( Path, p, new DavException("Principal properties can not be deleted.", DavStatus.FORBIDDEN)); } Context.PrincipalOperation(userPrincipal.Save); }
/// <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); } }
/// <summary> /// Copies this folder to another folder with option to rename it. /// </summary> /// <param name="destFolder">Folder to copy this folder to.</param> /// <param name="destName">New name of this folder.</param> /// <param name="deep">Whether children shall be copied.</param> /// <param name="multistatus">Container for errors. We put here errors which occur with /// individual items being copied.</param> public override async Task CopyToAsync( IItemCollectionAsync destFolder, string destName, bool deep, MultistatusException multistatus) { DavFolder destDavFolder = destFolder as DavFolder; if (destFolder == null) { throw new DavException("Destination folder doesn't exist", DavStatus.CONFLICT); } if (!await destDavFolder.ClientHasTokenAsync()) { throw new LockedException("Doesn't have token for destination folder."); } if (isRecursive(destDavFolder)) { throw new DavException("Cannot copy folder to its subtree", DavStatus.FORBIDDEN); } IHierarchyItemAsync destItem = await destDavFolder.FindChildAsync(destName); if (destItem != null) { try { await destItem.DeleteAsync(multistatus); } catch (DavException ex) { multistatus.AddInnerException(destItem.Path, ex); return; } } DavFolder newDestFolder = await CopyThisItemAsync(destDavFolder, null, destName); // copy children if (deep) { foreach (IHierarchyItemAsync child in (await GetChildrenAsync(new PropertyName[0], null, null, null)).Page) { var dbchild = child as DavHierarchyItem; try { await dbchild.CopyToAsync(newDestFolder, child.Name, deep, multistatus); } catch (DavException ex) { multistatus.AddInnerException(dbchild.Path, ex); } } } await Context.socketService.NotifyRefreshAsync(newDestFolder.Path); }
/// <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); }
/// <summary> /// Copies this folder to another folder with option to rename it. /// </summary> /// <param name="destFolder">Folder to copy this folder to.</param> /// <param name="destName">New name of this folder.</param> /// <param name="deep">Whether children shall be copied.</param> /// <param name="multistatus">Container for errors. We put here errors which occur with /// individual items being copied.</param> public override void CopyTo(IItemCollection destFolder, string destName, bool deep, MultistatusException multistatus) { DavFolder destDavFolder = destFolder as DavFolder; if (destFolder == null) { throw new DavException("Destination folder doesn't exist", DavStatus.CONFLICT); } if (!destDavFolder.ClientHasToken()) { throw new LockedException("Doesn't have token for destination folder."); } if (isRecursive(destDavFolder)) { throw new DavException("Cannot copy folder to its subtree", DavStatus.FORBIDDEN); } IHierarchyItem destItem = destDavFolder.FindChild(destName); if (destItem != null) { try { destItem.Delete(multistatus); } catch (DavException ex) { multistatus.AddInnerException(destItem.Path, ex); return; } } DavFolder newDestFolder = CopyThisItem(destDavFolder, null, destName); // copy children if (deep) { foreach (IHierarchyItem child in GetChildren(new PropertyName[0])) { var dbchild = child as DavHierarchyItem; try { dbchild.CopyTo(newDestFolder, child.Name, deep, multistatus); } catch (DavException ex) { multistatus.AddInnerException(dbchild.Path, ex); } } } }
/// <summary> /// Copies this file to another folder. /// </summary> /// <param name="destFolder">Destination folder.</param> /// <param name="destName">New file name in destination folder.</param> /// <param name="deep">Is not used.</param> /// <param name="multistatus">Container for errors with items other than this file.</param> public override void CopyTo( IItemCollection destFolder, string destName, bool deep, MultistatusException multistatus) { DavFolder destDavFolder = destFolder as DavFolder; if (destFolder == null) { throw new DavException("Destination folder doesn't exist.", DavStatus.CONFLICT); } if (!destDavFolder.ClientHasToken()) { throw new LockedException("Doesn't have token for destination folder."); } DavHierarchyItem destItem = destDavFolder.FindChild(destName); if (destItem != null) { try { destItem.Delete(multistatus); } catch (DavException ex) { multistatus.AddInnerException(destItem.Path, ex); return; } } CopyThisItem(destDavFolder, null, destName); }
/// <summary> /// Called whan this folder is being deleted. /// </summary> /// <param name="multistatus">Information about items that failed to delete.</param> public override async Task DeleteAsync(MultistatusException multistatus) { /* * if (await GetParentAsync() == null) * { * throw new DavException("Cannot delete root.", DavStatus.NOT_ALLOWED); * } */ bool allChildrenDeleted = true; foreach (IHierarchyItemAsync child in (await GetChildrenAsync(new PropertyName[0], null, null, null)).Page) { try { await child.DeleteAsync(multistatus); } catch (DavException ex) { //continue the operation if a child failed to delete. Tell client about it by adding to multistatus. multistatus.AddInnerException(child.Path, ex); allChildrenDeleted = false; } } if (allChildrenDeleted) { dirInfo.Delete(); } }
/// <summary> /// Called when this file is being copied. /// </summary> /// <param name="destFolder">Destination folder.</param> /// <param name="destName">New file name.</param> /// <param name="deep">Whether children items shall be copied. Ignored for files.</param> /// <param name="multistatus">Information about items that failed to copy.</param> public override async Task CopyToAsync(IItemCollectionAsync destFolder, string destName, bool deep, MultistatusException multistatus) { DavFolder targetFolder = (DavFolder)destFolder; if (!await context.DataLakeStoreService.ExistsAsync(targetFolder.Path)) { throw new DavException("Target directory doesn't exist", DavStatus.CONFLICT); } string targetPath = targetFolder.Path + EncodeUtil.EncodeUrlPart(destName); // If an item with the same name exists - remove it. try { if (await context.GetHierarchyItemAsync(targetPath) is { } item) { await item.DeleteAsync(multistatus); } } catch (DavException ex) { // Report exception to client and continue with other items by returning from recursion. multistatus.AddInnerException(targetPath, ex); return; } await context.DataLakeStoreService.CopyItemAsync(Path, targetFolder.Path, destName, ContentLength, dataCloudItem.Properties); await context.socketService.NotifyRefreshAsync(targetFolder.Path); }
/// <summary> /// Copies this file to another folder. /// </summary> /// <param name="destFolder">Destination folder.</param> /// <param name="destName">New file name in destination folder.</param> /// <param name="deep">Is not used.</param> /// <param name="multistatus">Container for errors with items other than this file.</param> public override async Task CopyToAsync( IItemCollectionAsync destFolder, string destName, bool deep, MultistatusException multistatus) { DavFolder destDavFolder = destFolder as DavFolder; if (destFolder == null) { throw new DavException("Destination folder doesn't exist.", DavStatus.CONFLICT); } if (!await destDavFolder.ClientHasTokenAsync()) { throw new LockedException("Doesn't have token for destination folder."); } DavHierarchyItem destItem = await destDavFolder.FindChildAsync(destName); if (destItem != null) { try { await destItem.DeleteAsync(multistatus); } catch (DavException ex) { multistatus.AddInnerException(destItem.Path, ex); return; } } await CopyThisItemAsync(destDavFolder, null, destName); await Context.socketService.NotifyRefreshAsync(destDavFolder.Path); }
/// <summary> /// Called when this file is being moved or renamed. /// </summary> /// <param name="destFolder">Destination folder.</param> /// <param name="destName">New name of this file.</param> /// <param name="multistatus">Information about items that failed to move.</param> public override async Task MoveToAsync(IItemCollectionAsync destFolder, string destName, MultistatusException multistatus) { DavFolder targetFolder = (DavFolder)destFolder; if (targetFolder == null || !Directory.Exists(targetFolder.FullPath)) { throw new DavException("Target directory doesn't exist", DavStatus.CONFLICT); } string newDirPath = System.IO.Path.Combine(targetFolder.FullPath, destName); string targetPath = targetFolder.Path + EncodeUtil.EncodeUrlPart(destName); // If an item with the same name exists in target directory - remove it. try { IHierarchyItemAsync item = await context.GetHierarchyItemAsync(targetPath); if (item != null) { await item.DeleteAsync(multistatus); } } catch (DavException ex) { // Report exception to client and continue with other items by returning from recursion. multistatus.AddInnerException(targetPath, ex); return; } // Move the file. try { File.Move(fileSystemInfo.FullName, newDirPath); var newFileInfo = new FileInfo(newDirPath); if (FileSystemInfoExtension.IsUsingFileSystemAttribute) { await fileSystemInfo.MoveExtendedAttributes(newFileInfo); } // Locks should not be copied, delete them. if (await newFileInfo.HasExtendedAttributeAsync("Locks")) { await newFileInfo.DeleteExtendedAttributeAsync("Locks"); } } catch (UnauthorizedAccessException) { // Exception occurred with the item for which MoveTo was called - fail the operation. NeedPrivilegesException ex = new NeedPrivilegesException("Not enough privileges"); ex.AddRequiredPrivilege(targetPath, Privilege.Bind); string parentPath = System.IO.Path.GetDirectoryName(Path); ex.AddRequiredPrivilege(parentPath, Privilege.Unbind); throw ex; } }
/// <summary> /// Called when this file is being copied. /// </summary> /// <param name="destFolder">Destination folder.</param> /// <param name="destName">New file name.</param> /// <param name="deep">Whether children items shall be copied. Ignored for files.</param> /// <param name="multistatus">Information about items that failed to copy.</param> public override async Task CopyToAsync(IItemCollectionAsync destFolder, string destName, bool deep, MultistatusException multistatus) { DavFolder targetFolder = (DavFolder)destFolder; if (targetFolder == null || !Directory.Exists(targetFolder.FullPath)) { throw new DavException("Target directory doesn't exist", DavStatus.CONFLICT); } string newFilePath = System.IO.Path.Combine(targetFolder.FullPath, destName); string targetPath = targetFolder.Path + EncodeUtil.EncodeUrlPart(destName); // If an item with the same name exists - remove it. try { IHierarchyItemAsync item = await context.GetHierarchyItemAsync(targetPath); if (item != null) { await item.DeleteAsync(multistatus); } } catch (DavException ex) { // Report error with other item to client. multistatus.AddInnerException(targetPath, ex); return; } // Copy the file togather with all extended attributes (custom props and locks). try { File.Copy(fileSystemInfo.FullName, newFilePath); var newFileSystemInfo = new FileInfo(newFilePath); if (FileSystemInfoExtension.IsUsingFileSystemAttribute) { await fileSystemInfo.CopyExtendedAttributes(newFileSystemInfo); } // Locks should not be copied, delete them. if (await fileSystemInfo.HasExtendedAttributeAsync("Locks")) { await newFileSystemInfo.DeleteExtendedAttributeAsync("Locks"); } } catch (UnauthorizedAccessException) { // Fail NeedPrivilegesException ex = new NeedPrivilegesException("Not enough privileges"); string parentPath = System.IO.Path.GetDirectoryName(Path); ex.AddRequiredPrivilege(parentPath, Privilege.Bind); throw ex; } await context.socketService.NotifyRefreshAsync(targetFolder.Path); }
/// <summary> /// Moves this file to different folder and renames it. /// </summary> /// <param name="destFolder">Destination folder.</param> /// <param name="destName">New file name.</param> /// <param name="multistatus">Container for errors with items other than this file.</param> public override async Task MoveToAsync(IItemCollectionAsync destFolder, string destName, MultistatusException multistatus) { DavFolder destDavFolder = destFolder as DavFolder; if (destFolder == null) { throw new DavException("Destination folder doesn't exist.", DavStatus.CONFLICT); } DavFolder parent = await GetParentAsync(); if (parent == null) { throw new DavException("Cannot move root.", DavStatus.CONFLICT); } if (!await ClientHasTokenAsync() || !await destDavFolder.ClientHasTokenAsync() || !await parent.ClientHasTokenAsync()) { throw new LockedException(); } DavHierarchyItem destItem = await destDavFolder.FindChildAsync(destName); if (destItem != null) { try { await destItem.DeleteAsync(multistatus); } catch (DavException ex) { multistatus.AddInnerException(destItem.Path, ex); return; } } await MoveThisItemAsync(destDavFolder, destName, parent); // Refresh client UI. await Context.socketService.NotifyRefreshAsync(parent.Path); await Context.socketService.NotifyRefreshAsync(destDavFolder.Path); }
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); } } }
protected static void FindLocksDown(IHierarchyItem root, bool skipShared) { IFolder folder = root as IFolder; if (folder != null) { foreach (IHierarchyItem child in folder.GetChildren(new PropertyName[0])) { DavHierarchyItem dbchild = child as DavHierarchyItem; if (dbchild.ItemHasLock(skipShared)) { MultistatusException mex = new MultistatusException(); mex.AddInnerException(dbchild.Path, new LockedException()); throw mex; } FindLocksDown(child, skipShared); } } }
/// <summary> /// Deletes this folder. /// </summary> /// <param name="multistatus">Container for errors. /// If some child file/folder fails to remove we report error in this container.</param> public override async Task DeleteAsync(MultistatusException multistatus) { DavFolder parent = await GetParentAsync(); if (parent == null) { throw new DavException("Cannot delete root.", DavStatus.CONFLICT); } if (!await parent.ClientHasTokenAsync()) { throw new LockedException(); } if (!await ClientHasTokenAsync()) { throw new LockedException(); } bool deletedAllChildren = true; foreach (IHierarchyItemAsync child in (await GetChildrenAsync(new PropertyName[0], null, null, null)).Page) { DavHierarchyItem dbchild = child as DavHierarchyItem; try { await dbchild.DeleteAsync(multistatus); } catch (DavException ex) { multistatus.AddInnerException(dbchild.Path, ex); deletedAllChildren = false; } } if (deletedAllChildren) { await DeleteThisItemAsync(parent); await Context.socketService.NotifyDeleteAsync(Path); } }
/// <summary> /// Deletes this folder. /// </summary> /// <param name="multistatus">Container for errors. /// If some child file/folder fails to remove we report error in this container.</param> public override void Delete(MultistatusException multistatus) { DavFolder parent = GetParent(); if (parent == null) { throw new DavException("Cannot delete root.", DavStatus.CONFLICT); } if (!parent.ClientHasToken()) { throw new LockedException(); } if (!ClientHasToken()) { throw new LockedException(); } bool deletedAllChildren = true; foreach (IHierarchyItem child in GetChildren(new PropertyName[0])) { DavHierarchyItem dbchild = child as DavHierarchyItem; try { dbchild.Delete(multistatus); } catch (DavException ex) { multistatus.AddInnerException(dbchild.Path, ex); deletedAllChildren = false; } } if (deletedAllChildren) { DeleteThisItem(parent); } }
/// <summary> /// Moves this file to different folder and renames it. /// </summary> /// <param name="destFolder">Destination folder.</param> /// <param name="destName">New file name.</param> /// <param name="multistatus">Container for errors with items other than this file.</param> public override void MoveTo(IItemCollection destFolder, string destName, MultistatusException multistatus) { DavFolder destDavFolder = destFolder as DavFolder; if (destFolder == null) { throw new DavException("Destination folder doesn't exist.", DavStatus.CONFLICT); } DavFolder parent = GetParent(); if (parent == null) { throw new DavException("Cannot move root.", DavStatus.CONFLICT); } if (!ClientHasToken() || !destDavFolder.ClientHasToken() || !parent.ClientHasToken()) { throw new LockedException(); } DavHierarchyItem destItem = destDavFolder.FindChild(destName); if (destItem != null) { try { destItem.Delete(multistatus); } catch (DavException ex) { multistatus.AddInnerException(destItem.Path, ex); return; } } MoveThisItem(destDavFolder, destName, parent); }
/// <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)); }
/// <summary> /// Moves this folder to destination folder with option to rename. /// </summary> /// <param name="destFolder">Folder to copy this folder to.</param> /// <param name="destName">New name of this folder.</param> /// <param name="multistatus">Container for errors. We put here errors occurring while moving /// individual files/folders.</param> public override async Task MoveToAsync(IItemCollectionAsync destFolder, string destName, MultistatusException multistatus) { DavFolder destDavFolder = destFolder as DavFolder; if (destFolder == null) { throw new DavException("Destination folder doesn't exist", DavStatus.CONFLICT); } if (isRecursive(destDavFolder)) { throw new DavException("Cannot move folder to its subtree", DavStatus.FORBIDDEN); } DavFolder parent = await GetParentAsync(); if (parent == null) { throw new DavException("Cannot move root", DavStatus.CONFLICT); } if (!await ClientHasTokenAsync() || !await destDavFolder.ClientHasTokenAsync() || !await parent.ClientHasTokenAsync()) { throw new LockedException(); } DavHierarchyItem destItem = await destDavFolder.FindChildAsync(destName); DavFolder newDestFolder; // copy this folder if (destItem != null) { if (destItem is IFileAsync) { try { await destItem.DeleteAsync(multistatus); } catch (DavException ex) { multistatus.AddInnerException(destItem.Path, ex); return; } newDestFolder = await CopyThisItemAsync(destDavFolder, null, destName); } else { newDestFolder = destItem as DavFolder; if (newDestFolder == null) { multistatus.AddInnerException( destItem.Path, new DavException("Destionation item is not folder", DavStatus.CONFLICT)); } } } else { newDestFolder = await CopyThisItemAsync(destDavFolder, null, destName); } // move children bool movedAllChildren = true; foreach (IHierarchyItemAsync child in (await GetChildrenAsync(new PropertyName[0], null, null, null)).Page) { DavHierarchyItem dbchild = child as DavHierarchyItem; try { await dbchild.MoveToAsync(newDestFolder, child.Name, multistatus); } catch (DavException ex) { multistatus.AddInnerException(dbchild.Path, ex); movedAllChildren = false; } } if (movedAllChildren) { await DeleteThisItemAsync(parent); } // Refresh client UI. await Context.socketService.NotifyDeleteAsync(Path); await Context.socketService.NotifyRefreshAsync(GetParentPath(newDestFolder.Path)); }
/// <summary> /// Moves this folder to destination folder with option to rename. /// </summary> /// <param name="destFolder">Folder to copy this folder to.</param> /// <param name="destName">New name of this folder.</param> /// <param name="multistatus">Container for errors. We put here errors occurring while moving /// individual files/folders.</param> public override void MoveTo(IItemCollection destFolder, string destName, MultistatusException multistatus) { DavFolder destDavFolder = destFolder as DavFolder; if (destFolder == null) { throw new DavException("Destination folder doesn't exist", DavStatus.CONFLICT); } if (isRecursive(destDavFolder)) { throw new DavException("Cannot move folder to its subtree", DavStatus.FORBIDDEN); } DavFolder parent = GetParent(); if (parent == null) { throw new DavException("Cannot move root", DavStatus.CONFLICT); } if (!ClientHasToken() || !destDavFolder.ClientHasToken() || !parent.ClientHasToken()) { throw new LockedException(); } DavHierarchyItem destItem = destDavFolder.FindChild(destName); DavFolder newDestFolder; // copy this folder if (destItem != null) { if (destItem is IFile) { try { destItem.Delete(multistatus); } catch (DavException ex) { multistatus.AddInnerException(destItem.Path, ex); return; } newDestFolder = CopyThisItem(destDavFolder, null, destName); } else { newDestFolder = destItem as DavFolder; if (newDestFolder == null) { multistatus.AddInnerException( destItem.Path, new DavException("Destionation item is not folder", DavStatus.CONFLICT)); } } } else { newDestFolder = CopyThisItem(destDavFolder, null, destName); } // move children bool movedAllChildren = true; foreach (IHierarchyItem child in GetChildren(new PropertyName[0])) { DavHierarchyItem dbchild = child as DavHierarchyItem; try { dbchild.MoveTo(newDestFolder, child.Name, multistatus); } catch (DavException ex) { multistatus.AddInnerException(dbchild.Path, ex); movedAllChildren = false; } } if (movedAllChildren) { DeleteThisItem(parent); } }