Example #1
0
        protected virtual Organization 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);

                // Deserialize the xml file whether or not it has an exchange header
                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 ATTAINS 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 ATTAINS data");
                Organization data = null;
                if (loadElement != null)
                {
                    data = _serializationHelper.Deserialize <Organization>(loadElement);
                }
                else
                {
                    data = _serializationHelper.Deserialize <Organization>(tempXmlFilePath);
                }

                return(data);
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
            }
        }
Example #2
0
        public DocumentLiteModel LoadByNumber(string documentNumber)
        {
            var document = _documentManager.GetDocument(documentNumber);

            return(new DocumentLiteModel(document,
                                         string.Format($"{document.File.FileName}{document.File.FileExtension.ExtensionName}"),
                                         document.OwnerUser, document.ResponsibleUser, document.DocumentTags.Select(dt => dt.Tag)));
        }
        public Document GetDocument()
        {
            Document document;

            lock (this)
            {
                document = _documentManager.GetDocument();
            }
            return(document);
        }
Example #4
0
 protected void Run()
 {
     while (true)
     {
         if (_documentManager.IsDocumentAvailable)
         {
             Document document = _documentManager.GetDocument();
             Console.WriteLine("Processing document {0}", document.Title);
         }
         Thread.Yield();
     }
     // ReSharper disable once FunctionNeverReturns
 }
Example #5
0
 protected void ProcessSubmitDocument(string transactionId, string docId)
 {
     try
     {
         IHeaderDocumentHelper headerDocumentHelper;
         GetServiceImplementation(out headerDocumentHelper);
         AppendAuditLogEvent("Getting data for document with id \"{0}\"", docId);
         Document document = _documentManager.GetDocument(transactionId, docId, true);
         if (document.IsZipFile)
         {
             AppendAuditLogEvent("Decompressing document to temporary file");
             _compressionHelper.UncompressDeep(document.Content, _dataDestinationPath + document.DocumentName + ".xml");
         }
         else
         {
             AppendAuditLogEvent("Writing document data to temporary file");
             File.WriteAllBytes(_dataDestinationPath + document.DocumentName + ".xml", document.Content);
         }
     }
     catch (Exception e)
     {
         AppendAuditLogEvent("Failed to process document with id \"{0}.\"  EXCEPTION: {1}", docId.ToString(), ExceptionUtils.ToShortString(e)); throw;
     }
 }
Example #6
0
        public void ProcessSubmit(string transactionId)
        {
            LOG.Info("NCT.ProcessSubmit()");
            AppendAuditLogEvent("NCT ProcessSubmit() enter");

            LazyInit();

            IList <string> dbDocIds = _transactionManager.GetAllUnprocessedDocumentDbIds(transactionId);

            if (!CollectionUtils.IsNullOrEmpty(dbDocIds))
            {
                foreach (string dbDocId in dbDocIds)
                {
                    Document document = _documentManager.GetDocument(transactionId, dbDocId, true);
                    _documentManager.SetDocumentStatus(transactionId, dbDocId, CommonTransactionStatusCode.Processed,
                                                       "Processed " + dbDocId);
                    string statusDetail;
                    CommonTransactionStatusCode status = _documentManager.GetDocumentStatus(transactionId, dbDocId,
                                                                                            out statusDetail);
                }
            }
            AddReportDocumentToTransaction(transactionId, true);
            AppendAuditLogEvent("NCT ProcessSubmit() exit");
        }
Example #7
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);
            }
        }
Example #8
0
        protected void ProcessSubmitDocument(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);
                }

                AppendAuditLogEvent("Deserializing document data to BEACHES data");
                Windsor.Node2008.WNOSPlugin.BEACHES_24.BeachDataSubmissionDataType data =
                    _serializationHelper.Deserialize <Windsor.Node2008.WNOSPlugin.BEACHES_24.BeachDataSubmissionDataType>(tempXmlFilePath);
                data.BeforeSaveToDatabase();

                AppendAuditLogEvent("Storing BEACHES data into database");

                AppendAuditLogEvent("BEACHES data contains {0} Organization Details, {0} Beach Details, and {0} Beach Procedure Details",
                                    CollectionUtils.Count(data.OrganizationDetail).ToString(),
                                    CollectionUtils.Count(data.BeachDetail).ToString(),
                                    CollectionUtils.Count(data.BeachProcedureDetail).ToString());

                AppendAuditLogEvent("Deleting existing BEACHES data from the data store ...");

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

                _baseDao.TransactionTemplate.Execute(delegate
                {
                    _baseDao.AdoTemplate.ExecuteNonQuery(CommandType.Text, "DELETE FROM NOTIF_YEARCOMPLETION");
                    _baseDao.AdoTemplate.ExecuteNonQuery(CommandType.Text, "DELETE FROM NOTIF_PROCEDURE");
                    _baseDao.AdoTemplate.ExecuteNonQuery(CommandType.Text, "DELETE FROM NOTIF_BEACH");
                    _baseDao.AdoTemplate.ExecuteNonQuery(CommandType.Text, "DELETE FROM NOTIF_ORGANIZATION");

                    CollectionUtils.ForEach(data.OrganizationDetail, delegate(Windsor.Node2008.WNOSPlugin.BEACHES_24.OrganizationDetailDataType organizationDetailDataType)
                    {
                        Dictionary <string, int> tableRowCountsTemp = _objectsToDatabase.SaveToDatabase(organizationDetailDataType, _baseDao);
                        tableRowCounts = AddTableRowCounts(tableRowCountsTemp, tableRowCounts);
                    });
                    CollectionUtils.ForEach(data.BeachDetail, delegate(Windsor.Node2008.WNOSPlugin.BEACHES_24.BeachDetailDataType beachDetail)
                    {
                        Dictionary <string, int> tableRowCountsTemp = _objectsToDatabase.SaveToDatabase(beachDetail, _baseDao);
                        tableRowCounts = AddTableRowCounts(tableRowCountsTemp, tableRowCounts);
                    });
                    CollectionUtils.ForEach(data.BeachProcedureDetail, delegate(Windsor.Node2008.WNOSPlugin.BEACHES_24.BeachProcedureDetailDataType beachProcedureDetail)
                    {
                        Dictionary <string, int> tableRowCountsTemp = _objectsToDatabase.SaveToDatabase(beachProcedureDetail, _baseDao);
                        tableRowCounts = AddTableRowCounts(tableRowCountsTemp, tableRowCounts);
                    });
                    if (data.YearCompletionIndicators != null)
                    {
                        Dictionary <string, int> tableRowCountsTemp = _objectsToDatabase.SaveToDatabase(data.YearCompletionIndicators, _baseDao);
                        tableRowCounts = AddTableRowCounts(tableRowCountsTemp, tableRowCounts);
                    }

                    return(null);
                });

                if (numRowsDeleted > 0)
                {
                    AppendAuditLogEvent("Deleted {0} existing BEACHES data rows from the data store",
                                        numRowsDeleted.ToString());
                }
                else
                {
                    AppendAuditLogEvent("Did not find any existing BEACHES data to delete from the data store");
                }
                AppendAuditLogEvent("Stored BEACHES data content into the data store with the following table row counts: {0}",
                                    CreateTableRowCountsString(tableRowCounts));
            }
            catch (Exception e)
            {
                AppendAuditLogEvent("Failed to process document with id \"{0}.\"  EXCEPTION: {1}",
                                    docId.ToString(), ExceptionUtils.ToShortString(e));
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
            }
        }
        protected void ProcessSubmitDocument(string transactionId, string docId)
        {
            string tempXmlFilePath = _settingsProvider.NewTempFilePath();

            try
            {
                IHeaderDocumentHelper headerDocumentHelper;
                GetServiceImplementation(out headerDocumentHelper);

                AppendAuditLogEvent("Getting data for document with id \"{0}\"", docId);
                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);
                }

                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 a 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 TRI data");
                XmlReader reader;

                if (loadElement != null)
                {
                    reader = new NamespaceSpecifiedXmlNodeReader(TRI_XML_NAMESPACE, loadElement);
                }
                else
                {
                    reader = new NamespaceSpecifiedXmlTextReader(TRI_XML_NAMESPACE, tempXmlFilePath);
                }
                TRIDataType data = _serializationHelper.Deserialize <TRIDataType>(reader);

                AppendAuditLogEvent("Setting TRI transaction id to \"{0}\"", transactionId);
                data.TransactionID = transactionId;

                try
                {
                    AppendAuditLogEvent("Storing TRI data into database");

                    TRIData triDataLoader = new TRIData();
                    triDataLoader.Load(data, _baseDao, _deleteExistingDataBeforeInsert);

                    AppendAuditLogEvent("Stored TRI data into database");
                }
                catch (Exception ex)
                {
                    AppendAuditLogEvent("Failed to store TRI data into database: {0}",
                                        ExceptionUtils.GetDeepExceptionMessage(ex));
                    throw;
                }

                if (!string.IsNullOrEmpty(_postProcessingStoredProcName))
                {
                    try
                    {
                        AppendAuditLogEvent("Calling TRI post processing stored proc: \"{0}\"", _postProcessingStoredProcName);

                        _baseDao.DoStoredProc(_postProcessingStoredProcName);

                        AppendAuditLogEvent("Successfully called TRI post processing stored proc");
                    }
                    catch (Exception ex)
                    {
                        AppendAuditLogEvent("Failed to call TRI post processing stored proc: {0}",
                                            ExceptionUtils.GetDeepExceptionMessage(ex));
                        throw;
                    }
                }
            }
            catch (Exception e)
            {
                AppendAuditLogEvent("Failed to process document with id \"{0}.\"  EXCEPTION: {1}",
                                    docId.ToString(), ExceptionUtils.ToShortString(e));
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
            }
        }
Example #10
0
        protected virtual WQXDataType GetWQXData(string transactionId, string docId,
                                                 out Windsor.Node2008.WNOSPlugin.WQX1XsdOrm.WQXDataType data1,
                                                 out WQXDeleteDataType deleteData, out string attachmentsFolderPath)
        {
            WQXDataType data = null;

            data1      = null;
            deleteData = null;
            string tempXmlFilePath = _settingsProvider.NewTempFilePath();

            attachmentsFolderPath = null;
            string tempFolder = null;

            try
            {
                IHeaderDocumentHelper headerDocumentHelper;
                GetServiceImplementation(out headerDocumentHelper);

                AppendAuditLogEvent("Getting data for document with id \"{0}\"", docId);
                Document document = _documentManager.GetDocument(transactionId, docId, true);
                if (document.IsZipFile)
                {
                    tempFolder = _settingsProvider.CreateNewTempFolderPath();
                    AppendAuditLogEvent("Decompressing document to temporary folder");
                    _compressionHelper.UncompressDirectory(document.Content, tempFolder);
                    string[] xmlFiles = Directory.GetFiles(tempFolder, "*.xml");
                    if (xmlFiles.Length == 0)
                    {
                        throw new ArgException("Failed to locate a WQX xml file in the WQX data");
                    }
                    else if (xmlFiles.Length > 1)
                    {
                        throw new ArgException("More than one xml file was found in the WQX data");
                    }
                    tempXmlFilePath = xmlFiles[0];
                }
                else
                {
                    AppendAuditLogEvent("Writing document data to temporary file");
                    File.WriteAllBytes(tempXmlFilePath, document.Content);
                }

                XmlElement loadElement = null;
                try
                {
                    AppendAuditLogEvent("Attempting to load document with Exchange Header");
                    headerDocumentHelper.Load(tempXmlFilePath);
                    loadElement = headerDocumentHelper.GetPayload("Update-Insert");
                    if (loadElement == null)
                    {
                        loadElement = headerDocumentHelper.GetPayload("Delete");
                        if (loadElement == null)
                        {
                            throw new ArgumentException("The submitted document does not contain an \"Update-Insert\" or \"Delete\" 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 WQX data");
                if (loadElement != null)
                {
                    try
                    {
                        data = _serializationHelper.Deserialize <WQXDataType>(loadElement);
                        attachmentsFolderPath = tempFolder;
                    }
                    catch (Exception)
                    {
                        AppendAuditLogEvent("Failed to deserialize WQX v2, trying WQX v1 ...");
                        try
                        {
                            data1 = _serializationHelper.Deserialize <Windsor.Node2008.WNOSPlugin.WQX1XsdOrm.WQXDataType>(loadElement);
                        }
                        catch (Exception)
                        {
                            AppendAuditLogEvent("Failed to deserialize WQX v1, trying WQX v2 Delete data ...");
                            deleteData = _serializationHelper.Deserialize <WQXDeleteDataType>(loadElement);
                        }
                    }
                }
                else
                {
                    try
                    {
                        data = _serializationHelper.Deserialize <WQXDataType>(tempXmlFilePath);
                        attachmentsFolderPath = tempFolder;
                    }
                    catch (Exception)
                    {
                        AppendAuditLogEvent("Failed to deserialize WQX v2, trying WQX v1 ...");
                        try
                        {
                            data1 = _serializationHelper.Deserialize <Windsor.Node2008.WNOSPlugin.WQX1XsdOrm.WQXDataType>(tempXmlFilePath);
                        }
                        catch (Exception)
                        {
                            AppendAuditLogEvent("Failed to deserialize WQX v1, trying WQX v2 Delete data ...");
                            deleteData = _serializationHelper.Deserialize <WQXDeleteDataType>(tempXmlFilePath);
                        }
                    }
                }
            }
            catch (Exception)
            {
                FileUtils.SafeDeleteAllFilesAndFoldersInFolder(tempFolder);
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
            }
            return(data);
        }
        protected void ProcessSubmitDocument(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);
                }

                IHeaderDocumentHelper headerDocumentHelper;
                GetServiceImplementation(out headerDocumentHelper);

                XmlElement loadElement    = null;
                Type       submissionType = 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 a payload");
                    }
                    submissionType = GetSubmissionDataTypeFromHeaderOperation(operation);
                }
                catch (Exception)
                {
                    AppendAuditLogEvent("Document does not contain an Exchange Header");
                    // Assume, for now, that document does not have a header
                }

                if (typeof(T) == typeof(object))
                {
                    if (submissionType == null)
                    {
                        throw new ArgumentException("The RCRA submission data type cannot be determined from the Exchange Header");
                    }
                }
                else if (submissionType != null)
                {
                    if (submissionType != typeof(T))
                    {
                        throw new ArgumentException(string.Format("The RCRA submission data type ({0}) does not match the expected data type ({1})",
                                                                  submissionType.Name, typeof(T).Name));
                    }
                }
                AppendAuditLogEvent("Deserializing document data to RCRA data");
                T data = null;
                if (loadElement != null)
                {
                    if ((typeof(T) == typeof(object)))
                    {
                        data = (T)_serializationHelper.Deserialize(loadElement, submissionType);
                    }
                    else
                    {
                        data = _serializationHelper.Deserialize <T>(loadElement);
                    }
                }
                else
                {
                    data = _serializationHelper.Deserialize <T>(tempXmlFilePath);
                }

                AppendAuditLogEvent("Submitted document is of type {0}", data.GetType().Name);

                Dictionary <string, int> tableRowCounts = null;

                string deleteMessage = null;
                _baseDao.TransactionTemplate.Execute(delegate
                {
                    if (_deleteExistingDataBeforeInsert)
                    {
                        deleteMessage = DeleteBeforeInsert(data);
                    }

                    tableRowCounts = Insert(data);

                    return(null);
                });

                if (!string.IsNullOrEmpty(deleteMessage))
                {
                    AppendAuditLogEvent(deleteMessage);
                }
                AppendAuditLogEvent("Inserted RCRA content into the data store with the following table row counts: {0}",
                                    CreateTableRowCountsString(tableRowCounts));
            }
            catch (Exception e)
            {
                AppendAuditLogEvent("Failed to process document with id \"{0}.\"  EXCEPTION: {1}",
                                    docId.ToString(), ExceptionUtils.ToShortString(e));
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
            }
        }
Example #12
0
        protected void ProcessSubmitDocument(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);
                }

                IHeaderDocumentHelper 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 a payload");
                    }
                }
                catch (Exception ex)
                {
                    throw new ArgumentException("Document does not contain an Exchange Header", ex);
                }
                if (string.IsNullOrEmpty(headerDocumentHelper.Organization))
                {
                    throw new ArgumentException("Document does not contain an Organization element in the Exchange Header");
                }
                if (headerDocumentHelper.Organization.Length < 4)
                {
                    throw new ArgumentException("Document does not contain an valid Organization element in the Exchange Header");
                }
                string orgId = headerDocumentHelper.Organization.Substring(0, 4);
                AppendAuditLogEvent("Submitted document contains data for data organization \"{0}\"",
                                    orgId);

                AppendAuditLogEvent("Deserializing document data to UIC data");
                UICDataType data = null;
                if (loadElement != null)
                {
                    data = _serializationHelper.Deserialize <UICDataType>(loadElement);
                }
                else
                {
                    data = _serializationHelper.Deserialize <UICDataType>(tempXmlFilePath);
                }
                data.OrgId = orgId;

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

                _baseDao.TransactionTemplate.Execute(delegate
                {
                    if (_deleteExistingDataBeforeInsert)
                    {
                        AppendAuditLogEvent("Deleting existing UIC data from the data store for organization \"{0}\" ...", data.OrgId);
                        numRowsDeleted = _baseDao.DoSimpleDelete("UIC_ORG", "ORG_ID", data.OrgId);
                    }

                    tableRowCounts = _objectsToDatabase.SaveToDatabase(data, _baseDao);

                    return(null);
                });

                if (_deleteExistingDataBeforeInsert)
                {
                    if (numRowsDeleted > 0)
                    {
                        AppendAuditLogEvent("Deleted {0} existing WQX data rows from the data store for organization \"{1}\"",
                                            numRowsDeleted.ToString(), data.OrgId);
                    }
                    else
                    {
                        AppendAuditLogEvent("Did not find any existing UIC data to delete from the data store for data organization \"{0}\"",
                                            data.OrgId);
                    }
                }
                AppendAuditLogEvent("Stored UIC data content with data organization \"{0}\" into data store with the following table row counts: {1}",
                                    data.OrgId, CreateTableRowCountsString(tableRowCounts));
            }
            catch (Exception e)
            {
                AppendAuditLogEvent("Failed to process document with id \"{0}.\"  EXCEPTION: {1}",
                                    docId.ToString(), ExceptionUtils.ToShortString(e));
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
            }
        }