Exemple #1
0
 public byte[] GetUncompressedContent(string transactionId, string id)
 {
     byte[] content = GetContent(transactionId, id);
     if (content != null)
     {
         if (_compressionHelper.IsCompressed(content))
         {
             content = _compressionHelper.UncompressDeep(content);
         }
     }
     return(content);
 }
        public string ImportSettings(byte[] settingsFileBytes, ImportExportSettings settingsToImport,
                                     ImportSettingsAction importAction, NodeVisit visit)
        {
            ValidateByRole(visit, SystemRoleType.Admin);

            if (settingsToImport == ImportExportSettings.None)
            {
                return(null);
            }
            if (_compressionHelper.IsCompressed(settingsFileBytes))
            {
                try
                {
                    settingsFileBytes = _compressionHelper.UncompressDeep(settingsFileBytes);
                }
                catch (Exception e)
                {
                    throw new ArgException("Failed to uncompress zip file content: " + e.Message);
                }
            }
            NodeSettings nodeSettings;

            try
            {
                nodeSettings = _serializationHelper.Deserialize <NodeSettings>(settingsFileBytes);
            }
            catch (Exception e)
            {
                throw new ArgException("Failed to deserialize node settings content: " + e.Message);
            }
            string   errorMessage = null;
            DateTime modifiedOn   = DateTime.Now;
            string   modifiedById = visit.Account.Id;

            if (EnumUtils.IsFlagSet(settingsToImport, ImportExportSettings.GlobalArguments))
            {
                IList <ConfigItem> list =
                    NodeSettings.GetGlobalArguments(nodeSettings.GlobalArguments, modifiedById,
                                                    modifiedOn);
                ConfigManager.Import(list, importAction);
            }
            return(errorMessage);
        }
Exemple #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);
            }
        }
Exemple #4
0
        protected virtual string AddExchangeDocumentHeader(string inputFile, bool doCompress, string docTransactionId)
        {
            string tempZipFilePath = _settingsProvider.NewTempFilePath(".zip");

            if (!_addHeader)
            {
                if (doCompress && !_compressionHelper.IsCompressed(inputFile))
                {
                    _compressionHelper.CompressFile(inputFile, tempZipFilePath);
                }
                else
                {
                    tempZipFilePath = inputFile;
                }
            }
            else
            {
                AppendAuditLogEvent("Adding an exchange header to the document ...");

                ExceptionUtils.ThrowIfFileNotFound(inputFile);

                string tempInputFilePath = _settingsProvider.NewTempFilePath(".xml");
                string tempXmlFilePath   = _settingsProvider.NewTempFilePath(".xml");

                try
                {
                    if (_compressionHelper.IsCompressed(inputFile))
                    {
                        _compressionHelper.Uncompress(inputFile, tempInputFilePath);
                        inputFile = tempInputFilePath;
                    }

                    XmlDocument doc = new XmlDocument();
                    doc.Load(inputFile);

                    _headerDocumentHelper.Configure(_author, _organization, "AQS Data", AQS_FLOW_NAME, null, null, _aqsUserId, null);
                    if (!string.IsNullOrEmpty(_senderAddress))
                    {
                        List <string> emails = StringUtils.SplitAndReallyRemoveEmptyEntries(_senderAddress, EMAIL_ADDRESS_SEPARATOR);
                        if (!CollectionUtils.IsNullOrEmpty(emails))
                        {
                            _headerDocumentHelper.AddNotifications(emails);
                        }
                    }
                    if (!string.IsNullOrEmpty(_aqsScreeningGroup))
                    {
                        _headerDocumentHelper.AddPropery("AQS.ScreeningGroup", _aqsScreeningGroup);
                    }
                    if (!string.IsNullOrEmpty(_aqsFinalProcessingStep))
                    {
                        _headerDocumentHelper.AddPropery("AQS.FinalProcessingStep", _aqsFinalProcessingStep);
                    }
                    if (!string.IsNullOrEmpty(_aqsStopOnError))
                    {
                        _headerDocumentHelper.AddPropery("AQS.StopOnError", _aqsStopOnError);
                    }
                    _headerDocumentHelper.AddPropery("AQS.SchemaVersion", "3.0");

                    _headerDocumentHelper.AddPropery("AQS.PayloadType", "XML");

                    _headerDocumentHelper.AddPayload(null, doc.DocumentElement);

                    _headerDocumentHelper.Serialize(tempXmlFilePath);

                    if (doCompress)
                    {
                        _compressionHelper.CompressFile(tempXmlFilePath, tempZipFilePath);
                    }
                    else
                    {
                        tempZipFilePath = tempXmlFilePath;
                    }
                }
                catch (Exception ex)
                {
                    AppendAuditLogEvent("Failed to add an exchange header to the document with the following exception: {0}",
                                        ExceptionUtils.GetDeepExceptionMessage(ex));
                    FileUtils.SafeDeleteFile(tempZipFilePath);
                    throw;
                }
                finally
                {
                    FileUtils.SafeDeleteFile(tempInputFilePath);
                    FileUtils.SafeDeleteFile(tempXmlFilePath);
                }
            }
            if (!string.IsNullOrEmpty(docTransactionId))
            {
                _documentManager.AddDocument(docTransactionId, CommonTransactionStatusCode.Completed, null, tempZipFilePath);
            }
            return(tempZipFilePath);
        }