protected override void Do(IServiceScope scope) { var fileMarker = scope.ServiceProvider.GetService <FileMarker>(); Status += string.Format("folder_{0}{1}", _toFolderId, FileOperation.SPLIT_CHAR); //TODO: check on each iteration? var toFolder = FolderDao.GetFolder(_toFolderId); if (toFolder == null) { return; } if (!FilesSecurity.CanCreate(toFolder)) { throw new System.Security.SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create); } if (FolderDao.GetParentFolders(toFolder.ID).Any(parent => Folders.Contains(parent.ID.ToString()))) { Error = FilesCommonResource.ErrorMassage_FolderCopyError; return; } if (_copy) { Folder rootFrom = null; if (0 < Folders.Count) { rootFrom = FolderDao.GetRootFolder(Folders[0]); } if (0 < Files.Count) { rootFrom = FolderDao.GetRootFolderByFile(Files[0]); } if (rootFrom != null && rootFrom.FolderType == FolderType.TRASH) { throw new InvalidOperationException("Can not copy from Trash."); } if (toFolder.RootFolderType == FolderType.TRASH) { throw new InvalidOperationException("Can not copy to Trash."); } } MoveOrCopyFolders(scope, Folders, toFolder, _copy); MoveOrCopyFiles(scope, Files, toFolder, _copy); _needToMark.Distinct().ToList().ForEach(x => fileMarker.MarkAsNew(x)); }
protected override void Do() { Status += string.Format("folder_{0}{1}", _toFolderId, SplitCharacter); //TODO: check on each iteration? var toFolder = FolderDao.GetFolder(_toFolderId); if (toFolder == null) { return; } if (!FilesSecurity.CanCreate(toFolder)) { throw new System.Security.SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create); } if (_copy) { Folder rootFrom = null; if (0 < Folders.Count) { rootFrom = FolderDao.GetRootFolder(Folders[0]); } if (0 < Files.Count) { rootFrom = FolderDao.GetRootFolderByFile(Files[0]); } if (rootFrom != null && rootFrom.FolderType == FolderType.TRASH) { throw new InvalidOperationException("Can not copy from Trash."); } if (toFolder.RootFolderType == FolderType.TRASH) { throw new InvalidOperationException("Can not copy to Trash."); } } MoveOrCopyFolders(Folders, toFolder, _copy); MoveOrCopyFiles(Files, toFolder, _copy, _resolveType); _needToMarkAsNew.Distinct().ToList().ForEach(x => FileMarker.MarkAsNew(x, _markAsNewRecipientIDs)); }
protected override void Do() { Status += string.Format("folder_{0}{1}", _toFolder, splitCharacter); //TODO: check on each iteration? var to = FolderDao.GetFolder(_toFolder); if (to == null) { return; } if (!FilesSecurity.CanCreate(to)) { throw new System.Security.SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create); } if (_copy) { Folder rootFrom = null; if (0 < Folders.Count) { rootFrom = FolderDao.GetRootFolder(Folders[0]); } if (0 < Files.Count) { rootFrom = FolderDao.GetRootFolderByFile(Files[0]); } if (rootFrom != null && rootFrom.FolderType == FolderType.TRASH) { throw new InvalidOperationException("Can not copy from Trash."); } if (to.RootFolderType == FolderType.TRASH) { throw new InvalidOperationException("Can not copy to Trash."); } } MoveOrCopyFolders(Folders, _toFolder, _copy); MoveOrCopyFiles(Files, _toFolder, _copy, _resolveType); }
protected override void Do() { if (_files.Count == 0) { return; } var parent = FolderDao.GetFolder(_parentId); if (parent == null) { throw new Exception(FilesCommonResource.ErrorMassage_FolderNotFound); } if (!FilesSecurity.CanCreate(parent)) { throw new System.Security.SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create); } if (parent.RootFolderType == FolderType.TRASH) { throw new Exception(FilesCommonResource.ErrorMassage_ImportToTrash); } if (!string.IsNullOrEmpty(parent.ProviderName)) { throw new System.Security.SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create); } var to = FolderDao.GetFolder(_folderName, _parentId); if (to == null) { to = new Folder { FolderType = FolderType.DEFAULT, ParentFolderID = _parentId, Title = _folderName }; to.ID = FolderDao.SaveFolder(to); } foreach (var f in _files) { if (Canceled) { return; } try { long size; using (var stream = _docProvider.GetDocumentStream(f.ContentLink, out size)) { if (stream == null) { throw new Exception("Can not import document " + f.ContentLink + ". Empty stream."); } if (SetupInfo.MaxUploadSize < size) { throw FileSizeComment.FileSizeException; } var folderId = to.ID; var pos = f.Title.LastIndexOf('/'); if (0 < pos) { folderId = GetOrCreateHierarchy(f.Title.Substring(0, pos), to); f.Title = f.Title.Substring(pos + 1); } f.Title = Global.ReplaceInvalidCharsAndTruncate(f.Title); var file = new File { Title = f.Title, FolderID = folderId, ContentLength = size, ContentType = "application/octet-stream", }; var conflict = FileDao.GetFile(file.FolderID, file.Title); if (conflict != null) { if (_overwrite) { file.ID = conflict.ID; file.Version = conflict.Version + 1; } else { continue; } } if (size <= 0L) { using (var buffered = stream.GetBuffered()) { size = buffered.Length; if (SetupInfo.MaxUploadSize < size) { throw FileSizeComment.FileSizeException; } file.ContentLength = size; try { file = FileDao.SaveFile(file, buffered); } catch (Exception error) { FileDao.DeleteFile(file.ID); throw error; } } } else { try { file = FileDao.SaveFile(file, stream); } catch (Exception error) { FileDao.DeleteFile(file.ID); throw error; } } if (conflict != null) { Global.PublishUpdateDocument(file.ID); } else { FilesActivityPublisher.UploadFile(FileDao.GetFile(file.ID)); } } } catch (Exception error) { Error = error; } finally { ProgressStep(); } } }
protected override void Do() { if (_files.Count == 0) { return; } var parent = FolderDao.GetFolder(_parentId); if (parent == null) { throw new DirectoryNotFoundException(FilesCommonResource.ErrorMassage_FolderNotFound); } if (!FilesSecurity.CanCreate(parent)) { throw new System.Security.SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create); } if (parent.RootFolderType == FolderType.TRASH) { throw new Exception(FilesCommonResource.ErrorMassage_ImportToTrash); } if (parent.ProviderEntry) { throw new System.Security.SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create); } var to = FolderDao.GetFolder(_folderName, _parentId) ?? FolderDao.SaveFolder( new Folder { FolderType = FolderType.DEFAULT, ParentFolderID = _parentId, Title = _folderName }); foreach (var f in _files) { if (Canceled) { return; } try { long size; using (var stream = _docProvider.GetDocumentStream(f.ContentLink, out size)) { if (stream == null) { throw new Exception("Can not import document " + f.ContentLink + ". Empty stream."); } if (SetupInfo.MaxUploadSize < size) { throw FileSizeComment.FileSizeException; } var folderId = to.ID; var pos = f.Title.LastIndexOf('/'); if (0 < pos) { folderId = GetOrCreateHierarchy(f.Title.Substring(0, pos), to); f.Title = f.Title.Substring(pos + 1); } f.Title = Global.ReplaceInvalidCharsAndTruncate(f.Title); var file = new File { Title = f.Title, FolderID = folderId, ContentLength = size, }; var conflict = FileDao.GetFile(file.FolderID, file.Title); if (conflict != null) { if (_overwrite) { if (!FilesSecurity.CanEdit(conflict)) { throw new Exception(FilesCommonResource.ErrorMassage_SecurityException); } if ((conflict.FileStatus & FileStatus.IsEditing) == FileStatus.IsEditing) { throw new Exception(FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile); } if (EntryManager.FileLockedForMe(conflict)) { throw new Exception(FilesCommonResource.ErrorMassage_LockedFile); } file.ID = conflict.ID; file.Version = conflict.Version + 1; } else { continue; } } if (size <= 0L) { using (var buffered = stream.GetBuffered()) { size = buffered.Length; if (SetupInfo.MaxUploadSize < size) { throw FileSizeComment.FileSizeException; } file.ContentLength = size; try { file = FileDao.SaveFile(file, buffered); } catch (Exception error) { FileDao.DeleteFile(file.ID); throw error; } } } else { try { file = FileDao.SaveFile(file, stream); FilesMessageService.Send(file, httpRequestHeaders, MessageAction.FileImported, parent.Title, file.Title, _docProvider.Name); } catch (Exception error) { FileDao.DeleteFile(file.ID); throw error; } } FileMarker.MarkAsNew(file, _markAsNewRecipientIDs); } } catch (Exception ex) { Error = ex.Message; Logger.Error(Error, ex); } finally { ProgressStep(); } } }