Пример #1
0
        public static bool GetCAOInfo(out TSDictionary info, bool includeCountries = true, bool includeAddOns = true, bool openOnly = false)
        {
            info = new TSDictionary();

            try
            {
                List <Country> caos = new List <Country>();
                if (includeCountries)
                {
                    caos.AddRange(CountryAdministrator.GetCountries());
                }
                if (includeAddOns)
                {
                    caos.AddRange(CountryAdministrator.GetAddOns());
                }

                Dictionary <string, EM_UI_MainForm> openMainForms = new Dictionary <string, EM_UI_MainForm>();
                foreach (EM_UI_MainForm mf in EM_AppContext.Instance.GetOpenCountriesMainForms())
                {
                    openMainForms.Add(mf.GetCountryShortName().ToLower(), mf);
                }

                List <Form>   mainForms        = new List <Form>();
                List <string> shortNames       = new List <string>();
                List <string> longNames        = new List <string>();
                List <bool>   isAddOn          = new List <bool>();
                List <bool>   isOpen           = new List <bool>();
                List <string> mainXMLFileNames = new List <string>();
                List <string> dataXMLFileNames = new List <string>();
                List <string> filePaths        = new List <string>();
                foreach (Country cao in caos)
                {
                    bool open = openMainForms.ContainsKey(cao._shortName.ToLower());
                    if (openOnly && !open)
                    {
                        continue;
                    }
                    mainForms.Add(open ? openMainForms[cao._shortName.ToLower()] : null);
                    shortNames.Add(cao._shortName);
                    // long name is only availabel through CountryConfig (it doesn't seem appropriate to open the country just to get the long-name)
                    longNames.Add(open ? openMainForms[cao._shortName.ToLower()].GetCountryLongName() : cao._shortName);
                    isAddOn.Add(cao._isAddOn);
                    isOpen.Add(open);
                    mainXMLFileNames.Add(CountryAdministrator.GetCountryFileName(cao._shortName));
                    dataXMLFileNames.Add(cao._isAddOn ? string.Empty : CountryAdministrator.GetDataFileName(cao._shortName));
                    filePaths.Add(CountryAdministrator.GetCountryPath(cao._shortName));
                }
                info.SetItem(UISessionInfo.CAO_INFO_MainForms, mainForms);
                info.SetItem(UISessionInfo.CAO_INFO_ShortNames, shortNames);
                info.SetItem(UISessionInfo.CAO_INFO_LongNames, longNames);
                info.SetItem(UISessionInfo.CAO_INFO_IsAddOn, isAddOn);
                info.SetItem(UISessionInfo.CAO_INFO_IsOpen, isOpen);
                info.SetItem(UISessionInfo.CAO_INFO_MainXMLFileNames, mainXMLFileNames);
                info.SetItem(UISessionInfo.CAO_INFO_DataXMLFileNames, dataXMLFileNames);
                info.SetItem(UISessionInfo.CAO_INFO_FilePaths, filePaths);
                return(true);
            }
            catch { return(false); }
        }
Пример #2
0
        private Dictionary <string, string> EM2_CreateConfig(string countryShortName, string outputPath, DataConfig.DataBaseRow dbr, CountryConfig.SystemRow sr, bool useTempCountry = true)
        {
            Dictionary <string, string> contentEMConfig = new Dictionary <string, string>();

            string emVersion = EM_AppContext.Instance.GetProjectName();

            if (emVersion.Trim() == string.Empty)
            {
                UserInfoHandler.ShowError($"{DefGeneral.BRAND_TITLE} version is not defined. Please define it via the menu 'Configuration'.");
                return(null);
            }
            //fill EMConfig-entry-list
            string dateTimePrefix = string.Format("{0:yyyyMMddHHmm}", DateTime.Now);

            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_ERRLOG_FILE, outputPath + dateTimePrefix + EM_XmlHandler.TAGS.EM2CONFIG_errLogFileName);
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_LOG_WARNINGS, DefPar.Value.YES);
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_EMVERSION, emVersion);
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_UIVERSION, DefGeneral.UI_VERSION);
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_PARAMPATH, useTempCountry ? EMPath.AddSlash(EMPath.Folder_Temp(EM_AppContext.FolderEuromodFiles)) : EMPath.AddSlash(Path.Combine(EMPath.Folder_Countries(EM_AppContext.FolderEuromodFiles), countryShortName)));
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_CONFIGPATH, EMPath.Folder_Config(EM_AppContext.FolderEuromodFiles));
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_OUTPUTPATH, outputPath);
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_DATAPATH, EM_AppContext.FolderInput);
            string executablePath = EnvironmentInfo.GetEM2ExecutableFile();

            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_EMCONTENTPATH, EM_AppContext.FolderEuromodFiles);
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_HEADER_DATE, dateTimePrefix);
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_OUTFILE_DATE, "-");
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_LOG_RUNTIME, DefPar.Value.NO);
            if (EM_AppContext.Instance.IsPublicVersion())
            {
                contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_ISPUBLICVERSION, DefPar.Value.YES);
            }
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_DECSIGN_PARAM, EM_Helpers.uiDecimalSeparator);
            string startHH = EM_XmlHandler.TAGS.EM2CONFIG_defaultHHID;
            string lastHH  = EM_XmlHandler.TAGS.EM2CONFIG_defaultHHID;

            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_STARTHH, startHH);
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_LASTHH, lastHH);
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_COUNTRY_FILE, CountryAdministrator.GetCountryFileName(countryShortName));
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_DATACONFIG_FILE, CountryAdministrator.GetDataFileName(countryShortName));
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_DATASET_ID, dbr.ID);
            contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_SYSTEM_ID, sr.ID);

            //generate for each (available) switchable policy a POLICY_SWITCH-entry
            Dictionary <string, string> extIDAndPattern = new Dictionary <string, string>();

            foreach (GlobLocExtensionRow e in ExtensionAndGroupManager.GetExtensions(countryShortName))
            {
                extIDAndPattern.Add(e.ID, e.ShortName);
            }

            List <string> policySwitchEntries = new List <string>();

            foreach (var e in extIDAndPattern)
            {
                string extID = e.Key, extShortName = e.Value;
                string policySwitchValue = string.Empty;
                if (dbr.GetDBSystemConfigRows().Count(x => x.SystemID == sr.ID) > 0)
                {
                    policySwitchValue = ExtensionAndGroupManager.GetExtensionDefaultSwitch(dbr.GetDBSystemConfigRows().First(x => x.SystemID == sr.ID), extID);
                }

                //generate the POLICY_SWITCH-entry
                //taking into account that there is no need to generate it if the switch is set to n/a (i.e. the switchable policy is not switchable for this db-system-combination or does not even exist)
                if (policySwitchValue != string.Empty && policySwitchValue != DefPar.Value.NA)
                {
                    string policySwitchEntry =                            //the executable needs three pieces of information to overwrite the default value of the policy switch:
                                               extShortName               //which switchable policy (e.g. BTA_??)
                                               + "=" + sr.ID              //which system
                                               + "=" + policySwitchValue; //and the respective value (on or off)
                    policySwitchEntries.Add(policySwitchEntry);
                }
            }

            //for each (available) switchable policy add a POLICY_SWITCH-entry
            foreach (string policySwitchEntry in policySwitchEntries)
            {
                contentEMConfig.Add(EM_XmlHandler.TAGS.EM2CONFIG_POLICY_SWITCH + Guid.NewGuid().ToString(), policySwitchEntry);
            }


            //now actually write the EMConfigXXX.xml files and hand them over to the run-manager
            string configurationFileNameAndPath = EMPath.Folder_Temp(EM_AppContext.FolderEuromodFiles) + EM_XmlHandler.TAGS.EM2CONFIG_labelEMConfig + Guid.NewGuid().ToString() + ".xml";

            using (XmlTextWriter configurationFileWriter = new XmlTextWriter(configurationFileNameAndPath, null))
            {
                configurationFileWriter.Formatting = System.Xml.Formatting.Indented;
                configurationFileWriter.WriteStartDocument(true);
                configurationFileWriter.WriteStartElement(EM_XmlHandler.TAGS.EM2CONFIG_labelEMConfig);

                string runFormInfoText = string.Empty;
                foreach (string key in contentEMConfig.Keys)
                {
                    if (key.StartsWith(EM_XmlHandler.TAGS.EM2CONFIG_SYSTEM_ID)) //remove Guid, see above
                    {
                        configurationFileWriter.WriteElementString(EM_XmlHandler.TAGS.EM2CONFIG_SYSTEM_ID, contentEMConfig[key]);
                    }
                    else if (key.StartsWith(EM_XmlHandler.TAGS.EM2CONFIG_POLICY_SWITCH)) //remove Guid, see above
                    {
                        configurationFileWriter.WriteElementString(EM_XmlHandler.TAGS.EM2CONFIG_POLICY_SWITCH, contentEMConfig[key]);
                    }
                    else
                    {
                        configurationFileWriter.WriteElementString(key, contentEMConfig[key]);
                    }
                }

                configurationFileWriter.WriteElementString(EM_XmlHandler.TAGS.EM2CONFIG_LAST_RUN, DefPar.Value.NO);
                configurationFileWriter.WriteEndElement();
                configurationFileWriter.WriteEndDocument();
            }
            // EM3 returns the config-dictionary, therefore (mis)use this structure to just store the file-path as the first entry (to avoid extra variables for EM2)
            return(new Dictionary <string, string>()
            {
                { configurationFileNameAndPath, null }
            });
        }