Example #1
0
        protected virtual Document GetRCRAXmlDocument(NodeTransaction nodeTransaction)
        {
            IList <Document> documents = _documentManager.GetDocuments(nodeTransaction.Id, false);
            Document         document  = null;

            CollectionUtils.ForEach(documents, delegate(Document checkDocument)
            {
                string extension = Path.GetExtension(checkDocument.DocumentName).ToUpper();
                if ((extension == ".ZIP") || (extension == ".XML"))
                {
                    document = checkDocument;
                }
            });
            return(document);
        }
Example #2
0
        /// <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);
                }
            }
        }
Example #3
0
        /// <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);
                }
            }
        }
        /// <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);
            }
        }