private static IList <string> GetImportFiles(string importZipFile, string importCSVFileSearchPattern, string tempFolderPath, ICompressionHelper compressionHelper) { if (string.IsNullOrEmpty(tempFolderPath)) { tempFolderPath = Path.GetTempPath(); } if (!Directory.Exists(tempFolderPath)) { throw new DirectoryNotFoundException(string.Format("The node temporary folder does not exist: {0}", tempFolderPath)); } string outputPath = Path.Combine(tempFolderPath, Guid.NewGuid().ToString()); Directory.CreateDirectory(outputPath); try { compressionHelper.UncompressDirectory(importZipFile, outputPath); string[] fileList = Directory.GetFiles(outputPath, importCSVFileSearchPattern); if (CollectionUtils.IsNullOrEmpty(fileList)) { throw new FileNotFoundException(string.Format("No valid CSV import files were included in the input zip file \"{0}\"", importZipFile)); } return(fileList); } catch (Exception) { FileUtils.SafeDeleteDirectory(outputPath); throw; } }
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 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); }
public static WQXDataType GenerateWqxObjectsFromSubmissionFile(IAppendAuditLogEvent appendAuditLogEvent, string submissionFilePath, string sysTempFolderPath, Assembly xmlSchemaZippedResourceAssembly, string xmlSchemaZippedQualifiedResourceName, string xmlSchemaRootFileName, ISerializationHelper serializationHelper, ICompressionHelper compressionHelper, out string attachmentsFolderPath, out string validationErrorsFile) { WQXDataType data = null; attachmentsFolderPath = null; string wqxFilePath = null; validationErrorsFile = null; try { attachmentsFolderPath = Path.Combine(sysTempFolderPath, Guid.NewGuid().ToString()); Directory.CreateDirectory(attachmentsFolderPath); appendAuditLogEvent.AppendAuditLogEvent("Decompressing the WQX data to a temporary folder ..."); try { compressionHelper.UncompressDirectory(submissionFilePath, attachmentsFolderPath); } catch (Exception ex) { throw new ArgException("An error occurred decompressing the WQX data: {0}", ExceptionUtils.GetDeepExceptionMessage(ex)); } string[] xmlFiles = Directory.GetFiles(attachmentsFolderPath, "*.xml"); if (xmlFiles.Length == 0) { throw new ArgException("Failed to locate an 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"); } wqxFilePath = xmlFiles[0]; if (!string.IsNullOrEmpty(xmlSchemaZippedQualifiedResourceName)) { validationErrorsFile = BaseWNOSPlugin.ValidateXmlFile(wqxFilePath, xmlSchemaZippedResourceAssembly, xmlSchemaZippedQualifiedResourceName, xmlSchemaRootFileName, sysTempFolderPath, appendAuditLogEvent, compressionHelper); if (validationErrorsFile != null) { FileUtils.SafeDeleteDirectory(attachmentsFolderPath); return(null); } } //Remove header wqxFilePath = RemoveHeaderFile(wqxFilePath, sysTempFolderPath, serializationHelper); appendAuditLogEvent.AppendAuditLogEvent("Deserializing the WQX data xml file ..."); try { data = serializationHelper.Deserialize <WQXDataType>(wqxFilePath); } catch (Exception ex) { appendAuditLogEvent.AppendAuditLogEvent("Failed to deserialize the WQX data xml file: {0}", ExceptionUtils.GetDeepExceptionMessage(ex)); throw; } if (data == null) { appendAuditLogEvent.AppendAuditLogEvent("The WQX data does not contain any organizations, so no elements will be stored in the database."); return(null); } } catch (Exception ex) { FileUtils.SafeDeleteDirectory(attachmentsFolderPath); throw ex; } finally { FileUtils.SafeDeleteFile(wqxFilePath); } return(data); }