public byte[] ExportSettingsAsZippedBytes(ImportExportSettings settingsToExport, NodeVisit visit)
        {
            ValidateByRole(visit, SystemRoleType.Admin);

            NodeSettings nodeSettings = new NodeSettings();

            string errorMessage = null;

            if (EnumUtils.IsFlagSet(settingsToExport, ImportExportSettings.GlobalArguments))
            {
                nodeSettings.SetGlobalArguments(ConfigManager.Get(ConfigurationType.All));
            }
            if (EnumUtils.IsFlagSet(settingsToExport, ImportExportSettings.DataSources))
            {
                nodeSettings.SetDataSources(DataProviderManager.Get());
            }
            if (EnumUtils.IsFlagSet(settingsToExport, ImportExportSettings.NetworkPartners))
            {
                nodeSettings.SetNetworkPartners(PartnerManager.Get());
            }
            bool exportExchanges = EnumUtils.IsFlagSet(settingsToExport, ImportExportSettings.Exchanges);
            bool exportServices  = EnumUtils.IsFlagSet(settingsToExport, ImportExportSettings.Services);

            if (exportExchanges || exportServices)
            {
                IList <DataFlow> flows = FlowManager.GetAllDataFlows(exportServices, false);
                if (exportExchanges)
                {
                    nodeSettings.SetExchanges(flows);
                }
                if (exportServices)
                {
                    nodeSettings.SetServices(flows);
                }
            }
            if (EnumUtils.IsFlagSet(settingsToExport, ImportExportSettings.Schedules))
            {
                IDictionary <string, string> flowIdToNameMap    = FlowManager.GetAllFlowsIdToNameMap();
                IDictionary <string, string> serviceIdToNameMap = ServiceManager.GetAllServicesIdToNameMap();
                IDictionary <string, string> partnerIdToNameMap = PartnerManager.GetAllPartnersIdToNameMap();

                nodeSettings.SetSchedules(ScheduleManager.GetSchedules(), flowIdToNameMap, serviceIdToNameMap,
                                          partnerIdToNameMap, out errorMessage);
            }

            string tempFilePath = SettingsProvider.NewTempFilePath();

            _compressionHelper.Compress("Settings.xml", _serializationHelper.SerializeWithLineBreaks(nodeSettings),
                                        tempFilePath);
            if (errorMessage != null)
            {
                _compressionHelper.Compress("Errors.txt", Encoding.UTF8.GetBytes(errorMessage), tempFilePath);
            }

            byte[] zippedData = File.ReadAllBytes(tempFilePath);

            ActivityManager.LogAudit(NodeMethod.None, null, visit, "{0} exported the following node settings: {1}.",
                                     visit.Account.NaasAccount, settingsToExport);
            return(zippedData);
        }
Example #2
0
        public void SerializeWithLineBreaks(string filePath)
        {
            _hd.Header.Notification = _notifs.ToArray();
            _hd.Header.Property     = _properties.ToArray();
            _hd.Payload             = _payloads.ToArray();

            _serializationHelper.SerializeWithLineBreaks(_hd, filePath);
        }
        protected virtual void SaveCheckStatusInfo(CheckStatusInfo info)
        {
            byte[]   content = _serializationHelper.SerializeWithLineBreaks(info);
            Document doc     = new Document(SUBMISSION_CHECK_STATUS_INFO_FILE_NAME, CommonContentType.XML, content);

            doc.DontAutoCompress = true;
            Document existingDoc = null;

            try
            {
                existingDoc = _documentManager.GetDocumentByName(_transaction.Id, SUBMISSION_CHECK_STATUS_INFO_FILE_NAME, false);
            }
            catch (FileNotFoundException)
            {
            }
            if (existingDoc != null)
            {
                _documentManager.DeleteDocument(_transaction.Id, existingDoc.Id);
            }
            _documentManager.AddDocument(_transaction.Id, CommonTransactionStatusCode.Completed, string.Empty, doc);
        }
        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);
        }