// if required, rename output-files to indicate if switches are set to non-default values bool EM3_AddNonDefaultSwitches_To_OutputFileName(Dictionary <ConfigKey, Dictionary <string, string> > contentEMConfigs, RunMainForm runMainForm) { try { // check if automatic renaming of the output-filenames is switched on if (!EM_UI.EM_AppContext.Instance.GetUserSettingsAdministrator().GetPolicySwitchAutoRenameValue()) { return(true); } foreach (DataGridViewRow systemRow in runMainForm.dgvRun.Rows) // loop over systems { // assess whether any run-checkboxes (standard run, add-ons) are checked for the system if (!EM_Helpers.SaveConvertToBoolean(systemRow.Cells[runMainForm.colRun.Name].Value)) { continue; } // assess which dataset is selected for run DataConfig.DBSystemConfigRow dbSystemConfigRow = runMainForm.GetSelectedDBSystemCombination(systemRow); if (dbSystemConfigRow == null) { continue; // should not happen } // find the EMConfig (prepared in GenerateEMConfigs) where the output needs to be renamed Dictionary <string, string> contentEMConfig = null; ConfigKey key = new ConfigKey(systemRow.Cells[runMainForm.colCountry.Name].Value.ToString(), dbSystemConfigRow.DataBaseID, dbSystemConfigRow.SystemID); if (contentEMConfigs.ContainsKey(key)) { contentEMConfig = contentEMConfigs[key]; } if (contentEMConfig == null) { continue; // should not happen } // instruct the executable to apply this suffix to standard output (i.e. concerns only DefOutputs in policies output_std and output_std_hh): // specificly, change e.g. mt_2014_std to mt_2014_UAAon and/or mt_2014_std_hh to mt_2014_UAAon_hh string renameString = GenerateSwitchRenamingSuffix(runMainForm, systemRow, dbSystemConfigRow); if (renameString != string.Empty) { contentEMConfig.Add(TAGS.STDOUTPUT_FILENAME_SUFFIX, renameString); } } } catch { } return(true); }
// this does not only add the addOn-info, but also collects the country- and addOn-file that need to be transformed to EM3 format bool EM3_AddAddOnInfo(string outputPath, Dictionary <ConfigKey, Dictionary <string, string> > contentEMConfigs, RunMainForm runMainForm) { addOnsToTransform = new List <string>(); countriesToTransform = new List <string>(); // for collecting country- and addon-files which need to be transformed to EM3 foreach (DataGridViewRow systemRow in runMainForm.dgvRun.Rows) // loop over systems { // assess whether any add-on is selected for run (theoretically more than one add-on can be selected for a system) List <AddOnSystemInfo> selectedAddOns = new List <AddOnSystemInfo>(); foreach (DataGridViewColumn column in runMainForm.dgvRun.Columns) { if (column.Name.StartsWith(RunMainForm._colAddOnPrefix) && EM_Helpers.SaveConvertToBoolean(systemRow.Cells[column.Name].Value)) { if (!AddOnInfoHelper.GetSupportedSystemInfo(systemRow.Cells[runMainForm.colSystem.Name].Value.ToString(), column.Tag as List <AddOnSystemInfo>, out List <AddOnSystemInfo> supportedAOSystemInfo)) { return(false); } selectedAddOns.AddRange(supportedAOSystemInfo); } } // we need to know whether the system is selected, first to collect the country for transformation (see remark above) // and, if it is selected in addition to any add-on(s), we need to copy the configuration file (instead of just adapting it) bool isSystemSelected = EM_Helpers.SaveConvertToBoolean(systemRow.Cells[runMainForm.colRun.Name].Value); string countryShortName = systemRow.Cells[runMainForm.colCountry.Name].Value.ToString().ToLower(); if (isSystemSelected || selectedAddOns.Any()) { string countryToTransform = countryShortName; if (!countriesToTransform.Contains(countryToTransform)) { countriesToTransform.Add(countryToTransform); } } if (!selectedAddOns.Any()) { continue; } // to find the config (prepared in GenerateEMConfigs) we need the dataset DataConfig.DBSystemConfigRow dbSystemConfigRow = runMainForm.GetSelectedDBSystemCombination(systemRow); if (dbSystemConfigRow == null) { continue; // should not happen } ConfigKey key = new ConfigKey(countryShortName, dbSystemConfigRow.DataBaseID, dbSystemConfigRow.SystemID); if (!contentEMConfigs.ContainsKey(key)) { continue; // should not happen } Dictionary <string, string> contentEMConfig = contentEMConfigs[key]; // if the system itself is selected too, we need to make a copy of the config (i.e. run the plain system and run the add-on) if (isSystemSelected) { contentEMConfig = new Dictionary <string, string>(); foreach (var entry in contentEMConfigs[key]) { contentEMConfig.Add(entry.Key, entry.Value); } ConfigKey someKey = new ConfigKey(Guid.NewGuid().ToString(), string.Empty, string.Empty); // the key is irrelevant contentEMConfigs.Add(someKey, contentEMConfig); } int cnt = 0; foreach (AddOnSystemInfo addOnSystemInfo in selectedAddOns) // loop over the add-ons which are selected for run (usually one) { contentEMConfig[RunMainForm._labelRunFormInfoText] += addOnSystemInfo._addOnSystemName + " "; // add to text that is displayed in the window showing run status // add: $"ADDON{cnt}", $"{addOn}|{addOnSys}" contentEMConfig.Add(TAGS.EM2CONFIG_ADDON + (cnt++).ToString(), addOnSystemInfo._addOnShortName + "|" + addOnSystemInfo._addOnSystemName); string addOnToTransform = addOnSystemInfo._addOnShortName.ToLower(); if (!addOnsToTransform.Contains(addOnToTransform)) { EM_AppContext.Instance.WriteXml(addOnSystemInfo._addOnShortName, false, false); // make sure the EM2 version is saved addOnsToTransform.Add(addOnToTransform); } } } return(true); }