public string SubmitFile(string filePath, string localTransactionId) { string transactionId; try { UserSubmitInfo userSubmitInfo = _naasUsernameToPasswordMap[_submitUsername.ToUpper()]; AppendAuditLogEvent("Submitting results to endpoint \"{0}\" using NAAS account: \"{1}\"", _submitPartnerNode.Name, _submitUsername); string networkFlowName = RCRABaseSolicitProcessor.RCRA_FLOW_NAME, networkFlowOperation = null; try { using (INodeEndpointClient endpointClient = _nodeEndpointClientFactory.Make(_submitPartnerNode.Url, _submitPartnerNode.Version, new AuthenticationCredentials(_submitUsername, userSubmitInfo.Password))) { if (endpointClient.Version == EndpointVersionType.EN20) { IList <string> notificationUris = null; if (!string.IsNullOrEmpty(_notifications)) { notificationUris = StringUtils.SplitAndReallyRemoveEmptyEntries(_notifications, ',', ';'); } transactionId = endpointClient.Submit(networkFlowName, "default", string.Empty, notificationUris, new string[] { filePath }); networkFlowOperation = "default"; } else { transactionId = endpointClient.Submit(networkFlowName, null, new string[] { filePath }); } } AppendAuditLogEvent("Successfully submitted results to endpoint \"{0}\" with returned transaction id \"{1}\"", _submitPartnerNode.Name, transactionId); } catch (Exception e) { AppendAuditLogEvent("Failed to submit results to endpoint \"{0}\": {1}", _submitPartnerNode.Name, ExceptionUtils.ToShortString(e)); throw; } _transactionManager.SetNetworkId(localTransactionId, transactionId, _submitPartnerNode.Version, _submitPartnerNode.Url, networkFlowName, networkFlowOperation); } catch (Exception e) { AppendAuditLogEvent("Failed to submit results to endpoint \"{0}\" with exception: {1}", _submitPartnerNode.Name, ExceptionUtils.ToShortString(e)); throw; } finally { FileUtils.SafeDeleteFile(filePath); } return(transactionId); }
protected string SubmitFile(string filePath, string localTransactionId) { string transactionId; try { UserSubmitInfo userSubmitInfo = _naasUsernameToPasswordMap[_submitUsername.ToUpper()]; AppendAuditLogEvent("Submitting results to endpoint \"{0}\" using NAAS account: \"{1}\"", _submitPartnerNode.Name, _submitUsername); try { using (INodeEndpointClient endpointClient = _nodeEndpointClientFactory.Make(_submitPartnerNode.Url, _submitPartnerNode.Version, new AuthenticationCredentials(_submitUsername, userSubmitInfo.Password))) { if (endpointClient.Version == EndpointVersionType.EN20) { transactionId = endpointClient.Submit(AQS_FLOW_NAME, string.Empty, string.Empty, new string[] { filePath }); } else { transactionId = endpointClient.Submit(AQS_FLOW_NAME, null, new string[] { filePath }); } } AppendAuditLogEvent("Successfully submitted results to endpoint \"{0}\" with returned transaction id \"{1}\"", _submitPartnerNode.Name, transactionId); } catch (Exception e) { AppendAuditLogEvent("Failed to submit results to endpoint \"{0}\": {1}", _submitPartnerNode.Name, ExceptionUtils.ToShortString(e)); throw; } _transactionManager.SetNetworkId(localTransactionId, transactionId, _submitPartnerNode.Version, _submitPartnerNode.Url, AQS_FLOW_NAME, null); } catch (Exception e) { AppendAuditLogEvent("Failed to submit results to endpoint \"{0}\" with exception: {1}", _submitPartnerNode.Name, ExceptionUtils.ToShortString(e)); throw; } finally { FileUtils.SafeDeleteFile(filePath); } return(transactionId); }
protected string SubmitData(string transactionId, string submitFilePath) { string networkTransactionId; try { string networkFlowName = _submitFlowName, networkFlowOperation = null; AppendAuditLogEvent("Submitting results to endpoint \"{0}\"", _epaPartnerNode.Name); try { using (INodeEndpointClient endpointClient = _nodeEndpointClientFactory.Make(_epaPartnerNode.Url, _epaPartnerNode.Version)) { if (endpointClient.Version == EndpointVersionType.EN20) { networkTransactionId = endpointClient.Submit(_submitFlowName, _submitFlowOperation, string.Empty, new string[] { submitFilePath }); networkFlowOperation = _submitFlowOperation; } else { networkTransactionId = endpointClient.Submit(_submitFlowName, null, new string[] { submitFilePath }); } } AppendAuditLogEvent("Successfully submitted results to endpoint \"{0}\" with returned transaction id \"{1}\"", _epaPartnerNode.Name, networkTransactionId); } catch (Exception e) { AppendAuditLogEvent("Failed to submit results to endpoint \"{0}\": {1}", _epaPartnerNode.Name, ExceptionUtils.ToShortString(e)); throw; } _transactionManager.SetNetworkId(transactionId, networkTransactionId, _epaPartnerNode.Version, _epaPartnerNode.Url, networkFlowName, networkFlowOperation); } catch (Exception e) { AppendAuditLogEvent("Failed to submit results to endpoint \"{0}\" with exception: {1}", _epaPartnerNode.Name, ExceptionUtils.ToShortString(e)); throw; } return(networkTransactionId); }
/// <summary> /// Plug-in service processor method /// </summary> /// <param name="transactionId">Transaction ID reference</param> public void ProcessSubmit(string transactionId) { TransactionStatus status = new TransactionStatus(transactionId); try { LazyInit(); WriteOut("Runtime arguments:"); foreach (string param in Enum.GetNames(typeof(AqsEndpointProxyServiceParameterType))) { WriteOut("{0} = {1}; ", param, ConfigurationArguments[param]); } WriteOut("Getting documents:"); IList <Document> documents = _documentManager.GetDocuments(transactionId, true); List <string> documentPaths = new List <string>(); string tempDirPath = Path.Combine(_settingsProvider.TempFolderPath, Guid.NewGuid().ToString()); WriteOut("Creating temp. directory: " + tempDirPath); Directory.CreateDirectory(tempDirPath); foreach (Document doc in documents) { WriteOut("Doc: {0} ({1}); ", doc.DocumentName, doc.Type); string tempDocPath = Path.Combine(tempDirPath, doc.DocumentName); WriteOut("Saving content: " + tempDocPath); File.WriteAllBytes(tempDocPath, doc.Content); documentPaths.Add(tempDocPath); } WriteOut("Parsing argument values..."); _strSubmitEndpointUri = ConfigurationArguments[AqsEndpointProxyServiceParameterType.SUBMIT_ENDPOINT_URI.ToString()]; WriteOut("endpointUrl: {0}; ", _strSubmitEndpointUri); if (!string.IsNullOrEmpty(_strSubmitEndpointUri)) { _strEnsUserId = GetConfigParameter(AqsEndpointProxyServiceParameterType.ENS_USER_ID.ToString()); WriteOut(" submit user: {0}", _strEnsUserId); _strEnsPassword = GetConfigParameter(AqsEndpointProxyServiceParameterType.ENS_PASSWORD.ToString()); WriteOut(" submit password: *********", _strEnsPassword); WriteOut("Creating endpoint client..."); _strDataFlow = ConfigurationArguments[AqsEndpointProxyServiceParameterType.DATA_FLOW.ToString()]; if (String.IsNullOrEmpty(_strDataFlow)) { _strDataFlow = FLOW_NAME; } string resultTranId = null; if (!String.IsNullOrEmpty(_strEnsUserId) && !String.IsNullOrEmpty(_strEnsPassword)) { WriteOut("Using custom credentials"); using (INodeEndpointClient nodeClient = _nodeEndpointClientFactory.Make(_strSubmitEndpointUri, EndpointVersionType.EN20, new AuthenticationCredentials(_strEnsUserId, _strEnsPassword))) { WriteOut("Submitting documents..."); resultTranId = nodeClient.Submit(_strDataFlow, null, documentPaths); if (string.IsNullOrEmpty(resultTranId)) { throw new ApplicationException("Node client did not return any transaction!"); } _transactionManager.SetTransactionStatus(transactionId, CommonTransactionStatusCode.Completed, WriteOut("Remote transaction Id: {1}", _strSubmitEndpointUri, resultTranId), true); _transactionManager.SetNetworkId(transactionId, resultTranId, EndpointVersionType.EN20, _strSubmitEndpointUri, _strDataFlow, null); WriteOut("Submission done..."); } } else { WriteOut("Using default credentials"); using (INodeEndpointClient nodeClient = _nodeEndpointClientFactory.Make(_strSubmitEndpointUri, EndpointVersionType.EN20)) { WriteOut("Submitting documents..."); resultTranId = nodeClient.Submit(_strDataFlow, null, documentPaths); if (string.IsNullOrEmpty(resultTranId)) { throw new ApplicationException("Node client did not return any transaction!"); } _transactionManager.SetTransactionStatus(transactionId, CommonTransactionStatusCode.Completed, WriteOut("Remote transaction Id: {1}", _strSubmitEndpointUri, resultTranId), true); _transactionManager.SetNetworkId(transactionId, resultTranId, nodeClient.Version, _strSubmitEndpointUri, _strDataFlow, null); WriteOut("Submission done..."); } } status.Description = string.Format("The AQS document was successfully submitted at {0} with a returned transaction id of {1}.", DateTime.Now, resultTranId); status.Status = CommonTransactionStatusCode.Completed; } } catch (Exception ex) { status.Description = string.Format("An error occurred running the {0} service:{1}{2}{3}", SERVICE_NAME, Environment.NewLine, Environment.NewLine, ExceptionUtils.GetDeepExceptionMessage(ex)); status.Status = CommonTransactionStatusCode.Failed; throw; } finally { if (status.Description != null) { AppendAuditLogEvent(status.Description); } if ((_notificationManager != null) && !string.IsNullOrEmpty(_strNotificationEmails)) { string strMessage; if (status.Status == CommonTransactionStatusCode.Completed) { strMessage = "Submitted AQS Document"; } else { strMessage = "Failed to Submit AQS Document"; } _notificationManager.DoScheduleNotifications(status, _strNotificationEmails, strMessage, SERVICE_NAME, null, null, status.Description); } } }
protected virtual void ProcessPartnerTarget(TransactionStatus transactionStatus, ScheduledItem scheduledItem, Activity activity) { PartnerIdentity partner = _partnerManager.GetById(scheduledItem.TargetId); 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 = GetZippedTransactionDocumentsAsTempFile(transactionStatus); if (filePath != null) { string transactionId; EndpointVersionType endpointVersion; string endpointUrl; string networkFlowName = null, networkFlowOperation = null; using (INodeEndpointClient client = GetNodeClient(partner, activity, scheduledItem.TargetEndpointUser)) { try { if (client.Version == EndpointVersionType.EN11) { LogActivity(activity, "Attempting to submit target documents as \"{0}\" to partner \"{1}\" for flow \"{2}\"", Path.GetFileName(filePath), partner.Name, scheduledItem.TargetFlow); transactionId = client.Submit(scheduledItem.TargetFlow, string.Empty, new string[] { filePath }); networkFlowName = scheduledItem.TargetFlow; } else { LogActivity(activity, "Attempting to submit target documents as \"{0}\" to partner \"{1}\" for flow \"{2}\" and operation \"{3}\"", Path.GetFileName(filePath), partner.Name, scheduledItem.TargetFlow, scheduledItem.TargetRequest); transactionId = client.Submit(scheduledItem.TargetFlow, scheduledItem.TargetRequest, string.Empty, new string[] { filePath }); networkFlowName = scheduledItem.TargetFlow; networkFlowOperation = scheduledItem.TargetRequest; } } catch (Exception e) { LogActivityError(activity, "Error returned from node endpoint: \"{0}\"", ExceptionUtils.GetDeepExceptionMessage(e)); throw; } endpointVersion = client.Version; endpointUrl = client.Url; } LogActivity(activity, "Submitted target documents to partner \"{0}\" at url \"{1}\" for flow \"{2}\" with returned transaction id \"{3}\"", partner.Name, partner.Url, scheduledItem.TargetFlow, transactionId); _transactionManager.SetNetworkIdAndEndpointUserId(transactionStatus.Id, transactionId, endpointVersion, endpointUrl, networkFlowName, networkFlowOperation, null, scheduledItem.TargetEndpointUser); } else { LogActivity(activity, "No target documents found to submit to partner \"{0}\"", partner.Name); } }
protected virtual string SubmitDataToEndpoint(string filePath) { if (_epaPartnerNode == null) { AppendAuditLogEvent("No node partner was specified for submission, so no Submit will be performed."); return(null); } string transactionId; try { AppendAuditLogEvent("Submitting BEACHES data to endpoint \"{0}\"", _epaPartnerNode.Name); ITransactionManager transactionManager; GetServiceImplementation(out transactionManager); string networkFlowName = BEACHES_FLOW_NAME, networkFlowOperation = null; try { INodeEndpointClientFactory nodeEndpointClientFactory; GetServiceImplementation(out nodeEndpointClientFactory); using (INodeEndpointClient endpointClient = nodeEndpointClientFactory.Make(_epaPartnerNode.Url, _epaPartnerNode.Version)) { if (endpointClient.Version == EndpointVersionType.EN20) { transactionId = endpointClient.Submit(BEACHES_FLOW_NAME, "default", string.Empty, new string[] { filePath }); networkFlowOperation = "default"; } else { transactionId = endpointClient.Submit(BEACHES_FLOW_NAME, null, new string[] { filePath }); } } AppendAuditLogEvent("Successfully submitted BEACHES data to endpoint \"{0}\" with returned transaction id \"{1}\"", _epaPartnerNode.Name, transactionId); UpdateStatusOfNetworkTransaction(_dataRequest.TransactionId, transactionId, _epaPartnerNode.Url, _epaPartnerNode.Version); } catch (Exception e) { AppendAuditLogEvent("Failed to submit BEACHES data to endpoint \"{0}\": {1}", _epaPartnerNode.Name, ExceptionUtils.ToShortString(e)); throw; } transactionManager.SetNetworkId(_dataRequest.TransactionId, transactionId, _epaPartnerNode.Version, _epaPartnerNode.Url, networkFlowName, networkFlowOperation); } catch (Exception e) { AppendAuditLogEvent("Failed to submit BEACHES data to endpoint \"{0}\" with exception: {1}", _epaPartnerNode.Name, ExceptionUtils.ToShortString(e)); throw; } finally { FileUtils.SafeDeleteFile(filePath); } return(transactionId); }
/// <summary> /// ProcessSubmit /// </summary> /// <param name="transactionId"></param> public void ProcessSubmit(string transactionId) { TransactionStatus status = new TransactionStatus(transactionId); try { LazyInit(); WriteOut("Runtime arguments:"); foreach (string param in Enum.GetNames(typeof(SdwisServiceParameterType))) { WriteOut("{0} = {1}; ", param, ConfigurationArguments[param]); } WriteOut("Getting documents:"); IList <Document> documents = _documentManager.GetDocuments(transactionId, true); List <string> documentPaths = new List <string>(); string tempDirPath = Path.Combine(_settingsProvider.TempFolderPath, Guid.NewGuid().ToString()); WriteOut("Creating temp. directory: " + tempDirPath); Directory.CreateDirectory(tempDirPath); foreach (Document doc in documents) { WriteOut("Doc: {0} ({1}); ", doc.DocumentName, doc.Type); string tempDocPath = Path.Combine(tempDirPath, doc.DocumentName); WriteOut("Saving content: " + tempDocPath); File.WriteAllBytes(tempDocPath, doc.Content); documentPaths.Add(tempDocPath); } string endpointUrl = ConfigurationArguments[SdwisServiceParameterType.SubmitEndpointUri.ToString()]; WriteOut("endpointUrl: {0}; ", endpointUrl); string resultTranId = null; EndpointVersionType endpointVersion; using (INodeEndpointClient client = _nodeEndpointClientFactory.Make(endpointUrl, EndpointVersionType.EN11)) { WriteOut("endpoint client created: {0}; ", client); //Set up client and submit the comrpessed file WriteOut("submitting documents..."); resultTranId = client.Submit("SDWIS", null, documentPaths); endpointVersion = client.Version; } if (string.IsNullOrEmpty(resultTranId)) { throw new ApplicationException("Node client did not return any transaction!"); } _transactionManager.SetTransactionStatus(transactionId, CommonTransactionStatusCode.Completed, WriteOut("Submission to: {0} resulted in: {1}", endpointUrl, resultTranId), true); _transactionManager.SetNetworkId(transactionId, resultTranId, endpointVersion, endpointUrl, "SDWIS", null); WriteOut("Done processing submission"); status.Description = string.Format("The SDWIS document was successfully submitted at {0} with a returned transaction id of {1}.", DateTime.Now, resultTranId); status.Status = CommonTransactionStatusCode.Completed; } catch (Exception ex) { status.Description = string.Format("An error occurred running the {0} service:{1}{2}{3}", _thisServiceName, Environment.NewLine, Environment.NewLine, ExceptionUtils.GetDeepExceptionMessage(ex)); status.Status = CommonTransactionStatusCode.Failed; throw; } finally { if (status.Description != null) { AppendAuditLogEvent(status.Description); } if ((_notificationManager != null) && !string.IsNullOrEmpty(_notificationEmailAddresses)) { string subject; if (status.Status == CommonTransactionStatusCode.Completed) { subject = "Submitted SDWIS Document"; } else { subject = "Failed to Submit SDWIS Document"; } _notificationManager.DoScheduleNotifications(status, _notificationEmailAddresses, subject, _thisServiceName, null, null, status.Description); } } }
/// <summary> /// ProcessSubmit /// </summary> /// <param name="transactionId"></param> public void ProcessSubmit(string transactionId) { try { LazyInit(); WriteOut("Runtime arguments:"); foreach (string param in Enum.GetNames(typeof(SdwisRelayServiceParameterType))) { WriteOut("{0} = {1}; ", param, ConfigurationArguments[param]); } WriteOut("Getting documents:"); IList <Document> documents = _documentManager.GetDocuments(transactionId, true); List <string> documentPaths = new List <string>(); string tempDirPath = Path.Combine(_settingsProvider.TempFolderPath, Guid.NewGuid().ToString()); WriteOut("Creating temp. directory: " + tempDirPath); Directory.CreateDirectory(tempDirPath); foreach (Document doc in documents) { WriteOut("Parsing document: {0} ({1}); ", doc.DocumentName, doc.Type); string tempDocPath = Path.Combine(tempDirPath, doc.DocumentName); WriteOut("Saving content: " + tempDocPath); File.WriteAllBytes(tempDocPath, doc.Content); documentPaths.Add(tempDocPath); } WriteOut("Parsing argument values..."); string endpointUrl = GetConfigParameter(SdwisRelayServiceParameterType.SubmitEndpointUri.ToString()); WriteOut(" endpoint url: {0}", endpointUrl); if (!string.IsNullOrEmpty(endpointUrl)) { string submitAsUser = GetConfigParameter(SdwisRelayServiceParameterType.SubmitUsername.ToString()); WriteOut(" submit user: {0}", submitAsUser); string submitPassword = GetConfigParameter(SdwisRelayServiceParameterType.SubmitPassword.ToString()); WriteOut(" submit password: *********", submitPassword); string resultTranId = null; WriteOut("Creating endpoint client..."); INodeEndpointClient client = null; if (!String.IsNullOrEmpty(submitAsUser) && !String.IsNullOrEmpty(submitPassword)) { WriteOut("Using custom credentials"); client = _nodeEndpointClientFactory.Make(endpointUrl, EndpointVersionType.EN11, new AuthenticationCredentials(submitAsUser, submitPassword)); } else { WriteOut("Using default credentials"); client = _nodeEndpointClientFactory.Make(endpointUrl, EndpointVersionType.EN11); } WriteOut("Submitting documents..."); resultTranId = client.Submit(FLOW_NAME, null, documentPaths); if (string.IsNullOrEmpty(resultTranId)) { throw new ApplicationException("Node client did not return any transaction!"); } _transactionManager.SetTransactionStatus(transactionId, CommonTransactionStatusCode.Completed, WriteOut("Remote transaction Id: {1}", endpointUrl, resultTranId), true); _transactionManager.SetNetworkId(transactionId, resultTranId, EndpointVersionType.EN11, endpointUrl, FLOW_NAME, null); WriteOut("Submission done..."); } //********************************************* //HERE //********************************************* string hereEndpointUrl = GetConfigParameter(SdwisRelayServiceParameterType.HereEndpointUri.ToString()); WriteOut("Here endpoint url: {0}", hereEndpointUrl); if (!string.IsNullOrEmpty(hereEndpointUrl)) { WriteOut("Initializing HERE process..."); WriteOut("Validating submitted file name..."); if (documentPaths.Count == 1) { string submittedFileName = Path.GetFileName(documentPaths[0]); WriteOut("submittedFileName: {0}; ", submittedFileName); string hereFileNameFilter = ValidateNonEmptyConfigParameter(SdwisRelayServiceParameterType.HereFileNameFilter.ToString()); WriteOut("hereFileNameFilter: {0}; ", hereFileNameFilter); if (submittedFileName.IndexOf(hereFileNameFilter) > -1) { string hereIsFacilitySource = ValidateNonEmptyConfigParameter(SdwisRelayServiceParameterType.HereIsFacilitySource.ToString()); WriteOut("hereIsFacilitySource: {0}; ", hereIsFacilitySource); bool isFacilitySource = false; if (!bool.TryParse(hereIsFacilitySource, out isFacilitySource)) { throw new ApplicationException(string.Format( "Unable to parse the {0} argument. Must be a valid bool expression.", hereIsFacilitySource)); } string hereSourceSystemName = ValidateNonEmptyConfigParameter(SdwisRelayServiceParameterType.HereSourceSystemName.ToString()); WriteOut("hereSourceSystemName: {0}; ", hereSourceSystemName); WriteOut("creating Here data access object..."); HereDao hereDao = new HereDao(ValidateDBProvider(SdwisRelayServiceDataSourceType.HereDataSource.ToString())); WriteOut("hereDao: {0}; ", hereDao); WriteOut("saving submission in Here..."); hereDao.SetResultData(transactionId, hereEndpointUrl, FLOW_NAME, isFacilitySource, hereSourceSystemName, true); } else { WriteOut("Submitted file name: {0} does match the filter: {1}", submittedFileName, hereFileNameFilter); } } else { WriteOut("Found more than one submission... HERE requires only one file!"); } } else if (string.IsNullOrEmpty(endpointUrl)) { throw new ArgumentException(string.Format("Please specify either \"{0}\" or \"{1}\" configuration parameters", SdwisRelayServiceParameterType.SubmitEndpointUri.ToString(), SdwisRelayServiceParameterType.HereEndpointUri.ToString())); } } catch (Exception ex) { LOG.Error("Error while processing submission:", ex); throw new ApplicationException("Error while processing submission:", ex); } }