Exemplo n.º 1
0
        protected virtual EMTSDataType GetSubmitDocumentData(string transactionId, string docId)
        {
            string tempXmlFilePath = _settingsProvider.NewTempFilePath();

            try
            {
                AppendAuditLogEvent("Getting data for document with id \"{0}\"", docId);
                Windsor.Node2008.WNOSDomain.Document document = _documentManager.GetDocument(transactionId, docId, true);
                if (document.IsZipFile)
                {
                    AppendAuditLogEvent("Decompressing document to temporary file");
                    _compressionHelper.UncompressDeep(document.Content, tempXmlFilePath);
                }
                else
                {
                    AppendAuditLogEvent("Writing document data to temporary file");
                    File.WriteAllBytes(tempXmlFilePath, document.Content);
                }

                IHeaderDocument2Helper headerDocumentHelper;
                GetServiceImplementation(out headerDocumentHelper);

                XmlElement loadElement = null;
                try
                {
                    AppendAuditLogEvent("Attempting to load document with Exchange Header");
                    headerDocumentHelper.Load(tempXmlFilePath);
                    string operation;
                    loadElement = headerDocumentHelper.GetFirstPayload(out operation);
                    if (loadElement == null)
                    {
                        throw new ArgumentException("The submitted document does not contain an EMTS payload");
                    }
                }
                catch (Exception)
                {
                    AppendAuditLogEvent("Document does not contain an Exchange Header");
                    // Assume, for now, that document does not have a header
                }

                AppendAuditLogEvent("Deserializing document data to EMTS data");
                EMTSDataType data = null;
                if (loadElement != null)
                {
                    data = _serializationHelper.Deserialize <EMTSDataType>(loadElement);
                }
                else
                {
                    data = _serializationHelper.Deserialize <EMTSDataType>(tempXmlFilePath);
                }

                return(data);
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
            }
        }
        protected string GetSubmissionResultsString(EMTSDataType data)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("Found the following EMTS submission data: ");
            int i = 0;

            AppendCountString("Generate Transaction Details", data.GenerateTransactionDetail, ++i == 1, sb);
            AppendCountString("Separate Transaction Details", data.SeparateTransactionDetail, ++i == 1, sb);
            AppendCountString("Sell Transaction Details", data.SellTransactionDetail, ++i == 1, sb);
            AppendCountString("Buy Transaction Details", data.BuyTransactionDetail, ++i == 1, sb);
            AppendCountString("Retire Transaction Details", data.RetireTransactionDetail, ++i == 1, sb);
            return(sb.ToString());
        }
        protected string GenerateSubmissionFile(EMTSDataType data)
        {
            string tempZipFilePath = _settingsProvider.NewTempFilePath(".zip");
            string tempXmlFilePath = _settingsProvider.NewTempFilePath(".xml");

            try
            {
                _serializationHelper.Serialize(data, tempXmlFilePath);

                AppendAuditLogEvent("Generating submission file (with an exchange header) from results");

                IHeaderDocument2Helper headerDocumentHelper;
                GetServiceImplementation(out headerDocumentHelper);
                // Configure the submission header helper
                headerDocumentHelper.Configure(_authorName, _settingsProvider.NodeOrganizationName, EMTS_FLOW_NAME,
                                               EMTS_FLOW_NAME, string.Empty, string.Empty, null);

                string tempXmlFilePath2 = _settingsProvider.NewTempFilePath(".xml");
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(tempXmlFilePath);

                    headerDocumentHelper.AddPayload(string.Empty, doc.DocumentElement);

                    headerDocumentHelper.Serialize(tempXmlFilePath2);

                    _compressionHelper.CompressFile(tempXmlFilePath2, tempZipFilePath);
                }
                finally
                {
                    FileUtils.SafeDeleteFile(tempXmlFilePath2);
                }
            }
            catch (Exception)
            {
                FileUtils.SafeDeleteFile(tempZipFilePath);
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
            }
            return(tempZipFilePath);
        }
Exemplo n.º 4
0
        protected void ProcessSubmitDocument(string transactionId, string docId)
        {
            try
            {
                EMTSDataType data = GetSubmitDocumentData(transactionId, docId);

                int numRowsDeleted = 0;
                Dictionary <string, int> tableRowCounts = null;

                _baseDao.TransactionTemplate.Execute(delegate
                {
                    if (_deleteBeforeInsert)
                    {
                        string parentTableName = _objectsToDatabase.GetTableNameForType(typeof(EMTSDataType));
                        numRowsDeleted         = _baseDao.DoSimpleDelete(parentTableName, null, null);
                    }

                    tableRowCounts = _objectsToDatabase.SaveToDatabase(data, _baseDao);

                    return(null);
                });

                if (numRowsDeleted > 0)
                {
                    AppendAuditLogEvent("Deleted {0} existing EMTS elements from the data store",
                                        numRowsDeleted.ToString());
                }
                else
                {
                    AppendAuditLogEvent("Did not delete any existing EMTS data from the data store");
                }
                AppendAuditLogEvent("Stored EMTS data content with primary key \"{0}\" into data store with the following table row counts: {1}",
                                    data._PK, CreateTableRowCountsString(tableRowCounts));
            }
            catch (Exception e)
            {
                AppendAuditLogEvent("Failed to process document with id \"{0}.\"  EXCEPTION: {1}",
                                    docId.ToString(), ExceptionUtils.ToShortString(e));
                throw;
            }
        }
        protected string GenerateSubmissionFileAndAddToTransaction(EMTSDataType data)
        {
            string submitFile = GenerateSubmissionFile(data);

            try
            {
                AppendAuditLogEvent("Attaching submission document to transaction \"{0}\"",
                                    _dataRequest.TransactionId);
                _documentManager.AddDocument(_dataRequest.TransactionId,
                                             CommonTransactionStatusCode.Completed,
                                             null, submitFile);
            }
            catch (Exception e)
            {
                AppendAuditLogEvent("Failed to attach submission document \"{0}\" to transaction \"{1}\" with exception: {2}",
                                    submitFile, _dataRequest.TransactionId, ExceptionUtils.ToShortString(e));
                FileUtils.SafeDeleteFile(submitFile);
                throw;
            }
            return(submitFile);
        }
        protected string GenerateSubmissionFileAndAddToTransaction()
        {
            Dictionary <string, DbAppendSelectWhereClause> selectClauses = new Dictionary <string, DbAppendSelectWhereClause>();

            selectClauses.Add("EMTS_EMTS",
                              new DbAppendSelectWhereClause(_baseDao, "ORG_IDEN = ?", _organizationIdentifier));

            List <EMTSDataType> dataList = _objectsFromDatabase.LoadFromDatabase <EMTSDataType>(_baseDao, selectClauses);

            if (CollectionUtils.IsNullOrEmpty(dataList))
            {
                throw new ArgumentException(string.Format("No EMTS data was found to submit for organization \"{0}\"", _organizationIdentifier));
            }
            else if (dataList.Count > 1)
            {
                throw new ArgumentException(string.Format("More than one set of EMTS data was found for organization \"{0}\"", _organizationIdentifier));
            }
            else
            {
                EMTSDataType data = dataList[0];
                AppendAuditLogEvent(GetSubmissionResultsString(data));
                return(GenerateSubmissionFileAndAddToTransaction(data));
            }
        }