public static void PublishUpdateDocument(object fileId) { var file = DaoFactory.GetFileDao().GetFile(fileId); FilesActivityPublisher.UpdateFile(file); NotifyClient.SendUpdateNotice(file); var newTags = NotifySource.Instance.GetSubscriptionProvider() .GetRecipients(NotifyConstants.Event_UpdateDocument, file.UniqID) .Select(id => new Guid(id.ID)) .Where(id => id != SecurityContext.CurrentAccount.ID) .Select(r => Tag.New(r, file)).ToArray(); DaoFactory.GetTagDao().SaveTags(newTags); }
public static File UploadFile(string folderId, string title, long contentLength, string contentType, Stream data, bool createNewIfExist) { if (contentLength > SetupInfo.MaxUploadSize) { throw FileSizeComment.FileSizeException; } if (contentLength <= 0) { throw new InvalidOperationException(FilesCommonResource.ErrorMassage_EmptyFile); } title = Global.ReplaceInvalidCharsAndTruncate(Path.GetFileName(title)); using (var dao = Global.DaoFactory.GetFileDao()) { var file = dao.GetFile(folderId, title); if (file == null || createNewIfExist) { using (var folderDao = Global.DaoFactory.GetFolderDao()) { var folder = folderDao.GetFolder(folderId); if (folder == null) { throw new Exception(FilesCommonResource.ErrorMassage_FolderNotFound); } if (!Global.GetFilesSecurity().CanCreate(folder)) { throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create); } file = new File { FolderID = folder.ID, Title = title, ContentLength = contentLength, ContentType = contentType }; } try { file = dao.SaveFile(file, data); } catch { dao.DeleteFile(file.ID); throw; } FilesActivityPublisher.UploadFile(dao.GetFile(file.ID)); } else { if (!Global.GetFilesSecurity().CanEdit(file)) { throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException); } if ((file.FileStatus & FileStatus.IsEditing) == FileStatus.IsEditing) { throw new Exception(FilesCommonResource.ErrorMassage_SecurityException_DeleteEditingFile); } file.Title = title; file.ContentLength = contentLength; file.ContentType = contentType; file.ConvertedType = null; file.Version++; file = dao.SaveFile(file, data); Global.PublishUpdateDocument(file.ID); } return(file); } }