private string GetSolictZipFile(List <KeyValuePair <string, DateTime> > docPaths) { if ((docPaths.Count == 1) && (CommonContentAndFormatProvider.GetFileTypeFromName(docPaths[0].Key) == CommonContentType.ZIP)) { AppendAuditLogEvent("Added document \"{0}\" to solicit request", docPaths[0].Key); return(docPaths[0].Key); // Single file and already zipped } ISettingsProvider settingsProvider; ICompressionHelper compressionHelper; GetServiceImplementation(out settingsProvider); GetServiceImplementation(out compressionHelper); List <string> files = new List <string>(docPaths.Count); foreach (KeyValuePair <string, DateTime> pair in docPaths) { AppendAuditLogEvent("Added document \"{0}\" to solicit request", pair.Key); files.Add(pair.Key); } string tempFile = settingsProvider.NewTempFilePath(".zip"); compressionHelper.CompressFiles(tempFile, files); return(tempFile); }
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(), '_')); }
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; } }
public virtual PaginatedContentResult ProcessQuery(string requestId) { string dataFilePath = GetDataFile(requestId, false); byte[] data; CommonContentType?contentType = CommonContentType.XML; if (string.IsNullOrEmpty(dataFilePath)) { data = new byte[0]; } else { data = File.ReadAllBytes(dataFilePath); contentType = CommonContentAndFormatProvider.GetFileTypeFromContent(data); if (!contentType.HasValue) { contentType = CommonContentType.OTHER; } } PaginatedContentResult result = new PaginatedContentResult(_dataRequest.RowIndex, 0, true, contentType.Value, data); return(result); }
/// <summary> /// NotifyDocument11 /// </summary> /// <returns></returns> public string NotifyDocument11(string nodeEndpoint, string flow, string name, CommonContentType type, string content) { string transactionId = _requestor.Notify(Authenticate(), nodeEndpoint, flow, name, CommonContentAndFormatProvider.ConvertTo11Enum(type), content); return(transactionId); }
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)); }
protected virtual void DoDownloadResponse(byte[] content, string documentName, CommonContentType contentType) { Response.ClearHeaders(); Response.ClearContent(); Response.AddHeader("Content-Disposition", string.Format("attachment;filename=\"{0}\"", documentName)); Response.AddHeader("Content-Length", content.Length.ToString()); Response.ContentType = CommonContentAndFormatProvider.ConvertToMimeType(contentType); Response.BinaryWrite(content); Response.End(); }
protected virtual string AddDocument(string transactionId, CommonTransactionStatusCode status, string statusDetail, string filePath, bool dontAutoCompress) { string docName = Path.GetFileName(filePath); Document doc = new Document(docName, CommonContentAndFormatProvider.GetFileTypeFromName(docName), File.ReadAllBytes(filePath)); doc.DontAutoCompress = dontAutoCompress; 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); }
public virtual HttpResponseMessage Get([FromUri] QueryParameters parameters) { NamedOrAuthEndpointVisit visit = GetNamedOrAuthEndpointVisit(parameters); FormattedPaginatedContentRequest request = new FormattedPaginatedContentRequest(); request.FlowName = parameters.Dataflow; request.OperationName = parameters.Request; request.Paging = new PaginationIndicator(); request.Paging.Start = parameters.RowId.HasValue ? parameters.RowId.Value : 0; request.Paging.Count = parameters.MaxRows.HasValue ? parameters.MaxRows.Value : -1; request.Parameters = parameters.ParseParams(); request.ZipResults = parameters.ZipResults; PaginatedContentResult resultSet = ServiceProvider.TransactionService.QueryEx(request, visit); if ((resultSet == null) || !resultSet.HasContent) { return(this.Request.CreateBadRequestResponse("No data was returned from the query.")); } HttpResponseMessage responseMessage = new HttpResponseMessage(); switch (resultSet.Content.Type) { case CommonContentType.XML: case CommonContentType.Flat: case CommonContentType.HTML: responseMessage.Content = new StringContent(resultSet.ConvertContentBytesToString()); break; default: responseMessage.Content = new ByteArrayContent(resultSet.Content.Content); break; } responseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue(CommonContentAndFormatProvider.ConvertToMimeType(resultSet.Content.Type)); return(responseMessage); }
public string[] DownloadByName(string flow, string transactionId, params string[] documentNames) { if (CollectionUtils.IsNullOrEmpty(documentNames)) { throw new ArgumentException("documentNames cannot be empty"); } Windsor.Node.Proxy11.WSDL.NodeDocument[] documents = new Windsor.Node.Proxy11.WSDL.NodeDocument[documentNames.Length]; for (int i = 0; i < documentNames.Length; ++i) { Windsor.Node.Proxy11.WSDL.NodeDocument document = new Windsor.Node.Proxy11.WSDL.NodeDocument(); document.name = documentNames[i]; CommonContentType type = CommonContentAndFormatProvider.GetFileTypeFromName(document.name); if (type == CommonContentType.OTHER) { type = CommonContentType.XML; // Assume XML } document.type = type.ToString(); documents[i] = document; } _requestor.Download(Authenticate(), transactionId, flow, ref documents); return(SaveDownloadedDocuments(documents, null)); //throw new InvalidOperationException("DownloadByName() is not a valid method call for Client11"); }
/// <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); }
public PaginatedContentResult(string filePath) : this(0, -1, true, CommonContentAndFormatProvider.GetFileTypeFromName(filePath), File.ReadAllBytes(filePath)) { }
/// <summary> /// Download /// </summary> /// <param name="securityToken"></param> /// <param name="transactionId"></param> /// <param name="dataflow"></param> /// <param name="documents"></param> void INetworkNodeBinding.Download(string securityToken, string transactionId, string dataflow, ref NodeDocument[] documents) { Init(); LOG.Debug("Download"); if (string.IsNullOrEmpty(transactionId)) { throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "NULL Transaction Id"); } try { SoapContext res = HttpSoapContext.ResponseContext; LOG.Debug("Getting visit"); NamedEndpointVisit visit = _service11Provider.VisitProvider.GetVisit(securityToken); ComplexContent content = new ComplexContent(); if (!string.IsNullOrEmpty(dataflow)) { content.Flow = new OperationDataFlow(dataflow); } content.Transaction = new SimpleId(transactionId); LOG.Debug("Submitting: " + content); IList <Document> wnosDocs = _service11Provider.ContentService.Download(content, visit); List <NodeDocument> wsdlDocList = new List <NodeDocument>(); if (!CollectionUtils.IsNullOrEmpty(wnosDocs)) { Dictionary <string, string> docIdList = new Dictionary <string, string>(); LOG.Debug("Spooling documents"); foreach (Document wnosDoc in wnosDocs) { NodeDocument doc = new NodeDocument(); doc.content = wnosDoc.Content; doc.type = CommonContentAndFormatProvider.ConvertTo11Enum(wnosDoc.Type); doc.name = wnosDoc.DocumentName; LOG.Debug(" doc:" + doc); DimeAttachment attachment = new DimeAttachment(); attachment.Stream = new MemoryStream(doc.content); attachment.TypeFormat = TypeFormatEnum.MediaType; attachment.Type = "application/x-gzip"; attachment.Id = Guid.NewGuid().ToString(); //Add to the the xref filter collection docIdList.Add(doc.name, attachment.Id); res.Attachments.Add(attachment); wsdlDocList.Add(doc); } //Output filter specific res.Add("hrefs", docIdList); } documents = wsdlDocList.ToArray(); } catch (Exception ex) { LOG.Error("Error while downloading", ex); throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ex); } }
/// <summary> /// Submit /// </summary> /// <param name="securityToken"></param> /// <param name="transactionId"></param> /// <param name="dataflow"></param> /// <param name="documents"></param> /// <returns></returns> string INetworkNodeBinding.Submit(string securityToken, string transactionId, string dataflow, NodeDocument[] documents) { Init(); LOG.Debug("Submit"); if (documents == null || documents.Length == 0) { throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "Document not provided"); } SoapContext context = HttpSoapContext.RequestContext; bool useDimeAttachments = true; if (context == null || context.Attachments == null || context.Attachments.Count == 0) { bool allContentNull = true; bool anyContentMissing = false; foreach (NodeDocument document in documents) { if (document.content == null) { anyContentMissing = true; } else { allContentNull = false; } } if (anyContentMissing) { if (!allContentNull) { // Some documents contain content, some don't, what the heck is this??? throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "Some documents do not contain any content."); } // All document content is null, attempt to locate all <content> elements in the xml itself XmlNodeList nodeList = context.Envelope.Body.GetElementsByTagName("content"); if ((nodeList == null) || (nodeList.Count != documents.Length)) { throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "Could not locate the data content for the submitted documents."); } int index = 0; foreach (NodeDocument document in documents) { XmlNode contentContentNode = nodeList[index++]; if (string.IsNullOrEmpty(contentContentNode.InnerXml)) { throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "Some documents do not contain any content."); } document.content = System.Convert.FromBase64String(contentContentNode.InnerXml); } } useDimeAttachments = false; } else if (context.Attachments.Count != documents.Length) { throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter, "DIME attachment count does not equal to the number of documents."); } try { LOG.Debug("Getting visit"); NamedEndpointVisit visit = _service11Provider.VisitProvider.GetVisit(securityToken); AsyncComplexContent content = new AsyncComplexContent(); content.Documents = new List <Document>(); content.Flow = new OperationDataFlow(dataflow); content.Transaction = new SimpleId(transactionId); int attachmentCounter = 0; LOG.Debug("Spooling documents"); foreach (NodeDocument wsdlDoc in documents) { Document doc = new Document(); doc.Content = useDimeAttachments ? GetContent(context.Attachments[attachmentCounter++].Stream) : wsdlDoc.content; doc.Type = CommonContentAndFormatProvider.Convert(wsdlDoc.type); doc.DocumentId = string.Empty; doc.DocumentName = wsdlDoc.name; LOG.Debug(" doc:" + doc); content.Documents.Add(doc); } LOG.Debug("Submitting: " + content); TransactionStatus status = _service11Provider.ContentService.Submit(content, visit); LOG.Debug("Status: " + status); return(status.Id); //Status ID in this case is the transaction id } catch (Exception ex) { LOG.Error("Error while submitting", ex); throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ex); } }
public virtual string ConvertContentBytesToString() { return(CommonContentAndFormatProvider.ConvertContentBytesToString(_content)); }