private void DeleteFiles(List <object> fileIds) { if (fileIds.Count == 0) { return; } foreach (var fileId in fileIds) { if (Canceled) { return; } var file = FileDao.GetFile(fileId); if (file == null) { Error = FilesCommonResource.ErrorMassage_FileNotFound; } else if (!ignoreException && EntryManager.FileLockedForMe(file.ID)) { Error = FilesCommonResource.ErrorMassage_LockedFile; } else if (!ignoreException && FileTracker.IsEditing(file.ID)) { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteEditingFile; } else if (!ignoreException && !FilesSecurity.CanDelete(file)) { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile; } else { FileMarker.RemoveMarkAsNewForAll(file); if (FileDao.UseTrashForRemove(file)) { FileDao.MoveFile(file.ID, _trashId); FilesMessageService.Send(file, httpRequestHeaders, MessageAction.FileMovedToTrash, file.Title); ResultedFile(fileId); } else { try { FileDao.DeleteFile(file.ID); FileDao.DeleteFolder(file.ID); } catch (Exception ex) { Error = ex.Message; Logger.Error(Error, ex); } } ProcessedFile(fileId); } ProgressStep(); } }
private void DeleteFiles(List <object> fileIds) { if (fileIds.Count == 0) { return; } foreach (var fileId in fileIds) { if (Canceled) { return; } var file = FileDao.GetFile(fileId); if (file == null) { Error = FilesCommonResource.ErrorMassage_FileNotFound; } else if (!ignoreException && (file.FileStatus & FileStatus.IsEditing) == FileStatus.IsEditing) { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteEditingFile; } else if (!ignoreException && !FilesSecurity.CanDelete(file)) { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile; } else { FileMarker.RemoveMarkAsNewForAll(file); if (FileDao.UseTrashForRemove(file)) { FileDao.MoveFile(file.ID, _trashId); } else { try { FileDao.DeleteFile(file.ID); FileDao.DeleteFolder(file.ID); } catch (Exception ex) { Error = ex.Message; Logger.Error(Error, ex); } } ProcessedFile(fileId); } ProgressStep(); } }
private void DeleteFiles(IEnumerable <object> fileIds) { foreach (var fileId in fileIds) { CancellationToken.ThrowIfCancellationRequested(); var file = FileDao.GetFile(fileId); string tmpError; if (file == null) { Error = FilesCommonResource.ErrorMassage_FileNotFound; } else if (!_ignoreException && WithError(new[] { file }, false, out tmpError)) { Error = tmpError; } else { FileMarker.RemoveMarkAsNewForAll(file); if (!_immediately && FileDao.UseTrashForRemove(file)) { FileDao.MoveFile(file.ID, _trashId); FilesMessageService.Send(file, _headers, MessageAction.FileMovedToTrash, file.Title); if (file.ThumbnailStatus == Thumbnail.Waiting) { file.ThumbnailStatus = Thumbnail.NotRequired; FileDao.SaveThumbnail(file, null); } } else { try { FileDao.DeleteFile(file.ID); FilesMessageService.Send(file, _headers, MessageAction.FileDeleted, file.Title); } catch (Exception ex) { Error = ex.Message; Logger.Error(Error, ex); } LinkDao.DeleteAllLink(file.ID); } ProcessedFile(fileId); } ProgressStep(fileId: FolderDao.CanCalculateSubitems(fileId) ? null : fileId); } }
private void DeleteFiles(List <object> fileIds) { foreach (var fileId in fileIds) { CancellationToken.ThrowIfCancellationRequested(); var file = FileDao.GetFile(fileId); if (file == null) { Error = FilesCommonResource.ErrorMassage_FileNotFound; } else if (!ignoreException && EntryManager.FileLockedForMe(file.ID)) { Error = FilesCommonResource.ErrorMassage_LockedFile; } else if (!ignoreException && FileTracker.IsEditing(file.ID)) { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteEditingFile; } else if (!ignoreException && !FilesSecurity.CanDelete(file)) { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile; } else { FileMarker.RemoveMarkAsNewForAll(file); if (FileDao.UseTrashForRemove(file)) { FileDao.MoveFile(file.ID, trashId); FilesMessageService.Send(file, headers, MessageAction.FileMovedToTrash, file.Title); } else { try { FileDao.DeleteFile(file.ID); FileDao.DeleteFolder(file.ID); } catch (Exception ex) { Error = ex.Message; Logger.Error(Error, ex); } } ProcessedFile(fileId); } ProgressStep(fileId: FolderDao.CanCalculateSubitems(fileId) ? null : fileId); } }
private void MoveOrCopyFiles(ICollection fileIds, Folder toFolder, bool copy) { if (fileIds.Count == 0) { return; } var toFolderId = toFolder.ID; foreach (var fileId in fileIds) { CancellationToken.ThrowIfCancellationRequested(); var file = FileDao.GetFile(fileId); if (file == null) { Error = FilesCommonResource.ErrorMassage_FileNotFound; } else if (!FilesSecurity.CanRead(file)) { Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFile; } else if (Global.EnableUploadFilter && !FileUtility.ExtsUploadable.Contains(FileUtility.GetFileExtension(file.Title))) { Error = FilesCommonResource.ErrorMassage_NotSupportedFormat; } else if (file.ContentLength > SetupInfo.AvailableFileSize && file.ProviderId != toFolder.ProviderId) { Error = string.Format(copy ? FilesCommonResource.ErrorMassage_FileSizeCopy : FilesCommonResource.ErrorMassage_FileSizeMove, FileSizeComment.FilesSizeToString(SetupInfo.AvailableFileSize)); } else { var parentFolder = FolderDao.GetFolder(file.FolderID); try { var conflict = resolveType == FileConflictResolveType.Duplicate ? null : FileDao.GetFile(toFolderId, file.Title); if (conflict != null && !FilesSecurity.CanEdit(conflict)) { Error = FilesCommonResource.ErrorMassage_SecurityException; } else if (conflict != null && EntryManager.FileLockedForMe(conflict.ID)) { Error = FilesCommonResource.ErrorMassage_LockedFile; } else if (conflict == null) { if (copy) { File newFile = null; try { newFile = FileDao.CopyFile(file.ID, toFolderId); //Stream copy will occur inside dao FilesMessageService.Send(file, toFolder, headers, MessageAction.FileCopied, file.Title, parentFolder.Title, toFolder.Title); if (Equals(newFile.FolderID.ToString(), this.toFolderId)) { needToMark.Add(newFile); } if (ProcessedFile(fileId)) { Status += string.Format("file_{0}{1}", newFile.ID, SPLIT_CHAR); } } catch { if (newFile != null) { FileDao.DeleteFile(newFile.ID); } throw; } } else { if (EntryManager.FileLockedForMe(file.ID)) { Error = FilesCommonResource.ErrorMassage_LockedFile; } else if (FileTracker.IsEditing(file.ID)) { Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile; } else if (FilesSecurity.CanDelete(file)) { FileMarker.RemoveMarkAsNewForAll(file); var newFileId = FileDao.MoveFile(file.ID, toFolderId); FilesMessageService.Send(file, toFolder, headers, MessageAction.FileMoved, file.Title, parentFolder.Title, toFolder.Title); if (Equals(toFolderId.ToString(), this.toFolderId)) { needToMark.Add(FileDao.GetFile(newFileId)); } if (ProcessedFile(fileId)) { Status += string.Format("file_{0}{1}", newFileId, SPLIT_CHAR); } } else { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile; } } } else { if (resolveType == FileConflictResolveType.Overwrite) { if (EntryManager.FileLockedForMe(conflict.ID)) { Error = FilesCommonResource.ErrorMassage_LockedFile; } else if (FileTracker.IsEditing(conflict.ID)) { Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile; } else { var newFile = conflict; newFile.Version++; newFile.ContentLength = conflict.ContentLength; using (var stream = FileDao.GetFileStream(file)) { newFile = FileDao.SaveFile(newFile, stream); } needToMark.Add(newFile); if (copy) { FilesMessageService.Send(file, toFolder, headers, MessageAction.FileCopiedWithOverwriting, file.Title, parentFolder.Title, toFolder.Title); if (ProcessedFile(fileId)) { Status += string.Format("file_{0}{1}", newFile.ID, SPLIT_CHAR); } } else { if (Equals(file.FolderID.ToString(), toFolderId.ToString())) { if (ProcessedFile(fileId)) { Status += string.Format("file_{0}{1}", newFile.ID, SPLIT_CHAR); } } else { if (EntryManager.FileLockedForMe(file.ID)) { Error = FilesCommonResource.ErrorMassage_LockedFile; } else if (FileTracker.IsEditing(file.ID)) { Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile; } else if (FilesSecurity.CanDelete(file)) { FileDao.DeleteFile(file.ID); FileDao.DeleteFolder(file.ID); FilesMessageService.Send(file, toFolder, headers, MessageAction.FileMovedWithOverwriting, file.Title, parentFolder.Title, toFolder.Title); if (ProcessedFile(fileId)) { Status += string.Format("file_{0}{1}", newFile.ID, SPLIT_CHAR); } } else { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile; } } } } } else if (resolveType == FileConflictResolveType.Skip) { //nothing } } } catch (Exception ex) { Error = ex.Message; Logger.Error(Error, ex); } } ProgressStep(fileId: FolderDao.CanCalculateSubitems(fileId) ? null : fileId); } }
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 MoveOrCopyFiles(ICollection fileIds, Folder toFolder, bool copy) { if (fileIds.Count == 0) { return; } var toFolderId = toFolder.ID; foreach (var fileId in fileIds) { if (Canceled) { return; } var file = FileDao.GetFile(fileId); if (file == null) { Error = FilesCommonResource.ErrorMassage_FileNotFound; } else if (!FilesSecurity.CanRead(file)) { Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFile; } else if (Global.EnableUploadFilter && !FileUtility.ExtsUploadable.Contains(FileUtility.GetFileExtension(file.Title))) { Error = FilesCommonResource.ErrorMassage_NotSupportedFormat; } else // if (!Equals(file.FolderID.ToString(), toFolderId.ToString()) || _resolveType == FileConflictResolveType.Duplicate) { var parentFolder = FolderDao.GetFolder(file.FolderID); try { var conflict = _resolveType == FileConflictResolveType.Duplicate ? null : FileDao.GetFile(toFolderId, file.Title); if (conflict != null && !FilesSecurity.CanEdit(conflict)) { Error = FilesCommonResource.ErrorMassage_SecurityException; } else if (conflict != null && EntryManager.FileLockedForMe(conflict.ID)) { Error = FilesCommonResource.ErrorMassage_LockedFile; } else if (conflict == null) { if (copy) { File newFile = null; try { newFile = FileDao.CopyFile(file.ID, toFolderId); //Stream copy will occur inside dao FilesMessageService.Send(file, toFolder, httpRequestHeaders, MessageAction.FileCopied, file.Title, parentFolder.Title, toFolder.Title); if (Equals(newFile.FolderID.ToString(), _toFolderId)) { _needToMarkAsNew.Add(newFile); } if (ProcessedFile(fileId)) { Status += string.Format("file_{0}{1}", newFile.ID, SplitCharacter); ResultedFile(newFile.ID); } } catch { if (newFile != null) { FileDao.DeleteFile(newFile.ID); } throw; } } else { if (EntryManager.FileLockedForMe(file.ID)) { Error = FilesCommonResource.ErrorMassage_LockedFile; } else if (FileTracker.IsEditing(file.ID)) { Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile; } else if (FilesSecurity.CanDelete(file)) { FileMarker.RemoveMarkAsNewForAll(file); var newFileId = FileDao.MoveFile(file.ID, toFolderId); FilesMessageService.Send(file, toFolder, httpRequestHeaders, MessageAction.FileMoved, file.Title, parentFolder.Title, toFolder.Title); if (Equals(toFolderId.ToString(), _toFolderId)) { _needToMarkAsNew.Add(FileDao.GetFile(newFileId)); } if (ProcessedFile(fileId)) { Status += string.Format("file_{0}{1}", newFileId, SplitCharacter); ResultedFile(newFileId); } } else { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile; } } } else { if (_resolveType == FileConflictResolveType.Overwrite) { if (EntryManager.FileLockedForMe(conflict.ID)) { Error = FilesCommonResource.ErrorMassage_LockedFile; } else if (FileTracker.IsEditing(conflict.ID)) { Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile; } else { conflict.Version++; using (var stream = FileDao.GetFileStream(file)) { conflict.ContentLength = stream.Length; conflict.Comment = string.Empty; conflict = FileDao.SaveFile(conflict, stream); _needToMarkAsNew.Add(conflict); } if (copy) { FilesMessageService.Send(file, toFolder, httpRequestHeaders, MessageAction.FileCopiedWithOverwriting, file.Title, parentFolder.Title, toFolder.Title); if (ProcessedFile(fileId)) { Status += string.Format("file_{0}{1}", conflict.ID, SplitCharacter); ResultedFile(conflict.ID); } } else { if (Equals(file.FolderID.ToString(), toFolderId.ToString())) { if (ProcessedFile(fileId)) { Status += string.Format("file_{0}{1}", conflict.ID, SplitCharacter); ResultedFile(conflict.ID); } } else { if (EntryManager.FileLockedForMe(file.ID)) { Error = FilesCommonResource.ErrorMassage_LockedFile; } else if (FileTracker.IsEditing(file.ID)) { Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile; } else if (FilesSecurity.CanDelete(file)) { FileDao.DeleteFile(file.ID); FileDao.DeleteFolder(file.ID); FilesMessageService.Send(file, toFolder, httpRequestHeaders, MessageAction.FileMovedWithOverwriting, file.Title, parentFolder.Title, toFolder.Title); if (ProcessedFile(fileId)) { Status += string.Format("file_{0}{1}", conflict.ID, SplitCharacter); ResultedFile(conflict.ID); } } else { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile; } } } } } else if (_resolveType == FileConflictResolveType.Skip) { //nothing } } } catch (Exception ex) { Error = ex.Message; Logger.Error(Error, ex); } } ProgressStep(); } }
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 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 MoveOrCopyFiles(ICollection fileIds, Folder toFolder, bool copy, FileConflictResolveType resolveType) { if (fileIds.Count == 0) { return; } var toFolderId = toFolder.ID; foreach (var fileId in fileIds) { if (Canceled) { return; } var file = FileDao.GetFile(fileId); if (file == null) { Error = FilesCommonResource.ErrorMassage_FileNotFound; } else if (!FilesSecurity.CanRead(file)) { Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFile; } else if (Global.EnableUploadFilter && !Studio.Utility.FileUtility.ExtsUploadable.Contains(Studio.Utility.FileUtility.GetFileExtension(file.Title))) { Error = FilesCommonResource.ErrorMassage_NotSupportedFormat; } else if (!Equals(file.FolderID.ToString(), toFolderId)) { try { var conflict = FileDao.GetFile(toFolderId, file.Title); if (conflict != null && !FilesSecurity.CanEdit(conflict)) { Error = FilesCommonResource.ErrorMassage_SecurityException; } else if (conflict == null) { if (copy) { File newFile = null; try { newFile = FileDao.CopyFile(file.ID, toFolderId); //Stream copy will occur inside dao if (Equals(newFile.FolderID.ToString(), _toFolderId)) { _needToMarkAsNew.Add(newFile); } ProcessedFile(fileId); } catch { if (newFile != null) { FileDao.DeleteFile(newFile.ID); } throw; } } else { if ((file.FileStatus & FileStatus.IsEditing) == FileStatus.IsEditing) { Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile; } else if (FilesSecurity.CanDelete(file)) { FileMarker.RemoveMarkAsNewForAll(file); var newFileId = FileDao.MoveFile(file.ID, toFolderId); if (Equals(toFolderId.ToString(), _toFolderId)) { _needToMarkAsNew.Add(FileDao.GetFile(newFileId)); } ProcessedFile(fileId); } else { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile; } } } else { if (resolveType == FileConflictResolveType.Overwrite) { conflict.Version++; using (var stream = FileDao.GetFileStream(file)) { conflict.ContentLength = stream.Length; conflict = FileDao.SaveFile(conflict, stream); _needToMarkAsNew.Add(conflict); } if (copy) { ProcessedFile(fileId); } else { if ((file.FileStatus & FileStatus.IsEditing) == FileStatus.IsEditing) { Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile; } else if (FilesSecurity.CanDelete(file)) { FileDao.DeleteFile(file.ID); FileDao.DeleteFolder(file.ID); ProcessedFile(fileId); } else { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile; } } } else if (resolveType == FileConflictResolveType.Skip) { //nothing } } } 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 MoveOrCopyFiles(ICollection fileIds, Folder toFolder, bool copy) { if (fileIds.Count == 0) { return; } var toFolderId = toFolder.ID; foreach (var fileId in fileIds) { CancellationToken.ThrowIfCancellationRequested(); var file = FileDao.GetFile(fileId); if (file == null) { Error = FilesCommonResource.ErrorMassage_FileNotFound; } else if (!FilesSecurity.CanRead(file)) { Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFile; } else if (file.RootFolderType == FolderType.Privacy && (copy || toFolder.RootFolderType != FolderType.Privacy)) { Error = FilesCommonResource.ErrorMassage_SecurityException_MoveFile; } else if (Global.EnableUploadFilter && !FileUtility.ExtsUploadable.Contains(FileUtility.GetFileExtension(file.Title))) { Error = FilesCommonResource.ErrorMassage_NotSupportedFormat; } else { var parentFolder = FolderDao.GetFolder(file.FolderID); try { var conflict = _resolveType == FileConflictResolveType.Duplicate || file.RootFolderType == FolderType.Privacy ? null : FileDao.GetFile(toFolderId, file.Title); if (conflict == null) { File newFile = null; if (copy) { try { newFile = FileDao.CopyFile(file.ID, toFolderId); //Stream copy will occur inside dao FilesMessageService.Send(newFile, toFolder, _headers, MessageAction.FileCopied, newFile.Title, parentFolder.Title, toFolder.Title); if (Equals(newFile.FolderID.ToString(), _toFolderId)) { _needToMark.Add(newFile); } if (ProcessedFile(fileId)) { Status += string.Format("file_{0}{1}", newFile.ID, SPLIT_CHAR); } } catch { if (newFile != null) { FileDao.DeleteFile(newFile.ID); } throw; } } else { string tmpError; if (WithError(new[] { file }, out tmpError)) { Error = tmpError; } else { FileMarker.RemoveMarkAsNewForAll(file); var newFileId = FileDao.MoveFile(file.ID, toFolderId); newFile = FileDao.GetFile(newFileId); FilesMessageService.Send(file.RootFolderType != FolderType.USER ? file : newFile, toFolder, _headers, MessageAction.FileMoved, file.Title, parentFolder.Title, toFolder.Title); if (Equals(toFolderId.ToString(), _toFolderId)) { _needToMark.Add(newFile); } if (ProcessedFile(fileId)) { Status += string.Format("file_{0}{1}", newFileId, SPLIT_CHAR); } } } } else { if (_resolveType == FileConflictResolveType.Overwrite) { if (!FilesSecurity.CanEdit(conflict)) { Error = FilesCommonResource.ErrorMassage_SecurityException; } else if (EntryManager.FileLockedForMe(conflict.ID)) { Error = FilesCommonResource.ErrorMassage_LockedFile; } else if (FileTracker.IsEditing(conflict.ID)) { Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile; } else { var newFile = conflict; newFile.Version++; newFile.VersionGroup++; newFile.PureTitle = file.PureTitle; newFile.ConvertedType = file.ConvertedType; newFile.Comment = FilesCommonResource.CommentOverwrite; newFile.Encrypted = file.Encrypted; using (var stream = FileDao.GetFileStream(file)) { newFile.ContentLength = stream.CanSeek ? stream.Length : file.ContentLength; newFile = FileDao.SaveFile(newFile, stream); } _needToMark.Add(newFile); if (copy) { FilesMessageService.Send(newFile, toFolder, _headers, MessageAction.FileCopiedWithOverwriting, newFile.Title, parentFolder.Title, toFolder.Title); if (ProcessedFile(fileId)) { Status += string.Format("file_{0}{1}", newFile.ID, SPLIT_CHAR); } } else { if (Equals(file.FolderID.ToString(), toFolderId.ToString())) { if (ProcessedFile(fileId)) { Status += string.Format("file_{0}{1}", newFile.ID, SPLIT_CHAR); } } else { string tmpError; if (WithError(new[] { file }, out tmpError)) { Error = tmpError; } else { FileDao.DeleteFile(file.ID); FilesMessageService.Send(file.RootFolderType != FolderType.USER ? file : newFile, toFolder, _headers, MessageAction.FileMovedWithOverwriting, file.Title, parentFolder.Title, toFolder.Title); if (ProcessedFile(fileId)) { Status += string.Format("file_{0}{1}", newFile.ID, SPLIT_CHAR); } } } } } } else if (_resolveType == FileConflictResolveType.Skip) { //nothing } } } catch (Exception ex) { Error = ex.Message; Logger.Error(Error, ex); } } ProgressStep(fileId: FolderDao.CanCalculateSubitems(fileId) ? null : fileId); } }
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(); } }