private void DeleteFolders(IEnumerable <object> folderIds) { foreach (var folderId in folderIds) { CancellationToken.ThrowIfCancellationRequested(); var folder = FolderDao.GetFolder(folderId); object canCalculate = null; if (folder == null) { Error = FilesCommonResource.ErrorMassage_FolderNotFound; } else if (folder.FolderType != FolderType.DEFAULT && folder.FolderType != FolderType.BUNCH) { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder; } else if (!_ignoreException && !FilesSecurity.CanDelete(folder)) { canCalculate = FolderDao.CanCalculateSubitems(folderId) ? null : folderId; Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder; } else { canCalculate = FolderDao.CanCalculateSubitems(folderId) ? null : folderId; FileMarker.RemoveMarkAsNewForAll(folder); if (folder.ProviderEntry && folder.ID.Equals(folder.RootFolderId)) { if (ProviderDao != null) { ProviderDao.RemoveProviderInfo(folder.ProviderId); FilesMessageService.Send(folder, _headers, MessageAction.ThirdPartyDeleted, folder.ID.ToString(), folder.ProviderKey); } ProcessedFolder(folderId); } else { var immediately = _immediately || !FolderDao.UseTrashForRemove(folder); if (immediately && FolderDao.UseRecursiveOperation(folder.ID, null)) { DeleteFiles(FileDao.GetFiles(folder.ID)); DeleteFolders(FolderDao.GetFolders(folder.ID).Select(f => f.ID).ToList()); if (FolderDao.IsEmpty(folder.ID)) { FolderDao.DeleteFolder(folder.ID); FilesMessageService.Send(folder, _headers, MessageAction.FolderDeleted, folder.Title); ProcessedFolder(folderId); } } else { var files = FileDao.GetFiles(folder.ID, new OrderBy(SortedByType.AZ, true), FilterType.FilesOnly, false, Guid.Empty, string.Empty, false, true); string tmpError; if (!_ignoreException && WithError(files, true, out tmpError)) { Error = tmpError; } else { if (immediately) { FolderDao.DeleteFolder(folder.ID); FilesMessageService.Send(folder, _headers, MessageAction.FolderDeleted, folder.Title); } else { FolderDao.MoveFolder(folder.ID, _trashId, CancellationToken); FilesMessageService.Send(folder, _headers, MessageAction.FolderMovedToTrash, folder.Title); } ProcessedFolder(folderId); } } } } ProgressStep(canCalculate); } }
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(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 DeleteFolders(List <object> folderIds) { foreach (var folderId in folderIds) { CancellationToken.ThrowIfCancellationRequested(); var folder = FolderDao.GetFolder(folderId); if (folder == null) { Error = FilesCommonResource.ErrorMassage_FolderNotFound; } else if (!ignoreException && !FilesSecurity.CanDelete(folder)) { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder; } else { FileMarker.RemoveMarkAsNewForAll(folder); if (FolderDao.UseTrashForRemove(folder)) { var files = FileDao.GetFiles(folder.ID, true); if (!ignoreException && files.Exists(FileTracker.IsEditing)) { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteEditingFolder; } else { FolderDao.MoveFolder(folder.ID, trashId); FilesMessageService.Send(folder, headers, MessageAction.FolderMovedToTrash, folder.Title); ProcessedFolder(folderId); } } else { if (FolderDao.UseRecursiveOperation(folder.ID, null)) { DeleteFiles(FileDao.GetFiles(folder.ID, false)); DeleteFolders(FolderDao.GetFolders(folder.ID).Select(f => f.ID).ToList()); if (FolderDao.GetItemsCount(folder.ID, true) == 0) { FolderDao.DeleteFolder(folder.ID); ProcessedFolder(folderId); } } else { if (folder.ProviderEntry && folder.ID.Equals(folder.RootFolderId)) { ProviderDao.RemoveProviderInfo(folder.ProviderId); } else { FolderDao.DeleteFolder(folder.ID); } ProcessedFolder(folderId); } } } ProgressStep(); } }
private void DeleteFolders(List <object> folderIds) { 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.CanDelete(folder)) { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder; } else { if (FolderDao.UseTrashForRemove(folder)) { var files = FolderDao.GetFiles(folder.ID, true); if (files.Exists(fid => (File.GetFileStatus(fid, FileStatus.None) & FileStatus.IsEditing) == FileStatus.IsEditing)) { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteEditingFolder; } else { FolderDao.MoveFolder(folder.ID, _trashId); files.ForEach(fid => NoticeDelete(FileDao.GetFile(fid))); ProcessedFolder(folderId); TagDao.RemoveTags(TagDao.GetTags(folder.ID, FileEntryType.Folder, TagType.New).ToArray()); } } else { if (FolderDao.UseRecursiveOperation(folder.ID, null)) { DeleteFiles(FolderDao.GetFiles(folder.ID, false)); DeleteFolders(FolderDao.GetFolders(folder.ID).Select(f => f.ID).ToList()); if (FolderDao.GetItemsCount(folder.ID, true) == 0) { FolderDao.DeleteFolder(folder.ID); ProcessedFolder(folderId); } else { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteEditingFolder; } } else { FolderDao.DeleteFolder(folder.ID); ProcessedFolder(folderId); } } } ProgressStep(); } }
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) { 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); } }
private void DeleteFolders(List <object> folderIds) { foreach (var folderId in folderIds) { CancellationToken.ThrowIfCancellationRequested(); var folder = FolderDao.GetFolder(folderId); object canCalculate = null; if (folder == null) { Error = FilesCommonResource.ErrorMassage_FolderNotFound; } else if (folder.FolderType != FolderType.DEFAULT && folder.FolderType != FolderType.BUNCH) { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder; } else if (!ignoreException && !FilesSecurity.CanDelete(folder)) { canCalculate = FolderDao.CanCalculateSubitems(folderId) ? null : folderId; Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder; } else { canCalculate = FolderDao.CanCalculateSubitems(folderId) ? null : folderId; FileMarker.RemoveMarkAsNewForAll(folder); if (folder.ProviderEntry && folder.ID.Equals(folder.RootFolderId)) { if (ProviderDao != null) { ProviderDao.RemoveProviderInfo(folder.ProviderId); FilesMessageService.Send(folder, headers, MessageAction.ThirdPartyDeleted, folder.ID.ToString(), folder.ProviderKey); } ProcessedFolder(folderId); } else { if (FolderDao.UseTrashForRemove(folder)) { var files = FileDao.GetFiles(folder.ID); if (!ignoreException && files.Exists(FileTracker.IsEditing)) { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteEditingFolder; } else { FolderDao.MoveFolder(folder.ID, trashId); FilesMessageService.Send(folder, headers, MessageAction.FolderMovedToTrash, folder.Title); ProcessedFolder(folderId); } } else { if (FolderDao.UseRecursiveOperation(folder.ID, null)) { DeleteFiles(FileDao.GetFiles(folder.ID)); DeleteFolders(FolderDao.GetFolders(folder.ID).Select(f => f.ID).ToList()); if (FolderDao.IsEmpty(folder.ID)) { FolderDao.DeleteFolder(folder.ID); ProcessedFolder(folderId); } } else { FolderDao.DeleteFolder(folder.ID); ProcessedFolder(folderId); } } } } ProgressStep(canCalculate); } }
private void DeleteFolders(List <object> folderIds) { 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 (!ignoreException && !FilesSecurity.CanDelete(folder)) { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder; } else { FileMarker.RemoveMarkAsNewForAll(folder); if (FolderDao.UseTrashForRemove(folder)) { var files = FolderDao.GetFiles(folder.ID, true); if (!ignoreException && files.Exists(fid => ((new File { ID = fid, FileStatus = FileStatus.None }).FileStatus & FileStatus.IsEditing) == FileStatus.IsEditing)) { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteEditingFolder; } else { FolderDao.MoveFolder(folder.ID, _trashId); ProcessedFolder(folderId); } } else { if (FolderDao.UseRecursiveOperation(folder.ID, null)) { DeleteFiles(FolderDao.GetFiles(folder.ID, false)); DeleteFolders(FolderDao.GetFolders(folder.ID).Select(f => f.ID).ToList()); if (FolderDao.GetItemsCount(folder.ID, true) == 0) { FolderDao.DeleteFolder(folder.ID); ProcessedFolder(folderId); } } else { if (folder.ProviderEntry && folder.ID.Equals(folder.RootFolderId)) { ProviderDao.RemoveProviderInfo(folder.ProviderId); } else { FolderDao.DeleteFolder(folder.ID); } ProcessedFolder(folderId); } } } ProgressStep(); } }