Esempio n. 1
0
        protected virtual string PerformSolicit()
        {
            string transactionId;

            AppendAuditLogEvent("Soliciting endpoint \"{0}\" at url \"{1}\" with flow name \"{2}\" and service name \"{3}\"",
                                _solicitPartner.Name, _solicitPartner.Url, NETWORK_RCRA_FLOW_NAME, _queryServiceName);

            try
            {
                using (INodeEndpointClient endpointClient =
                           _endpointUserManager.GetNodeEndpointClient(_solicitPartner.Url, _solicitPartner.Version, _solicitEndpointUsername))
                {
                    transactionId = endpointClient.Solicit(NETWORK_RCRA_FLOW_NAME, _queryServiceName, _queryParameters);
                }
                AppendAuditLogEvent("Successfully solicited the node endpoint \"{0}\" with returned transaction id \"{1}\"",
                                    _solicitPartner.Name, transactionId);
            }
            catch (Exception e)
            {
                AppendAuditLogEvent("Failed to solicit the node endpoint \"{0}\" with exception: {1}",
                                    _solicitPartner.Name, ExceptionUtils.GetDeepExceptionMessage(e));
                throw;
            }
            _endpointUserManager.SetNetworkEndpointTransactionInfo(_dataRequest.TransactionId, transactionId, _solicitPartner.Version,
                                                                   _solicitPartner.Url, NETWORK_RCRA_FLOW_NAME, _queryServiceName,
                                                                   _solicitEndpointUsername);
            return(transactionId);
        }
        /// <summary>
        /// Makes EN Client
        /// </summary>
        /// <returns></returns>
        private INodeEndpointClient MakeClient(string targetEndpointUrl, EndpointVersionType type, AuthenticationCredentials credentials,
                                               string naasUserToken, string tempDirectoryPath, IWebProxy proxy)
        {
            INodeEndpointClient client = null;

            if ((credentials != null) && (naasUserToken != null))
            {
                throw new ArgumentException("Must specify either credentials or naasUserToken, not both");
            }
            if (string.IsNullOrEmpty(tempDirectoryPath))
            {
                tempDirectoryPath = Path.GetTempPath();
            }

            // TSM: This is a fix to allow clients to work with older versions of OpenNode2 that have not been
            // upgraded to the node version 2.1 spec yet.
            bool compatibilityMode = false;

            if (type == EndpointVersionType.EN20CompatibilityMode)
            {
                compatibilityMode = true;
                type = EndpointVersionType.EN20;
            }

            switch (type)
            {
            case EndpointVersionType.EN11:
                if (credentials != null)
                {
                    client = new Client11(targetEndpointUrl, credentials, tempDirectoryPath, proxy);
                }
                else
                {
                    client = new Client11(targetEndpointUrl, naasUserToken, tempDirectoryPath, proxy);
                }
                break;

            case EndpointVersionType.EN20:
                if (credentials != null)
                {
                    client = new Client20(targetEndpointUrl, credentials, tempDirectoryPath, proxy, compatibilityMode);
                }
                else
                {
                    client = new Client20(targetEndpointUrl, naasUserToken, tempDirectoryPath, proxy, compatibilityMode);
                }
                break;

            default:
                throw new ArgumentException("Invalid endpoint type");
            }

            if (client != null)
            {
                // Set default timeout
                client.Timeout = DefaultTimeout;
            }

            return(client);
        }
Esempio n. 3
0
        protected virtual void UpdateStatusOfTransaction(NodeTransaction transaction, ITransactionManager transactionManager,
                                                         INodeEndpointClientFactory nodeEndpointClientFactory)
        {
            try
            {
                AppendAuditLogEvent("Attempting to update status of local transaction id \"{0}\" that has endpoint transaction id \"{1}\" and current endpoint transaction status of \"{2}\" at url \"{3}\" and endpoint version \"{4}\" ...",
                                    transaction.Id, transaction.NetworkId, transaction.NetworkEndpointStatus,
                                    transaction.NetworkEndpointUrl, transaction.NetworkEndpointVersion);

                CommonTransactionStatusCode statusCode;
                using (INodeEndpointClient endpointClient =
                           nodeEndpointClientFactory.Make(transaction.NetworkEndpointUrl, transaction.NetworkEndpointVersion))
                {
                    statusCode = endpointClient.GetStatus(transaction.NetworkId);
                    AppendAuditLogEvent("Successfully got an endpoint transaction status of \"{0}\"", statusCode.ToString());
                    if (statusCode != transaction.NetworkEndpointStatus)
                    {
                        if (OnTransactionStatusChanged(transaction, endpointClient, statusCode))
                        {
                            AppendAuditLogEvent("Updating status of local transaction id \"{0}\" from \"{1}\" to \"{2}\"",
                                                transaction.Id, transaction.NetworkEndpointStatus, statusCode);
                            transactionManager.SetNetworkIdStatus(transaction.Id, statusCode);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                AppendAuditLogEvent("Failed to get status of transaction: {0}", ExceptionUtils.GetDeepExceptionMessage(e));
            }
        }
        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);
        }
Esempio n. 5
0
        protected virtual void ProcessWebServiceSolicitSource(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));

            string networkTransactionId;
            EndpointVersionType endpointVersion;
            string endpointUrl;
            string networkFlowName = null, networkFlowOperation = scheduledItem.SourceRequest;

            using (INodeEndpointClient client = GetNodeClient(partner, activity, scheduledItem.SourceEndpointUser))
            {
                try
                {
                    if (client.Version == EndpointVersionType.EN11)
                    {
                        networkTransactionId = client.Solicit(null, scheduledItem.SourceRequest, scheduledItem.GetTranformedSourceArgs(),
                                                              new string[] { SettingsProvider.Endpoint11Url });
                    }
                    else
                    {
                        networkTransactionId = client.Solicit(scheduledItem.SourceFlow, scheduledItem.SourceRequest,
                                                              scheduledItem.GetTranformedSourceArgs(),
                                                              new string[] { SettingsProvider.Endpoint20Url });
                        networkFlowName = scheduledItem.SourceFlow;
                    }
                }
                catch (Exception e)
                {
                    LogActivityError(activity, "Error returned from node endpoint: \"{0}\"", ExceptionUtils.GetDeepExceptionMessage(e));
                    throw;
                }
                endpointVersion = client.Version;
                endpointUrl     = client.Url;
            }
            LogActivity(activity, "Performed Solicit of partner \"{0}\" at url \"{1}\" with returned transaction id \"{2}\"",
                        partner.Name, partner.Url, networkTransactionId);
            _transactionManager.SetNetworkIdAndEndpointUserId(transactionId, networkTransactionId, endpointVersion, endpointUrl,
                                                              networkFlowName, networkFlowOperation,
                                                              null, scheduledItem.SourceEndpointUser);
            //_transactionManager.SetNetworkId(transactionId, networkTransactionId, endpointVersion, endpointUrl,
            //                                 networkFlowName, networkFlowOperation);
        }
        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);
        }
        public INodeEndpointClient Make(string targetEndpointUrl, EndpointVersionType type, string username,
                                        string testPassword, string prodPassword)
        {
            ExceptionUtils.ThrowIfEmptyString(username);
            ExceptionUtils.ThrowIfEmptyString(testPassword);
            ExceptionUtils.ThrowIfEmptyString(prodPassword);

            INodeEndpointClient client = null;

            try
            {
                AuthenticationCredentials credentials = new AuthenticationCredentials(username, testPassword);
                client = Make(targetEndpointUrl, type, credentials);
                // First, check to ping the node to make sure it is up and running
                try
                {
                    client.NodePing();
                }
                catch (Exception pingEx)
                {
                    throw new ArgumentException(string.Format("The node endpoint \"{0}\" cannot be contacted.  NodePing returned the error: {1}",
                                                              targetEndpointUrl, ExceptionUtils.GetDeepExceptionMessage(pingEx)));
                }

                client.Authenticate();
            }
            catch (Exception)
            {
                DisposableBase.SafeDispose(ref client);
            }
            if (client == null)
            {
                try
                {
                    AuthenticationCredentials credentials = new AuthenticationCredentials(username, prodPassword);
                    client = Make(targetEndpointUrl, type, credentials);
                    client.Authenticate();
                }
                catch (Exception)
                {
                    DisposableBase.SafeDispose(ref client);
                }
            }
            if (client == null)
            {
                throw new ArgumentException(string.Format("The NAAS user \"{0}\" failed to authenticate against the node endpoint \"{1}\".  Please check that the NAAS user's username and password have been entered correctly.",
                                                          username, targetEndpointUrl));
            }
            return(client);
        }
Esempio n. 8
0
 public Exception CheckConnection(PartnerIdentity instance)
 {
     try
     {
         using (INodeEndpointClient client =
                    _nodeEndpointClientFactory.Make(instance.Url, instance.Version))
         {
             client.NodePing();
         }
         return(null);
     }
     catch (Exception e)
     {
         return(e);
     }
 }
Esempio n. 9
0
 public INodeEndpointClient GetNodeEndpointClient(string targetEndpointUrl, EndpointVersionType type, string endpointUsername)
 {
     if (!string.IsNullOrEmpty(endpointUsername))
     {
         string testPassword, prodPassword;
         if (!EndpointUserDao.GetEnpointUserPasswordsByUsername(endpointUsername, out testPassword, out prodPassword))
         {
             throw new ArgumentException(string.Format("The node endpoint user \"{0}\" could not be found.", endpointUsername));
         }
         INodeEndpointClient client = NodeEndpointClientFactory.Make(targetEndpointUrl, type, endpointUsername, testPassword, prodPassword);
         return(client);
     }
     else
     {
         return(NodeEndpointClientFactory.Make(targetEndpointUrl, type));
     }
 }
        /// <summary>
        /// Create a new <see cref="INodeEndpointClient"/> instance for accessing and communicating with a specific Exchange node.
        /// The input credentials are authenticated against the client node before this method returns.  This method will attempt
        /// to connect to BOTH v1.1 and v2.0 endpoints and return the first connection that succeeds.  Note that you
        /// can access INodeEndpointClient.Version to determine the version of the returned endpoint.
        /// </summary>
        /// <param name="targetEndpointUrl">The url for the Exchange node endpoint.</param>
        /// <param name="credentials">The credentials used to authenticate with the Exchange node endpoint.</param>
        /// <param name="tempDirectoryPath">A local directory path used for creating temporary files during INodeEndpointClient method
        /// execution.  This value can be null, in which case the dafault system temp directory will be used.</param>
        /// <param name="proxy">Proxy information for accessing the Exchange node endpoint.  This value can be null if
        /// no proxy is required.</param>
        /// <returns>A new <see cref="INodeEndpointClient"/> instance for accessing and communicating with a specific Exchange node.  Dispose()
        /// should be called on the returned instance when the caller is finished using the instance.</returns>
        public static INodeEndpointClient CreateClientAndAuthenticate(string targetEndpointUrl, AuthenticationCredentials credentials,
                                                                      string tempDirectoryPath, IWebProxy proxy)
        {
            INodeEndpointClient client = null;

            try
            {
                client = CreateClientAndAuthenticate(targetEndpointUrl, EndpointVersionType.EN11, credentials,
                                                     tempDirectoryPath, proxy);
            }
            catch (SoapException)
            {
                client = CreateClientAndAuthenticate(targetEndpointUrl, EndpointVersionType.EN20, credentials,
                                                     tempDirectoryPath, proxy);
            }
            return(client);
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        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>
        /// Create a new <see cref="INodeEndpointClient"/> instance for accessing and communicating with a specific Exchange node.
        /// The node is pinged after is it created to ensure it can be accessed.  This method will attempt
        /// to connect to BOTH v1.1 and v2.0 endpoints and return the first connection that succeeds.  Note that you
        /// can access INodeEndpointClient.Version to determine the version of the returned endpoint.
        /// </summary>
        /// <param name="targetEndpointUrl">The url for the Exchange node endpoint.</param>
        /// <param name="naasUserToken">A valid NAAS user token that will be used for validating this endpoint.</param>
        /// <param name="tempDirectoryPath">A local directory path used for creating temporary files during INodeEndpointClient method
        /// execution.  This value can be null, in which case the dafault system temp directory will be used.</param>
        /// <param name="proxy">Proxy information for accessing the Exchange node endpoint.  This value can be null if
        /// no proxy is required.</param>
        /// <returns>A new <see cref="INodeEndpointClient"/> instance for accessing and communicating with a specific Exchange node.  Dispose()
        /// should be called on the returned instance when the caller is finished using the instance.</returns>
        public static INodeEndpointClient CreateClientAndPing(string targetEndpointUrl, string naasUserToken,
                                                              string tempDirectoryPath, IWebProxy proxy)
        {
            INodeEndpointClient client = null;

            try
            {
                client = CreateClientAndPing(targetEndpointUrl, EndpointVersionType.EN11, naasUserToken,
                                             tempDirectoryPath, proxy);
            }
            catch (SoapException e)
            {
                if (string.Equals(e.Code.Name, "VersionMismatch", StringComparison.InvariantCultureIgnoreCase))
                {
                    client = CreateClientAndPing(targetEndpointUrl, EndpointVersionType.EN20, naasUserToken,
                                                 tempDirectoryPath, proxy);
                }
            }
            return(client);
        }
Esempio n. 14
0
        protected virtual INodeEndpointClient GetNodeClient(PartnerIdentity partner, Activity activity, string endpointUserId)
        {
            LogActivity(activity, "Attempting to acquire node endpoint client for partner \"{0}\" with version \"{1}\" at url \"{2}\"...",
                        partner.Name, EnumUtils.ToDescription(partner.Version), partner.Url);

            try
            {
                string naasUsername;
                INodeEndpointClient client =
                    EndpointUserManager.GetNodeEndpointClientForEndpointUserId(partner.Url, partner.Version, endpointUserId, out naasUsername);

                LogActivity(activity, "Acquired node endpoint client for partner \"{0}\" using NAAS user account \"{1}\"",
                            partner.Name, naasUsername);
                return(client);
            }
            catch (Exception ex)
            {
                LogActivity(activity, "Failed to acquire node endpoint client for partner \"{0}\" with exception: {1}",
                            partner.Name, ExceptionUtils.GetDeepExceptionMessage(ex));
                throw;
            }
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
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);
                }
            }
        }
Esempio n. 17
0
        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);
            }
        }
Esempio n. 18
0
 protected virtual bool OnTransactionStatusChanged(NodeTransaction transaction, INodeEndpointClient endpointClient,
                                                   CommonTransactionStatusCode newStatusCode)
 {
     return(true);
 }
Esempio n. 19
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);
            }
        }