private void MoveOrCopyFolders(ICollection folderIds, Folder toFolder, bool copy) { if (folderIds.Count == 0) { return; } var toFolderId = toFolder.ID; var isToFolder = Equals(toFolderId.ToString(), this.toFolderId); foreach (var folderId in folderIds) { CancellationToken.ThrowIfCancellationRequested(); var folder = FolderDao.GetFolder(folderId); if (folder == null) { Error = FilesCommonResource.ErrorMassage_FolderNotFound; } else if (!FilesSecurity.CanRead(folder)) { Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFolder; } else if (!Equals((folder.ParentFolderID ?? string.Empty).ToString(), toFolderId.ToString()) || resolveType == FileConflictResolveType.Duplicate) { try { //if destination folder contains folder with same name then merge folders var conflictFolder = FolderDao.GetFolder(folder.Title, toFolderId); if (copy || conflictFolder != null) { Folder newFolder; if (conflictFolder != null) { newFolder = conflictFolder; if (isToFolder) { needToMark.Add(conflictFolder); } } else { newFolder = FolderDao.CopyFolder(folder.ID, toFolderId); FilesMessageService.Send(folder, toFolder, headers, MessageAction.FolderCopied, folder.Title, toFolder.Title); if (isToFolder) { needToMark.Add(newFolder); } if (ProcessedFolder(folderId)) { Status += string.Format("folder_{0}{1}", newFolder.ID, SPLIT_CHAR); } } if (FolderDao.UseRecursiveOperation(folder.ID, toFolderId)) { MoveOrCopyFiles(FileDao.GetFiles(folder.ID), newFolder, copy); MoveOrCopyFolders(FolderDao.GetFolders(folder.ID).Select(f => f.ID).ToList(), newFolder, copy); if (!copy) { if (FolderDao.IsEmpty(folder.ID) && FilesSecurity.CanDelete(folder)) { FolderDao.DeleteFolder(folder.ID); if (ProcessedFolder(folderId)) { Status += string.Format("folder_{0}{1}", newFolder.ID, SPLIT_CHAR); } } } } else { if (conflictFolder != null) { object newFolderId; if (copy) { newFolder = FolderDao.CopyFolder(folder.ID, toFolderId); newFolderId = newFolder.ID; FilesMessageService.Send(folder, toFolder, headers, MessageAction.FolderCopiedWithOverwriting, folder.Title, toFolder.Title); if (isToFolder) { needToMark.Add(newFolder); } } else { newFolderId = FolderDao.MoveFolder(folder.ID, toFolderId); FilesMessageService.Send(folder, toFolder, headers, MessageAction.FolderMovedWithOverwriting, folder.Title, toFolder.Title); if (isToFolder) { needToMark.Add(FolderDao.GetFolder(newFolderId)); } } if (ProcessedFolder(folderId)) { Status += string.Format("folder_{0}{1}", newFolderId, SPLIT_CHAR); } } } } else { if (FilesSecurity.CanDelete(folder)) { FileMarker.RemoveMarkAsNewForAll(folder); var newFolderId = FolderDao.MoveFolder(folder.ID, toFolderId); FilesMessageService.Send(folder, toFolder, headers, MessageAction.FolderMoved, folder.Title, toFolder.Title); if (isToFolder) { needToMark.Add(FolderDao.GetFolder(newFolderId)); } if (ProcessedFolder(folderId)) { Status += string.Format("folder_{0}{1}", newFolderId, SPLIT_CHAR); } } else { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder; } } } catch (Exception ex) { Error = ex.Message; Logger.Error(Error, ex); } } ProgressStep(FolderDao.CanCalculateSubitems(folderId) ? null : folderId); } }
private void MoveOrCopyFolders(List <object> folderIds, object to, bool copy) { if (folderIds.Count == 0) { return; } foreach (var folderId in folderIds) { if (Canceled) { return; } var folder = FolderDao.GetFolder(folderId); if (folder == null) { Error = FilesCommonResource.ErrorMassage_FolderNotFound; } else if (!FilesSecurity.CanRead(folder)) { Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFolder; } else if (!Equals((folder.ParentFolderID ?? string.Empty).ToString(), to)) { //if destination folder contains folder with same name then merge folders var conflictFolder = FolderDao.GetFolder(folder.Title, to); if (copy || conflictFolder != null) { object newFolder; if (conflictFolder != null) { newFolder = conflictFolder.ID; } else { newFolder = FolderDao.CopyFolder(folder.ID, to); ProcessedFolder(folderId); } if (FolderDao.UseRecursiveOperation(folder, to)) { MoveOrCopyFiles(FolderDao.GetFiles(folder.ID, false), newFolder, copy, _resolveType); MoveOrCopyFolders(FolderDao.GetFolders(folder.ID).Select(f => f.ID).ToList(), newFolder, copy); if (!copy && conflictFolder != null) { if (FolderDao.GetItemsCount(folder.ID, true) == 0 && FilesSecurity.CanDelete(folder)) { FolderDao.DeleteFolder(folder.ID); ProcessedFolder(folderId); } } } else { if (conflictFolder != null) { if (copy) { FolderDao.CopyFolder(folder.ID, to); } else { FolderDao.MoveFolder(folder.ID, to); } ProcessedFolder(folderId); } } } else { if (FilesSecurity.CanDelete(folder)) { FolderDao.MoveFolder(folder.ID, to); ProcessedFolder(folderId); } else { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder; } } } ProgressStep(); } }
private void MoveOrCopyFolders(ICollection folderIds, Folder toFolder, bool copy) { if (folderIds.Count == 0) { return; } var toFolderId = toFolder.ID; var isToFolder = Equals(toFolderId.ToString(), _toFolderId); foreach (var folderId in folderIds) { if (Canceled) { return; } var folder = FolderDao.GetFolder(folderId); if (folder == null) { Error = FilesCommonResource.ErrorMassage_FolderNotFound; } else if (!FilesSecurity.CanRead(folder)) { Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFolder; } else if (!Equals((folder.ParentFolderID ?? string.Empty).ToString(), toFolderId.ToString())) { try { //if destination folder contains folder with same name then merge folders var conflictFolder = FolderDao.GetFolder(folder.Title, toFolderId); if (copy || conflictFolder != null) { Folder newFolder; if (conflictFolder != null) { newFolder = conflictFolder; if (isToFolder) { _needToMarkAsNew.Add(conflictFolder); } } else { newFolder = FolderDao.CopyFolder(folder.ID, toFolderId); if (isToFolder) { _needToMarkAsNew.Add(newFolder); } ProcessedFolder(folderId); } if (FolderDao.UseRecursiveOperation(folder.ID, toFolderId)) { MoveOrCopyFiles(FolderDao.GetFiles(folder.ID, false), newFolder, copy, _resolveType); MoveOrCopyFolders(FolderDao.GetFolders(folder.ID).Select(f => f.ID).ToList(), newFolder, copy); if (!copy) { if (FolderDao.GetItemsCount(folder.ID, true) == 0 && FilesSecurity.CanDelete(folder)) { FolderDao.DeleteFolder(folder.ID); ProcessedFolder(folderId); } } } else { if (conflictFolder != null) { if (copy) { newFolder = FolderDao.CopyFolder(folder.ID, toFolderId); if (isToFolder) { _needToMarkAsNew.Add(newFolder); } } else { FolderDao.MoveFolder(folder.ID, toFolderId); if (isToFolder) { _needToMarkAsNew.Add(FolderDao.GetFolder(folder.ID)); } } ProcessedFolder(folderId); } } } else { if (FilesSecurity.CanDelete(folder)) { FileMarker.RemoveMarkAsNewForAll(folder); FolderDao.MoveFolder(folder.ID, toFolderId); if (isToFolder) { _needToMarkAsNew.Add(FolderDao.GetFolder(folder.ID)); } ProcessedFolder(folderId); } else { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder; } } } catch (Exception ex) { Error = ex.Message; Logger.Error(Error, ex); } } ProgressStep(); } }
private void MoveOrCopyFolders(ICollection folderIds, Folder toFolder, bool copy) { if (folderIds.Count == 0) { return; } var toFolderId = toFolder.ID; var isToFolder = Equals(toFolderId.ToString(), _toFolderId); foreach (var folderId in folderIds) { CancellationToken.ThrowIfCancellationRequested(); var folder = FolderDao.GetFolder(folderId); if (folder == null) { Error = FilesCommonResource.ErrorMassage_FolderNotFound; } else if (!FilesSecurity.CanRead(folder)) { Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFolder; } else if (!FilesSecurity.CanDownload(folder)) { Error = FilesCommonResource.ErrorMassage_SecurityException; } else if (folder.RootFolderType == FolderType.Privacy && (copy || toFolder.RootFolderType != FolderType.Privacy)) { Error = FilesCommonResource.ErrorMassage_SecurityException_MoveFolder; } else if (!Equals((folder.ParentFolderID ?? string.Empty).ToString(), toFolderId.ToString()) || _resolveType == FileConflictResolveType.Duplicate) { try { //if destination folder contains folder with same name then merge folders var conflictFolder = folder.RootFolderType == FolderType.Privacy ? null : FolderDao.GetFolder(folder.Title, toFolderId); Folder newFolder; if (copy || conflictFolder != null) { if (conflictFolder != null) { newFolder = conflictFolder; if (isToFolder) { _needToMark.Add(conflictFolder); } } else { newFolder = FolderDao.CopyFolder(folder.ID, toFolderId, CancellationToken); FilesMessageService.Send(newFolder, toFolder, _headers, MessageAction.FolderCopied, newFolder.Title, toFolder.Title); if (isToFolder) { _needToMark.Add(newFolder); } if (ProcessedFolder(folderId)) { Status += string.Format("folder_{0}{1}", newFolder.ID, SPLIT_CHAR); } } if (toFolder.ProviderId == folder.ProviderId && // crossDao operation is always recursive FolderDao.UseRecursiveOperation(folder.ID, toFolderId)) { MoveOrCopyFiles(FileDao.GetFiles(folder.ID), newFolder, copy); MoveOrCopyFolders(FolderDao.GetFolders(folder.ID).Select(f => f.ID).ToList(), newFolder, copy); if (!copy) { if (!FilesSecurity.CanDelete(folder)) { Error = FilesCommonResource.ErrorMassage_SecurityException_MoveFolder; } else if (FolderDao.IsEmpty(folder.ID)) { FolderDao.DeleteFolder(folder.ID); if (ProcessedFolder(folderId)) { Status += string.Format("folder_{0}{1}", newFolder.ID, SPLIT_CHAR); } } } } else { if (conflictFolder != null) { string tmpError; object newFolderId; if (copy) { newFolder = FolderDao.CopyFolder(folder.ID, toFolderId, CancellationToken); newFolderId = newFolder.ID; FilesMessageService.Send(newFolder, toFolder, _headers, MessageAction.FolderCopiedWithOverwriting, newFolder.Title, toFolder.Title); if (isToFolder) { _needToMark.Add(newFolder); } if (ProcessedFolder(folderId)) { Status += string.Format("folder_{0}{1}", newFolderId, SPLIT_CHAR); } } else if (!FilesSecurity.CanDelete(folder)) { Error = FilesCommonResource.ErrorMassage_SecurityException_MoveFolder; } else if (WithError(FileDao.GetFiles(folder.ID, new OrderBy(SortedByType.AZ, true), FilterType.FilesOnly, false, Guid.Empty, string.Empty, false, true), out tmpError)) { Error = tmpError; } else { FileMarker.RemoveMarkAsNewForAll(folder); newFolderId = FolderDao.MoveFolder(folder.ID, toFolderId, CancellationToken); newFolder = FolderDao.GetFolder(newFolderId); FilesMessageService.Send(folder, toFolder, _headers, MessageAction.FolderMovedWithOverwriting, folder.Title, toFolder.Title); if (isToFolder) { _needToMark.Add(newFolder); } if (ProcessedFolder(folderId)) { Status += string.Format("folder_{0}{1}", newFolderId, SPLIT_CHAR); } } } } } else { string tmpError; if (!FilesSecurity.CanDelete(folder)) { Error = FilesCommonResource.ErrorMassage_SecurityException_MoveFolder; } else if (WithError(FileDao.GetFiles(folder.ID, new OrderBy(SortedByType.AZ, true), FilterType.FilesOnly, false, Guid.Empty, string.Empty, false, true), out tmpError)) { Error = tmpError; } else { FileMarker.RemoveMarkAsNewForAll(folder); var parentFolder = FolderDao.GetFolder(folder.RootFolderId); var newFolderId = FolderDao.MoveFolder(folder.ID, toFolderId, CancellationToken); newFolder = FolderDao.GetFolder(newFolderId); FilesMessageService.Send(folder, toFolder, _headers, MessageAction.FolderMovedFrom, folder.Title, parentFolder.Title, toFolder.Title); if (isToFolder) { _needToMark.Add(newFolder); } if (ProcessedFolder(folderId)) { Status += string.Format("folder_{0}{1}", newFolderId, SPLIT_CHAR); } } } } catch (Exception ex) { Error = ex.Message; Logger.Error(Error, ex); } } ProgressStep(FolderDao.CanCalculateSubitems(folderId) ? null : folderId); } }