protected virtual void AttachSubmissionResponseToTransaction(string transactionId) { string tempXmlFilePath = _settingsProvider.NewTempFilePath(); string tempZipFilePath = _settingsProvider.NewTempFilePath(); try { Windsor.Node2008.WNOSPlugin.ICISAIR_54.SubmissionResponseDataType response = new Windsor.Node2008.WNOSPlugin.ICISAIR_54.SubmissionResponseDataType(); response.CreationDate = response.SubmissionDate = DateTime.Now; response.TransactionIdentifier = transactionId; _serializationHelper.Serialize(response, tempXmlFilePath); string zipDocumentName = string.Format("{0}_Response.xml", transactionId); string transactionDocumentName = Path.ChangeExtension(zipDocumentName, ".zip"); _compressionHelper.CompressFile(tempXmlFilePath, zipDocumentName, tempZipFilePath); var document = new Windsor.Node2008.WNOSDomain.Document(transactionDocumentName, CommonContentType.ZIP, File.ReadAllBytes(tempZipFilePath)); _documentManager.AddDocument(transactionId, CommonTransactionStatusCode.Completed, null, document); } catch (Exception e) { AppendAuditLogEvent("Failed to add response file to transaction \"{0}\" with error: {1}", transactionId, ExceptionUtils.GetDeepExceptionMessage(e)); throw; } finally { FileUtils.SafeDeleteFile(tempXmlFilePath); } }
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 override CERSDataType GetSubmitDocumentData(string transactionId, string docId) { AppendAuditLogEvent("Getting data for document with id \"{0}\"", docId); Windsor.Node2008.WNOSDomain.Document document = _documentManager.GetDocument(transactionId, docId, true); if (!document.IsZipFile) { throw new ArgumentException(string.Format("The submitted document \"{0}\" is not a zip file", document.DocumentName)); } int submitYear; string docName = Path.GetFileNameWithoutExtension(document.DocumentName); if (docName.Length < 10) { throw new ArgumentException(string.Format("The submitted document's name \"{0}\" is not valid", document.DocumentName)); } if (!int.TryParse(docName.Substring(docName.Length - 4, 4), out submitYear) || (submitYear > DateTime.Now.AddYears(1).Year) || (submitYear < 1900)) { throw new ArgumentException(string.Format("The submitted document's name \"{0}\" does not contain a valid year", document.DocumentName)); } int submitFIPSCode; if (!int.TryParse(docName.Substring(docName.Length - 10, 5), out submitFIPSCode)) { throw new ArgumentException(string.Format("The submitted document's name \"{0}\" does not contain a valid FIPS code", document.DocumentName)); } string submitFileName = submitFIPSCode.ToString("D5"); CERSDataType data = new CERSDataType(); data.DataCategory = DataCategory.OnroadNonroadActivity; data.EmissionsYear = submitYear.ToString(); data.UserIdentifier = _senderContactInfo; data.ProgramSystemCode = _programSystemCode; data.Location = new LocationDataType[1]; data.Location[0] = new LocationDataType(); data.Location[0].StateAndCountyFIPSCode = submitFileName; AppendAuditLogEvent("Submitted document contains data for FIPS code \"{0}\" and emissions year \"{1}\"", submitFileName, submitYear); submitFileName += ".zip"; string parentFolderPath = Path.Combine(_settingsProvider.TempFolderPath, transactionId); Directory.CreateDirectory(parentFolderPath); _attachmentFolderPath = parentFolderPath; string tempZipFilePath = Path.Combine(parentFolderPath, submitFileName); File.WriteAllBytes(tempZipFilePath, document.Content); data.AttachmentFileNames = new string[] { submitFileName }; return(data); }
protected virtual void DoEmailNotifications(Windsor.Node2008.WNOSDomain.Document zipResponseDocument, string localTransactionId) { if (!CollectionUtils.IsNullOrEmpty(_notificationEmails)) { string tempFilePath = null; try { string notificationEmails = StringUtils.Join(",", _notificationEmails); AppendAuditLogEvent("Sending email notifications to {0} ...", StringUtils.JoinCommaEnglish(_notificationEmails)); TransactionStatus transactionStatus = new TransactionStatus(); transactionStatus.Id = localTransactionId; transactionStatus.Status = CommonTransactionStatusCode.Completed; tempFilePath = _settingsProvider.NewTempFilePath(); File.WriteAllBytes(tempFilePath, zipResponseDocument.Content); string attachmentPath = tempFilePath; string attachmentName = zipResponseDocument.DocumentName; string subject = string.Format("ICIS-NPDES Submission Processing Report"); string message = string.Format("This email is to notify you that OpenNode2 has received and successfully processed submission results data from ICIS-NPDES.{0}{0}" + "The attached documents were returned from ICIS-NPDES in connection with the most recent submission.", Environment.NewLine); _notificationManager.DoScheduleNotifications(transactionStatus, notificationEmails, subject, _dataRequest.Service.Name, attachmentPath, attachmentName, message); AppendAuditLogEvent("Sent email notifications"); } catch (Exception ex) { AppendAuditLogEvent("Failed to send email notifications: {0}", ExceptionUtils.GetDeepExceptionMessage(ex)); } finally { FileUtils.SafeDeleteFile(tempFilePath); } } }
protected virtual bool DoProcessResponseDocuments(string localTransactionId, IList <string> documentNames, out Windsor.Node2008.WNOSDomain.Document zipResponseFile) { AppendAuditLogEvent("Attempting to process response documents for ICIS submission with transaction id \"{0}\"", _submissionTrackingDataType.SubmissionTransactionId); string responseZipFileName = FindResponseZipFileName(documentNames); AppendAuditLogEvent("Extracting response document content ..."); zipResponseFile = _documentManager.GetDocumentByName(localTransactionId, responseZipFileName, true); string tempFolder = _settingsProvider.CreateNewTempFolderPath(); _compressionHelper.UncompressDirectory(zipResponseFile.Content, tempFolder); string[] responseFiles = Directory.GetFiles(tempFolder); string responseAcceptedFilePath = FindResponseAcceptedFilePath(responseFiles); string responseRejectedFilePath = FindResponseRejectedFilePath(responseFiles); AppendAuditLogEvent("Loading response document content ..."); AppendAuditLogEvent("Transforming accepted response file ..."); string responseAcceptedTransformedFilePath = TransformResponseFile50(responseAcceptedFilePath); SubmissionResultList acceptedList = _serializationHelper.Deserialize <SubmissionResultList>(responseAcceptedTransformedFilePath); #if INCLUDE_TEST_SUBMIT_PROCESSOR if (DebugUtils.IsDebugging) { foreach (var submissionResultsDataType in acceptedList.SubmissionResult) { if (string.IsNullOrEmpty(submissionResultsDataType.SubmissionTransactionId)) { throw new ArgException("submissionResultsDataType.SubmissionTransactionId is null"); } } } #endif // INCLUDE_TEST_SUBMIT_PROCESSOR AppendAuditLogEvent("Transforming rejected response file ..."); string responseRejectedTransformedFilePath = TransformResponseFile50(responseRejectedFilePath); SubmissionResultList rejectedList = _serializationHelper.Deserialize <SubmissionResultList>(responseRejectedTransformedFilePath); #if INCLUDE_TEST_SUBMIT_PROCESSOR if (DebugUtils.IsDebugging) { foreach (var submissionResultsDataType in rejectedList.SubmissionResult) { if (string.IsNullOrEmpty(submissionResultsDataType.SubmissionTransactionId)) { throw new ArgException("submissionResultsDataType.SubmissionTransactionId is null"); } } } #endif // INCLUDE_TEST_SUBMIT_PROCESSOR List <SubmissionResultsDataType> saveList = new List <SubmissionResultsDataType>(CollectionUtils.Count(acceptedList.SubmissionResult) + CollectionUtils.Count(rejectedList.SubmissionResult)); DateTime now = DateTime.Now; CollectionUtils.ForEach(acceptedList.SubmissionResult, delegate(SubmissionResultsDataType result) { //DebugUtils.AssertDebuggerBreak(result.SubmissionTransactionId == _submissionTrackingDataType.SubmissionTransactionId); result.CreatedDateTime = now; saveList.Add(result); }); CollectionUtils.ForEach(rejectedList.SubmissionResult, delegate(SubmissionResultsDataType result) { //DebugUtils.AssertDebuggerBreak(result.SubmissionTransactionId == _submissionTrackingDataType.SubmissionTransactionId); result.CreatedDateTime = now; saveList.Add(result); }); _baseDao.TransactionTemplate.Execute(delegate(Spring.Transaction.ITransactionStatus status) { try { AppendAuditLogEvent("Saving response data to database ..."); Type mappingAttributesType = typeof(Windsor.Node2008.WNOSPlugin.ICISNPDES_50.MappingAttributes); Dictionary <string, int> tableRowCounts = _objectsToDatabase.SaveToDatabase(saveList, _baseDao, false, mappingAttributesType); AppendAuditLogEvent("Response data saved to database with the following insert row counts: {0}", CreateTableRowCountsString(tableRowCounts)); } catch (Exception ex1) { AppendAuditLogEvent("Failed to save response data to database, rolling back transaction: {0}", ExceptionUtils.GetDeepExceptionMessage(ex1)); throw; } ExecuteStoredProc(); return(null); }); return(true); }
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); } }
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 { 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); } }
protected virtual CERSDataType 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 EIS payload"); } string dataCategoryString = headerDocumentHelper.GetHeaderPropery(DATA_CATEGORY_HEADER_KEY); _headerDataCategory = EnumUtils.ParseEnum <DataCategory>(dataCategoryString); AppendAuditLogEvent("The Exchange Header contains a \"{0}\" property value of \"{1}\"", DATA_CATEGORY_HEADER_KEY, dataCategoryString ?? "None"); } 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 CERS data"); CERSDataType data = null; if (loadElement != null) { data = _serializationHelper.Deserialize <CERSDataType>(loadElement); } else { data = _serializationHelper.Deserialize <CERSDataType>(tempXmlFilePath); } data.DataCategory = this.DataCategory; AppendAuditLogEvent("Submitted document contains data for data category \"{0}\" and emissions year \"{1}\"", data.DataCategory, data.EmissionsYear); return(data); } finally { FileUtils.SafeDeleteFile(tempXmlFilePath); } }
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); } }