コード例 #1
0
        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);
        }