예제 #1
0
        protected virtual string InsertDocumentIntoDatabase(Type xmlDataType, NodeTransaction nodeTransaction, Document document)
        {
            if (_baseDao == null)
            {
                string noInsertMessage = "No data was inserted into the database since a data destination was not configured for the service";
                AppendAuditLogEvent(noInsertMessage);
                return(noInsertMessage);
            }
            AppendAuditLogEvent("Loading FACID content from transaction document \"{0}\" ...",
                                document.DocumentName);
            string operation;
            object xmlData = GetHeaderDocumentContent(xmlDataType, nodeTransaction.Id, document.Id, _settingsProvider,
                                                      _serializationHelper, _compressionHelper, _documentManager,
                                                      out operation);

            AppendAuditLogEvent("Inserting FACID content into database for document \"{0}\" ...",
                                document.DocumentName);

            try
            {
                if (_deleteExistingDataBeforeInsert)
                {
                    AppendAuditLogEvent("Deleting existing FACID data of type \"{0}\" from the data store ...", xmlDataType.Name);
                    int numRowsDeleted = _objectsToDatabase.DeleteAllFromDatabase(xmlDataType, _baseDao);

                    if (numRowsDeleted > 0)
                    {
                        AppendAuditLogEvent("Deleted {0} existing FACID data rows from the data store", numRowsDeleted.ToString());
                    }
                    else
                    {
                        AppendAuditLogEvent("Did not find any existing FACID data to delete from the data store");
                    }
                }
                Dictionary <string, int> tableRowCounts = _objectsToDatabase.SaveToDatabase(xmlData, _baseDao);
                string tableCountsString = string.Format("Successfully inserted FACID content into database for document \"{0}\" with table counts: {1}",
                                                         document.DocumentName, CreateTableRowCountsString(tableRowCounts));
                AppendAuditLogEvent(tableCountsString);

                return(tableCountsString);
            }
            catch (Exception ex)
            {
                AppendAuditLogEvent("Failed to insert FACID content into database for document \"{0}\" with exception: {1}",
                                    document.DocumentName, ExceptionUtils.GetDeepExceptionMessage(ex));
                throw;
            }
        }
예제 #2
0
        protected void ProcessSubmitDocument(string transactionId, string docId)
        {
            try
            {
                // Load the submission data from the xml file
                Organization data = GetSubmitDocumentData(transactionId, docId);

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

                _baseDao.TransactionTemplate.Execute(delegate
                {
                    if (_deleteBeforeInsert)
                    {
                        // Delete existing data from the database
                        numRowsDeleted = _objectsToDatabase.DeleteAllFromDatabase(data.GetType(), _baseDao, typeof(MappingAttributes));
                    }

                    // Insert data into the database
                    tableRowCounts = _objectsToDatabase.SaveToDatabase(data, _baseDao, typeof(MappingAttributes));

                    return(null);
                });

                if (numRowsDeleted > 0)
                {
                    AppendAuditLogEvent("Deleted {0} existing ATTAINS elements from the data store",
                                        numRowsDeleted.ToString());
                }
                else
                {
                    AppendAuditLogEvent("Did not delete any existing ATTAINS data from the data store");
                }
                var pk = _objectsToDatabase.GetPrimaryKeyValueForObject(data, typeof(MappingAttributes));
                AppendAuditLogEvent("Stored ATTAINS data content with primary key \"{0}\" into data store with the following table row counts: {1}",
                                    pk, CreateTableRowCountsString(tableRowCounts));
            }
            catch (Exception e)
            {
                AppendAuditLogEvent("Failed to process document with id \"{0}.\"  EXCEPTION: {1}",
                                    docId.ToString(), ExceptionUtils.ToShortString(e));
                throw;
            }
        }
예제 #3
0
        protected virtual CommonTransactionStatusCode ProcessSubmitDocument(string transactionId, string docId, out string statusDetail)
        {
            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 (_compressionHelper.IsCompressed(document.Content))
                {
                    AppendAuditLogEvent("Decompressing document to temporary file");
                    _compressionHelper.UncompressDeep(document.Content, tempXmlFilePath);
                }
                else
                {
                    AppendAuditLogEvent("Writing document data to temporary file");
                    File.WriteAllBytes(tempXmlFilePath, document.Content);
                }

                if (_validateXml)
                {
                    ValidateXmlFileAndAttachErrorsAndFileToTransaction(tempXmlFilePath, "xml_schema.xml_schema.zip",
                                                                       null, transactionId);
                }

                AppendAuditLogEvent("Deserializing document data to ICIS data");
                XmlReader reader = new NamespaceSpecifiedXmlTextReader("http://www.exchangenetwork.net/schema/icis/4", tempXmlFilePath);
                Windsor.Node2008.WNOSPlugin.ICISAIR_54.Document data =
                    _serializationHelper.Deserialize <Windsor.Node2008.WNOSPlugin.ICISAIR_54.Document>(reader);

                //Windsor.Node2008.WNOSPlugin.ICISAIR_54.Document data =
                //    _serializationHelper.Deserialize<Windsor.Node2008.WNOSPlugin.ICISAIR_54.Document>(tempXmlFilePath);

                if (CollectionUtils.IsNullOrEmpty(data.Payload))
                {
                    statusDetail = "Deserialized ICIS does not contain any payload elements, exiting processing thread.";
                    AppendAuditLogEvent(statusDetail);
                    return(CommonTransactionStatusCode.Completed);
                }
                AppendAuditLogEvent("ICIS data contains {0} payloads", data.Payload.Length.ToString());

                Type mappingAttributesType = typeof(Windsor.Node2008.WNOSPlugin.ICISAIR_54.MappingAttributes);

                _baseDao.TransactionTemplate.Execute(delegate
                {
                    if (_deleteExistingDataBeforeInsert)
                    {
                        AppendAuditLogEvent("Deleting all existing ICIS payload data from the data store");

                        int numRowsDeleted = _objectsToDatabase.DeleteAllFromDatabase(typeof(Windsor.Node2008.WNOSPlugin.ICISAIR_54.Payload),
                                                                                      _baseDao, mappingAttributesType);
                        if (numRowsDeleted > 0)
                        {
                            AppendAuditLogEvent("Deleted {0} existing ICIS payload data rows from the data store",
                                                numRowsDeleted.ToString());
                        }
                        else
                        {
                            AppendAuditLogEvent("Did not find any existing ICIS payload data to delete from the data store");
                        }
                    }

                    AppendAuditLogEvent("Storing ICIS payload data into database");

                    foreach (Windsor.Node2008.WNOSPlugin.ICISAIR_54.Payload payload in data.Payload)
                    {
                        Dictionary <string, int> tableRowCounts = _objectsToDatabase.SaveToDatabase(payload, _baseDao, mappingAttributesType);

                        AppendAuditLogEvent("Stored ICIS payload data for operation \"{0}\" into data store with the following table row counts: {1}",
                                            payload.Operation.ToString(), CreateTableRowCountsString(tableRowCounts));
                    }

                    return(null);
                });

                AttachSubmissionResponseToTransaction(transactionId);

                statusDetail = "Successfully processed the submitted ICIS document.";
                return(CommonTransactionStatusCode.Completed);
            }
            catch (Exception e)
            {
                AppendAuditLogEvent("Failed to process document with id \"{0}\" with error: {1}",
                                    docId.ToString(), ExceptionUtils.GetDeepExceptionMessage(e));
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
            }
        }