private bool CheckToCompressDocument(Document ioDocument) { if (_alwaysCompressDocumentContents) { if (!ioDocument.DontAutoCompress && !ioDocument.IsZipFile) { if (!string.IsNullOrEmpty(ioDocument.DocumentName)) { if ((ioDocument.DocumentName == "Node20.Report") || (ioDocument.DocumentName == "Node20.Error") || (ioDocument.DocumentName == "Node20.Original")) { // Don't compress these special files return(false); } } else { ioDocument.DocumentName = Guid.NewGuid().ToString(); } string originalDocumentName = ioDocument.DocumentName; string zipExtension = CommonContentAndFormatProvider.GetFileExtension(CommonContentType.ZIP); ioDocument.DocumentName = Path.ChangeExtension(ioDocument.DocumentName, zipExtension); ioDocument.Type = CommonContentType.ZIP; if (!CollectionUtils.IsNullOrEmpty(ioDocument.Content)) { ioDocument.Content = _compressionHelper.Compress(originalDocumentName, ioDocument.Content); } return(true); } } return(false); }
/// <summary> /// Add the input document to the node. /// </summary> public string AddDocument(string transactionId, CommonTransactionStatusCode status, string statusDetail, Document document) { if (CollectionUtils.IsNullOrEmpty(document.Content)) { throw new ArgumentException(string.Format("Document does not contain any content: \"{0}\".", document)); } string newId = IdProvider.Get(); try { document.Id = newId; // First, attempt to save all the documents to the repository if (string.IsNullOrEmpty(document.DocumentId)) { document.DocumentId = newId; // If not specified, set this to DB id } if (string.IsNullOrEmpty(document.DocumentName)) { // If not specified, set this to DB id + extension document.DocumentName = Path.ChangeExtension(newId, CommonContentAndFormatProvider.GetFileExtension(document.Type)); } CheckToCompressDocument(document); LOG.Debug("Saving document: \"{0}\"", document); _documentDao.CreateDocument(transactionId, status, statusDetail, document); _documentContentManager.SaveDocumentContent(transactionId, newId, document.Content, false); return(newId); } catch (Exception) { RollbackDocument(transactionId, newId); throw; } }
protected virtual string GetFileNameForRequestContent(FormattedPaginatedContentRequest request, PaginatedContentResult result) { StringBuilder sb = new StringBuilder(); if (!string.IsNullOrEmpty(request.FlowName)) { if (sb.Length > 0) { sb.Append("_"); } sb.Append(request.FlowName); } if (!string.IsNullOrEmpty(request.OperationName)) { if (sb.Length > 0) { sb.Append("_"); } sb.Append(request.OperationName); } if (sb.Length > 0) { sb.Append("_"); } sb.Append("Results"); sb.Append(CommonContentAndFormatProvider.GetFileExtension(result.Content.Type)); return(FileUtils.ReplaceInvalidFilenameChars(sb.ToString(), '_')); }
public string AddDocument(string transactionId, ExecuteContentResult result) { string docName = Path.ChangeExtension(Guid.NewGuid().ToString(), CommonContentAndFormatProvider.GetFileExtension(result.Content.Type)); Document doc = new Document(docName, result.Content.Type, result.Content.Content); return(AddDocument(transactionId, result.Status, null, doc)); }
public string AddDocument(string transactionId, CommonTransactionStatusCode status, string statusDetail, PaginatedContentResult result) { string docName = Path.ChangeExtension(Guid.NewGuid().ToString(), CommonContentAndFormatProvider.GetFileExtension(result.Content.Type)); Document doc = new Document(docName, result.Content.Type, result.Content.Content); return(AddDocument(transactionId, status, statusDetail, doc)); }
/// <summary> /// Add all the input documents to the node. /// </summary> public IList <string> AddDocuments(string transactionId, IList <Document> documents) { if (CollectionUtils.IsNullOrEmpty(documents)) { return(null); } List <string> newDocumentIds = new List <string>(documents.Count); try { LOG.Debug("Saving documents"); // First, generate ids for new documents foreach (Windsor.Node2008.WNOSDomain.Document document in documents) { if (CollectionUtils.IsNullOrEmpty(document.Content)) { throw new ArgumentException(string.Format("Document does not contain any content: \"{0}\".", document)); } document.Id = IdProvider.Get(); if (string.IsNullOrEmpty(document.DocumentId)) { document.DocumentId = document.Id; // If not specified, set this to DB id } if (string.IsNullOrEmpty(document.DocumentName)) { // If not specified, set this to DB id + extension document.DocumentName = Path.ChangeExtension(document.Id, CommonContentAndFormatProvider.GetFileExtension(document.Type)); } newDocumentIds.Add(document.Id); CheckToCompressDocument(document); } // Next, save the new documents to the DB _documentDao.CreateDocuments(transactionId, documents); // Finally, save document content to repository int index = 0; foreach (Windsor.Node2008.WNOSDomain.Document document in documents) { LOG.Debug("Saving document: \"{0}\"", document); _documentContentManager.SaveDocumentContent(transactionId, newDocumentIds[index++], document.Content, false); } return(newDocumentIds); } catch (Exception) { RollbackDocuments(transactionId, newDocumentIds); throw; } }
protected virtual void ProcessWebServiceQuerySource(ScheduledItem scheduledItem, Activity activity, string transactionId) { PartnerIdentity partner = _partnerManager.GetById(scheduledItem.SourceId); if (partner == null) { throw new ArgumentException(string.Format("Invalid partner id \"{0}.\" Could not find partner for scheduled item \"{1}\".", scheduledItem.TargetId, scheduledItem.Name)); } string filePath = Path.Combine(SettingsProvider.TempFolderPath, GetResultFileName(scheduledItem)); using (INodeEndpointClient client = GetNodeClient(partner, activity, scheduledItem.SourceEndpointUser)) { CommonContentType type; try { if (client.Version == EndpointVersionType.EN11) { type = client.Query(null, scheduledItem.SourceRequest, scheduledItem.GetTranformedSourceArgs(), 0, -1, filePath); _transactionManager.SetNetworkIdAndEndpointUserId(transactionId, transactionId, EndpointVersionType.EN11, partner.Url, scheduledItem.SourceRequest, null, null, scheduledItem.SourceEndpointUser); } else { type = client.Query(scheduledItem.SourceFlow, scheduledItem.SourceRequest, scheduledItem.GetTranformedSourceArgs(), 0, -1, filePath); _transactionManager.SetNetworkIdAndEndpointUserId(transactionId, transactionId, EndpointVersionType.EN20, partner.Url, scheduledItem.SourceFlow, scheduledItem.SourceRequest, null, scheduledItem.SourceEndpointUser); } } catch (Exception e) { LogActivityError(activity, "Error returned from node endpoint: \"{0}\"", ExceptionUtils.GetDeepExceptionMessage(e)); throw; } filePath = FileUtils.ChangeFileExtension(filePath, CommonContentAndFormatProvider.GetFileExtension(type)); DocumentManager.AddDocument(transactionId, CommonTransactionStatusCode.Processed, null, filePath); } LogActivity(activity, "Performed Query of partner \"{0}\" at url \"{1}\"", partner.Name, partner.Url); }
/// <summary> /// ProcessSubmit /// </summary> public void ProcessSubmit(string transactionId) { ITransactionManager transactionManager; ISettingsProvider settingsProvider; IDocumentManager documentManager; AppendAuditLogEvent("Enter CopySubmitFilesToFolder.ProcessSubmit({0})", transactionId); GetServiceImplementation(out transactionManager); GetServiceImplementation(out settingsProvider); GetServiceImplementation(out documentManager); string destinationFolderPath; if (!ConfigurationArguments.TryGetValue(DESTINATION_FOLDER_PATH, out destinationFolderPath)) { throw new ArgumentException("DESTINATION_FOLDER_PATH configuration key not set"); } if (!Directory.Exists(destinationFolderPath)) { throw new DirectoryNotFoundException(string.Format("DESTINATION_FOLDER_PATH does not exist: {0}", destinationFolderPath)); } bool createUsernameSubfolder = false; { string usernameSubfolder; if (ConfigurationArguments.TryGetValue(USE_USERNAME_SUBFOLDER, out usernameSubfolder) && !string.IsNullOrEmpty(usernameSubfolder)) { try { createUsernameSubfolder = bool.Parse(usernameSubfolder); } catch (Exception) { throw new FormatException(string.Format("Could not parse USE_USERNAME_SUBFOLDER true/false value: {0}", usernameSubfolder)); } } } if (createUsernameSubfolder) { string username = transactionManager.GetTransactionUsername(transactionId); if (string.IsNullOrEmpty(username)) { throw new ArgumentException(string.Format("Could not username for transaction: {0}", transactionId)); } username = FileUtils.ReplaceInvalidFilenameChars(username, '_'); destinationFolderPath = Path.Combine(destinationFolderPath, username); } AppendAuditLogEvent("DESTINATION_FOLDER_PATH: \"{0}\"", destinationFolderPath); IList <string> dbDocIds = transactionManager.GetAllUnprocessedDocumentDbIds(transactionId); if (!CollectionUtils.IsNullOrEmpty(dbDocIds)) { if (!Directory.Exists(destinationFolderPath)) { Directory.CreateDirectory(destinationFolderPath); AppendAuditLogEvent("Created folder DESTINATION_FOLDER_PATH: \"{0}\"", destinationFolderPath); } foreach (string dbDocId in dbDocIds) { Document document = documentManager.GetDocument(transactionId, dbDocId, true); string docName; if (!string.IsNullOrEmpty(document.DocumentName)) { docName = document.DocumentName; } else if (!string.IsNullOrEmpty(document.DocumentId)) { docName = document.DocumentName; } else { docName = dbDocId; } docName = FileUtils.ReplaceInvalidFilenameChars(docName, '_'); docName = Path.ChangeExtension(docName, CommonContentAndFormatProvider.GetFileExtension(document.Type)); string copyPath = FileUtils.MakeUniqueIncrementalFilePath(destinationFolderPath, docName); File.WriteAllBytes(copyPath, document.Content); AppendAuditLogEvent("Copied file \"{0}\"", copyPath); documentManager.SetDocumentStatus(transactionId, dbDocId, CommonTransactionStatusCode.Processed, "Processed " + dbDocId); } } AppendAuditLogEvent("Exit CopySubmitFilesToFolder.ProcessSubmit({0})", transactionId); }