public void Add(File <T> file, string password, int tenantId, IAccount account, bool deleteAfter, string url) { lock (locker) { if (conversionQueue.ContainsKey(file)) { return; } var queueResult = new ConvertFileOperationResult { Source = string.Format("{{\"id\":\"{0}\", \"version\":\"{1}\"}}", file.ID, file.Version), OperationType = FileOperationType.Convert, Error = string.Empty, Progress = 0, Result = string.Empty, Processed = "", Id = string.Empty, TenantId = tenantId, Account = account, Delete = deleteAfter, StartDateTime = DateTime.Now, Url = url, Password = password }; conversionQueue.Add(file, queueResult); cache.Insert(GetKey(file), queueResult, TimeSpan.FromMinutes(10)); timer.Change(0, Timeout.Infinite); } }
public void ExecAsync(File file, bool deleteAfter, string password = null) { if (!MustConvert(file)) { throw new ArgumentException(FilesCommonResource.ErrorMassage_NotSupportedFormat); } if (!string.IsNullOrEmpty(file.ConvertedType) || FileUtility.InternalExtension.Values.Contains(FileUtility.GetFileExtension(file.Title))) { return; } FileMarker.RemoveMarkAsNew(file); lock (locker) { if (conversionQueue.ContainsKey(file)) { return; } var queueResult = new ConvertFileOperationResult { Source = string.Format("{{\"id\":\"{0}\", \"version\":\"{1}\"}}", file.ID, file.Version), OperationType = FileOperationType.Convert, Error = string.Empty, Progress = 0, Result = string.Empty, Processed = "", Id = string.Empty, TenantId = TenantManager.GetCurrentTenant().TenantId, Account = AuthContext.CurrentAccount, Delete = deleteAfter, StartDateTime = DateTime.Now, Url = HttpContextAccesor?.HttpContext != null?HttpContextAccesor.HttpContext.Request.GetUrlRewriter().ToString() : null, Password = password }; conversionQueue.Add(file, queueResult); cache.Insert(GetKey(file), queueResult, TimeSpan.FromMinutes(10)); if (timer == null) { timer = new Timer(CheckConvertFilesStatus, null, 0, Timeout.Infinite); } else { timer.Change(0, Timeout.Infinite); } } }
public static void ExecAsync(File file, bool deleteAfter) { if (!MustConvert(file)) { throw new ArgumentException(FilesCommonResource.ErrorMassage_NotSupportedFormat); } if (!String.IsNullOrEmpty(file.ConvertedType) || FileUtility.InternalExtension.Values.Contains(FileUtility.GetFileExtension(file.Title))) { return; } FileMarker.RemoveMarkAsNew(file); lock (locker) { if (conversionQueue.ContainsKey(file)) { throw new Exception(FilesCommonResource.ErrorMassage_Reconverting); } var queueResult = new ConvertFileOperationResult { Source = String.Format("{{\"id\":\"{0}\", \"version\":\"{1}\"}}", file.ID, file.Version), OperationType = FileOperationType.Convert, Error = String.Empty, Progress = 0, Result = String.Empty, Processed = "", Id = String.Empty, TenantId = TenantProvider.CurrentTenantID, Account = SecurityContext.CurrentAccount, Delete = deleteAfter }; conversionQueue.Add(file, queueResult); cache.Insert(GetKey(file), queueResult, TimeSpan.FromMinutes(30)); if (timer == null) { timer = new Timer(CheckConvertFilesStatus, null, 0, Timeout.Infinite); } else { timer.Change(0, Timeout.Infinite); } } }
public FileOperationResult ExecSync <T>(File <T> file, string doc) { var fileDao = DaoFactory.GetFileDao <T>(); var fileSecurity = FileSecurity; if (!fileSecurity.CanRead(file)) { var readLink = FileShareLink.Check(doc, true, fileDao, out file); if (file == null) { throw new ArgumentNullException("file", FilesCommonResource.ErrorMassage_FileNotFound); } if (!readLink) { throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_ReadFile); } } var fileUri = PathProvider.GetFileStreamUrl(file); var fileExtension = file.ConvertedExtension; var toExtension = FileUtility.GetInternalExtension(file.Title); var docKey = DocumentServiceHelper.GetDocKey(file); fileUri = DocumentServiceConnector.ReplaceCommunityAdress(fileUri); DocumentServiceConnector.GetConvertedUri(fileUri, fileExtension, toExtension, docKey, null, null, null, false, out var convertUri); var operationResult = new ConvertFileOperationResult { Source = string.Format("{{\"id\":\"{0}\", \"version\":\"{1}\"}}", file.ID, file.Version), OperationType = FileOperationType.Convert, Error = string.Empty, Progress = 0, Result = string.Empty, Processed = "", Id = string.Empty, TenantId = TenantManager.GetCurrentTenant().TenantId, Account = AuthContext.CurrentAccount, Delete = false, StartDateTime = DateTime.Now, Url = HttpContextAccesor?.HttpContext != null?HttpContextAccesor.HttpContext.Request.GetUrlRewriter().ToString() : null, Password = null, ServerRootPath = BaseCommonLinkUtility.ServerRootPath }; var operationResultError = string.Empty; var newFile = SaveConvertedFile(file, convertUri); if (newFile != null) { var folderDao = DaoFactory.GetFolderDao <T>(); var folder = folderDao.GetFolder(newFile.FolderID); var folderTitle = fileSecurity.CanRead(folder) ? folder.Title : null; operationResult.Result = GetFileConverter <T>().FileJsonSerializer(EntryStatusManager, newFile, folderTitle); } operationResult.Progress = 100; operationResult.StopDateTime = DateTime.UtcNow; operationResult.Processed = "1"; if (!string.IsNullOrEmpty(operationResultError)) { operationResult.Error = operationResultError; } return(operationResult); }