protected string GetSubmissionResultsString(UICDataType data) { StringBuilder sb = new StringBuilder(); if (data == null) { sb.Append("Did not find any UIC submission data."); } else { sb.Append("Found the following UIC submission data: "); int i = 0; AppendCountString("Facilities", data.FacilityList, ++i == 1, sb); AppendCountString("Contacts", data.ContactDetail, ++i == 1, sb); AppendCountString("Permit Details", data.PermitDetail, ++i == 1, sb); AppendCountString("Geology Details", data.GeologyDetail, ++i == 1, sb); AppendCountString("Enforcements", data.EnforcementDetail, ++i == 1, sb); } return(sb.ToString()); }
protected string GenerateSubmissionFileAndAddToTransaction(UICDataType 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 GenerateSubmissionFile(UICDataType data) { AppendAuditLogEvent(GetSubmissionResultsString(data)); string tempZipFilePath = _settingsProvider.NewTempFilePath(".zip"); string tempXmlFilePath = _settingsProvider.NewTempFilePath(".xml"); try { //_serializationHelper.Serialize(data, tempXmlFilePath); _serializationHelper.SerializeWithLineBreaks(data, tempXmlFilePath); if (_validateXml) { ValidateXmlFileAndAttachErrorsAndFileToTransaction(tempXmlFilePath, "xml_schema.xml_schema.zip", null, _dataRequest.TransactionId); } if (_addHeader) { AppendAuditLogEvent("Generating submission file (with an exchange header) from results"); IHeaderDocumentHelper headerDocumentHelper; GetServiceImplementation(out headerDocumentHelper); // Configure the submission header helper string organization = data.OrgId; if (!string.IsNullOrEmpty(data.OrgName)) { organization += " - " + data.OrgName; } headerDocumentHelper.Configure(_headerAuthor, organization, UIC_FLOW_NAME, UIC_FLOW_NAME, _headerContactInfo, null); string tempXmlFilePath2 = _settingsProvider.NewTempFilePath(".xml"); try { XmlDocument doc = new XmlDocument(); doc.Load(tempXmlFilePath); headerDocumentHelper.AddPayload(EnumUtils.ToDescription(Submission_Type.DeleteInsert), doc.DocumentElement); headerDocumentHelper.SerializeWithLineBreaks(tempXmlFilePath2); _compressionHelper.CompressFile(tempXmlFilePath2, tempZipFilePath); } finally { FileUtils.SafeDeleteFile(tempXmlFilePath2); } } else { AppendAuditLogEvent("Generating submission file (without an exchange header) from results"); _compressionHelper.CompressFile(tempXmlFilePath, tempZipFilePath); } } catch (Exception) { FileUtils.SafeDeleteFile(tempZipFilePath); throw; } finally { FileUtils.SafeDeleteFile(tempXmlFilePath); } return(tempZipFilePath); }
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); } }