private ItemNameValueCollection GetFilesInFolders(IEnumerable <object> folderIds, string path) { if (Canceled) { return(null); } var entriesPathId = new ItemNameValueCollection(); foreach (var folderId in folderIds) { var folder = FolderDao.GetFolder(folderId); if (folder == null || !FilesSecurity.CanRead(folder)) { continue; } var folderPath = path + folder.Title + "/"; var files = FolderDao.GetFiles(folder.ID, null, FilterType.None, Guid.Empty, string.Empty); files = FilesSecurity.FilterRead(files).ToList(); files.ForEach(file => entriesPathId.Add(ExecPathFromFile(file, folderPath))); FileMarker.RemoveMarkAsNew(folder); var nestedFolders = FolderDao.GetFolders(folder.ID); nestedFolders = FilesSecurity.FilterRead(nestedFolders).ToList(); if (files.Count == 0 && nestedFolders.Count == 0) { entriesPathId.Add(folderPath, String.Empty); } var filesInFolder = GetFilesInFolders(nestedFolders.ConvertAll(f => f.ID), folderPath); if (filesInFolder == null) { return(null); } entriesPathId.Add(filesInFolder); } return(entriesPathId); }
private NameValueCollection GetFilesInFolders(IList <object> folderIds, string path) { if (Canceled) { return(null); } var result = new NameValueCollection(); foreach (var folderId in folderIds) { var folder = FolderDao.GetFolder(folderId); if (folder == null || !FilesSecurity.CanRead(folder)) { continue; } var folderPath = path + folder.Title + "/"; var files = FilesSecurity.FilterRead(FolderDao.GetFiles(folder.ID, null, FilterType.None, Guid.Empty, string.Empty)).ToList(); files.ForEach(f => result.Add(folderPath + f.Title, f.ID.ToString())); TagDao.RemoveTags(files.Select(f => Tag.New(SecurityContext.CurrentAccount.ID, f)).ToArray()); var nestedFolders = FilesSecurity.FilterRead(FolderDao.GetFolders(folder.ID)).ToList(); if (files.Count == 0 && nestedFolders.Count == 0) { result.Add(folderPath, String.Empty); } var filesInFolder = GetFilesInFolders(nestedFolders.ConvertAll(f => f.ID), folderPath); if (filesInFolder == null) { return(null); } result.Add(filesInFolder); } return(result); }
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()) || _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) { _needToMarkAsNew.Add(conflictFolder); } } else { newFolder = FolderDao.CopyFolder(folder.ID, toFolderId); FilesMessageService.Send(folder, toFolder, httpRequestHeaders, MessageAction.FolderCopied, folder.Title, toFolder.Title); if (isToFolder) { _needToMarkAsNew.Add(newFolder); } if (ProcessedFolder(folderId)) { Status += string.Format("folder_{0}{1}", newFolder.ID, SplitCharacter); ResultedFolder(newFolder.ID); } } if (FolderDao.UseRecursiveOperation(folder.ID, toFolderId)) { MoveOrCopyFiles(FolderDao.GetFiles(folder.ID, false), newFolder, copy); 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); if (ProcessedFolder(folderId)) { Status += string.Format("folder_{0}{1}", newFolder.ID, SplitCharacter); ResultedFolder(newFolder.ID); } } } } else { if (conflictFolder != null) { object newFolderId; if (copy) { newFolder = FolderDao.CopyFolder(folder.ID, toFolderId); newFolderId = newFolder.ID; FilesMessageService.Send(folder, toFolder, httpRequestHeaders, MessageAction.FolderCopiedWithOverwriting, folder.Title, toFolder.Title); if (isToFolder) { _needToMarkAsNew.Add(newFolder); } } else { newFolderId = FolderDao.MoveFolder(folder.ID, toFolderId); FilesMessageService.Send(folder, toFolder, httpRequestHeaders, MessageAction.FolderMovedWithOverwriting, folder.Title, toFolder.Title); if (isToFolder) { _needToMarkAsNew.Add(FolderDao.GetFolder(newFolderId)); } } if (ProcessedFolder(folderId)) { Status += string.Format("folder_{0}{1}", newFolderId, SplitCharacter); ResultedFolder(newFolderId); } } } } else { if (FilesSecurity.CanDelete(folder)) { FileMarker.RemoveMarkAsNewForAll(folder); var newFolderId = FolderDao.MoveFolder(folder.ID, toFolderId); FilesMessageService.Send(folder, toFolder, httpRequestHeaders, MessageAction.FolderMoved, folder.Title, toFolder.Title); if (isToFolder) { _needToMarkAsNew.Add(FolderDao.GetFolder(newFolderId)); } if (ProcessedFolder(folderId)) { Status += string.Format("folder_{0}{1}", newFolderId, SplitCharacter); ResultedFolder(newFolderId); } } 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) { 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) { 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 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(FileTracker.IsEditing)) { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteEditingFolder; } else { FolderDao.MoveFolder(folder.ID, _trashId); FilesMessageService.Send(folder, httpRequestHeaders, MessageAction.FolderMovedToTrash, folder.Title); ProcessedFolder(folderId); ResultedFolder(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(); } }
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(); } }