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 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 (!FilesSecurity.CanDownload(file)) { Error = FilesCommonResource.ErrorMassage_SecurityException; } 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, toFolder, _headers, MessageAction.FileMoved, file.Title, parentFolder.Title, toFolder.Title); if (file.RootFolderType == FolderType.TRASH && newFile.ThumbnailStatus == Thumbnail.NotRequired) { newFile.ThumbnailStatus = Thumbnail.Waiting; FileDao.SaveThumbnail(newFile, null); } if (newFile.ProviderEntry) { LinkDao.DeleteAllLink(file.ID); } 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; newFile.ThumbnailStatus = Thumbnail.Waiting; using (var stream = FileDao.GetFileStream(file)) { newFile.ContentLength = stream.CanSeek ? stream.Length : file.ContentLength; newFile = FileDao.SaveFile(newFile, stream); } if (file.ThumbnailStatus == Thumbnail.Created) { using (var thumbnail = FileDao.GetThumbnail(file)) { FileDao.SaveThumbnail(newFile, thumbnail); } newFile.ThumbnailStatus = Thumbnail.Created; } LinkDao.DeleteAllLink(newFile.ID); _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); LinkDao.DeleteAllLink(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 if (_resolveType == FileConflictResolveType.Skip) { //nothing } } } catch (Exception ex) { Error = ex.Message; Logger.Error(Error, ex); } } ProgressStep(fileId: FolderDao.CanCalculateSubitems(fileId) ? null : fileId); } }