string BestMatchCheck(List <SystemAndData> systemsAndData, BestMatchCheckType check, string country = "") { string faulty = string.Empty; List <string> done = new List <string>(); foreach (SystemAndData systemAndData in systemsAndData) { if (systemAndData.bestMatches.Count != 1) { continue; // only consider unique best-matches for simplicity } DataConfig.DataBaseRow data = systemAndData.bestMatches[0].DataBaseRow; if (done.Contains(data.Name.ToLower())) { continue; // data can be best-match of several systems (just need to check once) } switch (check) { case BestMatchCheckType.Year_NotEqual_Collection: string cy = data.YearCollection.Trim() == string.Empty ? "-" : data.YearCollection.Trim(); if (!data.Name.Contains(cy)) { faulty += string.Format("{0} ({1}), ", data.Name, cy); } break; case BestMatchCheckType.Income_Greater_Year: int incYear, colYear; if (int.TryParse(data.YearInc, out incYear) && int.TryParse(data.YearCollection, out colYear) && incYear > colYear) { faulty += string.Format("{0} ({1}>{2}), ", data.Name, incYear, colYear); } break; case BestMatchCheckType.UseCommonDefault: if (data.UseCommonDefault == DefPar.Value.YES) { faulty += data.Name + ", "; } break; case BestMatchCheckType.NoHICP: HICPConfigFacade hcf = EM_AppContext.Instance.GetHICPConfigFacade(false); if (hcf == null) { return(string.Empty); // should not happen } int year; if (!int.TryParse(data.YearInc, out year) || hcf.GetHICP(country, year) == null) { faulty += data.Name + ", "; } break; } done.Add(data.Name.ToLower()); } return(faulty); }
private Dictionary <string, string> EM3_CreateConfig(string countryShortName, string outputPath, DataConfig.DataBaseRow dbr, CountryConfig.SystemRow sr, string parModifications = null) { Dictionary <string, string> config = new Dictionary <string, string>(); config.Add(TAGS.CONFIG_PATH_OUTPUT, outputPath); config.Add(TAGS.CONFIG_PATH_DATA, EM_AppContext.FolderInput); config.Add(TAGS.CONFIG_PATH_EUROMODFILES, EM_AppContext.FolderEuromodFiles); config.Add(TAGS.CONFIG_COUNTRY, CountryAdministrator.GetCountryFileName(countryShortName).ToLower().Replace(".xml", "")); config.Add(TAGS.CONFIG_ID_DATA, dbr.ID); config.Add(TAGS.CONFIG_ID_SYSTEM, sr.ID); if (textRunFirstNHH.Text != null && !string.IsNullOrEmpty(textRunFirstNHH.Text) && int.TryParse(textRunFirstNHH.Text, out _)) { config.Add(TAGS.CONFIG_FIRST_N_HH_ONLY, textRunFirstNHH.Text); } if (parModifications != null) { config.Add(TAGS.CONFIG_STRING_PAR_MODIFICATIONS, parModifications); } string addOn = GetCheckedAddon(); if (!string.IsNullOrEmpty(addOn)) { string addOnSys = null; foreach (AddOnSystemInfo aos in AddOnInfoHelper.GetAddOnSystemInfo(addOn)) { foreach (string sysPattern in aos._supportedSystems) { if (EM_Helpers.DoesValueMatchPattern(sysPattern, sr.Name)) { addOnSys = aos._addOnSystemName; break; } } } if (addOnSys == null) { throw new Exception($"No matching Addon found for {sr.Name}"); } config.Add(TAGS.CONFIG_ADDON, $"{addOn}|{addOnSys}"); } return(config); }
private static void AssessExtensionInfo(CountryConfigFacade ccf, DataConfigFacade dcf, string extensionId, string offOn, ref Dictionary <string, List <string> > switchInfo) { Dictionary <string, List <string> > dataSwitches = new Dictionary <string, List <string> >(); foreach (DataConfig.PolicySwitchRow polSwitch in from e in dcf.GetDataConfig().PolicySwitch where e.SwitchablePolicyID == extensionId select e) { if (polSwitch.Value != offOn) { continue; } if (!dataSwitches.ContainsKey(polSwitch.DataBaseID)) { dataSwitches.Add(polSwitch.DataBaseID, new List <string>()); } dataSwitches[polSwitch.DataBaseID].Add(polSwitch.SystemID); } foreach (var dataSwitch in dataSwitches) { DataConfig.DataBaseRow dataRow = dcf.GetDataBaseRow(dataSwitch.Key); if (dataRow == null) { continue; } string sumDataSwitches = dataRow.Name + ":"; foreach (string sysId in dataSwitch.Value) { CountryConfig.SystemRow sysRow = ccf.GetSystemRowByID(sysId); if (sysRow == null) { continue; } sumDataSwitches += sysRow.Name + ","; } if (!switchInfo.ContainsKey(extensionId)) { switchInfo.Add(extensionId, new List <string>()); } switchInfo[extensionId].Add(RVItem_Base.TrimEnd(sumDataSwitches)); } }
void FillDatasetTable(List <DataConfigFacade> dataConfigFacades, List <string> countryShortNames) { dgvDatasets.Rows.Clear(); for (int i = dgvDatasets.Columns.Count - 1; i >= 0; --i) { if (dgvDatasets.Columns[i].Name.StartsWith(_colDataYearPrefix)) { dgvDatasets.Columns.RemoveAt(i); //delete all but the fix columns (those displaying data-properties like collection year, private, ...) } } List <string> dataYears = new List <string>(); //loop over countries for (int index = 0; index < dataConfigFacades.Count; ++index) { DataConfigFacade dataConfigFacade = dataConfigFacades.ElementAt(index); //loop over dataset of the country bool firstDatasetOfCountry = true; foreach (DataConfig.DataBaseRow dataset in dataConfigFacade.GetDataBaseRows()) { //if the dataset is a "standard dataset", i.e. called cc_yyyy_xx, extract the year of the name string datasetName = dataset.Name.ToLower().EndsWith(".txt") ? dataset.Name.Substring(0, dataset.Name.Length - 4) : dataset.Name; string dataYear = string.Empty; if (datasetName.Length >= 8 && datasetName.Substring(2, 1) == "_" && datasetName.Substring(7, 1) == "_" && EM_Helpers.IsNonNegInteger(datasetName.Substring(3, 4))) { dataYear = datasetName.Substring(3, 4); } else if (datasetName.ToLower().Contains("hypo")) //take respect of hypo-data ... { dataYear = "hypo"; } else if (datasetName.ToLower().Contains("training")) //... and training data (which also exist for most countries) { dataYear = "training"; } else { dataYear = _colHeadingNonStandard; //probably only SL_demo_vi } //add an entry for the dataset year, if not already existent if (!dataYears.Contains(dataYear)) { dataYears.Add(dataYear); } //generate a row for each dataset and equip the row's tag with information (data-year and data-properties) for the cell-filling below int rowIndex = dgvDatasets.Rows.Add(); dgvDatasets.Rows[rowIndex].Tag = new KeyValuePair <string, DataConfig.DataBaseRow>(dataYear, dataset); //put name of country in row header if first dataset for this country if (firstDatasetOfCountry && index < countryShortNames.Count) { dgvDatasets.Rows[rowIndex].HeaderCell.Value = countryShortNames.ElementAt(index); firstDatasetOfCountry = false; } } } //sort the list of years (to get 2001, 2002, 2003, etc. instead of 2001, 2003, 2002, etc.) and generate the columns dataYears.Sort(); dataYears.Reverse(); foreach (string dataYear in dataYears) { DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn(); column.Name = _colDataYearPrefix + dataYear; column.HeaderCell.Value = dataYear; dgvDatasets.Columns.Insert(0, column); //insert before the fix columns (collection year, private, etc.) } //fill the table foreach (DataGridViewRow row in dgvDatasets.Rows) { KeyValuePair <string, DataConfig.DataBaseRow> rowTag = (KeyValuePair <string, DataConfig.DataBaseRow>)(row.Tag); DataConfig.DataBaseRow dataset = rowTag.Value; string dataYear = rowTag.Key; row.Cells[colYearCollection.Name].Value = dataset.YearCollection; row.Cells[colYearIncome.Name].Value = dataset.YearInc; row.Cells[colPrivate.Name].Value = dataset.Private; row.Cells[_colDataYearPrefix + dataYear].Value = dataset.Name; } }
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 } }); }
private void EM2_RunDecompCountry(string countryShortName) { string currentAction = ""; try { currentAction = "getting " + countryShortName + " config files"; DataRow row = policyDataTable.Select("Country='" + countryShortName + "'")[0]; string sn1 = showFull ? row["System1"].ToString() : countryShortName + "_" + comboBox1.Text; string sn2 = showFull ? row["System2"].ToString() : countryShortName + "_" + comboBox2.Text; CountryConfig.SystemRow sr1 = CountryAdministrator.GetCountryConfigFacade(countryShortName).GetSystemRowByName(sn1); CountryConfig.SystemRow sr2 = CountryAdministrator.GetCountryConfigFacade(countryShortName).GetSystemRowByName(sn2); // make a copy of the country, to be later stored in the temp-folder currentAction = "copying " + countryShortName + " for decomposition"; Country copiedCountry = CountryAdministrator.GetCopyOfCountry(countryShortName); CountryConfigFacade ccf = copiedCountry.GetCountryConfigFacade(); DataConfigFacade _dataConfigFacade = copiedCountry.GetDataConfigFacade(); DataConfig.DataBaseRow dbr1 = null; DataConfig.DataBaseRow dbr2 = null; foreach (DataConfig.DataBaseRow dataSet in _dataConfigFacade.GetDataBaseRows()) { if (dataSet.Name == row["Data1"].ToString()) { dbr1 = dataSet; } if (dataSet.Name == row["Data2"].ToString()) { dbr2 = dataSet; } } // then create all required systems, depending on decomposition and Alpha selection currentAction = "getting " + countryShortName + "'s uprate factors"; Dictionary <string, string> upratingFactors1 = GetUpratingFactors(sr1, dbr1, countryShortName); Dictionary <string, string> upratingFactors2 = GetUpratingFactors(sr2, dbr2, countryShortName); double alpha = 0; List <DecompSystem> allSystems = new List <DecompSystem>(); bool treatAsMarket = chkTreatAsMarket.Checked; // get the systems of the checked addon (if one was checked) string addon = GetCheckedAddon(); bool hasAddon = addon != string.Empty; List <AddOnSystemInfo> addonSystems = hasAddon ? AddOnInfoHelper.GetAddOnSystemInfo(addon) : null; currentAction = "creating " + countryShortName + "'s decomposed systems"; const double ALPHA_CPI = double.MinValue, ALPHA_MII = double.MaxValue; // just any numbers differnt from the alphas in alphaFIX List <double> alphas = new List <double>(); if (checkBoxAlphaCPI.Checked) { alphas.Add(ALPHA_CPI); } if (checkBoxAlphaMII.Checked) { alphas.Add(ALPHA_MII); } if (checkBoxAlphaFIX.Checked) { alphas.AddRange(alphaFIXValues); // those where gathered in GetAlphaFIX } foreach (double a in alphas) { string systemNameExt = ""; // first find Alpha, log text, system name extention etc. if (a == ALPHA_CPI) { Dictionary <string, string> rawIndices = GetRawCPIindices(sr1, countryShortName); if (!(rawIndices.ContainsKey(comboBox1.Text) || rawIndices.ContainsKey(comboBox2.Text))) { throw new Exception("The CPI raw indices ('" + FactorCPI + "') were not found for the selected years!"); } double hicp1 = EM_Helpers.SaveConvertToDouble(rawIndices[comboBox1.Text]); double hicp2 = EM_Helpers.SaveConvertToDouble(rawIndices[comboBox2.Text]); alpha = hicp2 / hicp1; AddToLog($"{RunLogger.PetInfo.LOGTAG_ALPHA_CPI} ({countryShortName})", $"{alpha} ({hicp2}/{hicp1})", LOGMODE.EM2); systemNameExt = "_cpi"; alphaValues.Add(countryShortName + "_cpi", alpha); } else if (a == ALPHA_MII) { double mii1 = getAlphaFromBaselineFile(sr1.Name); double mii2 = getAlphaFromBaselineFile(sr2.Name); alpha = mii2 / mii1; AddToLog($"{RunLogger.PetInfo.LOGTAG_ALPHA_MII} ({countryShortName})", $"{alpha} ({mii2}/{mii1})", LOGMODE.EM2); systemNameExt = "_mii"; alphaValues.Add(countryShortName + "_mii", alpha); } else { alpha = a; systemNameExt = "_a" + GetAlphaFIXId(a); alphaValues.Add(countryShortName + "_fix" + GetAlphaFIXId(a), alpha); } // Then actually create the required systems if (checkRadioData1.Checked || checkRadioDataBoth.Checked) { DecompSystem ds1 = new DecompSystem(); ds1.sr = CountryConfigFacade.CopySystemRow(sr2.Name + "_on_" + dbr1.Name + systemNameExt, ccf.GetSystemRowByID(sr2.ID)); copiedCountry.GetDataConfigFacade().CopyDBSystemConfigRows(ccf.GetSystemRowByID(sr2.ID), ds1.sr); ds1.dbr = dbr1; if (hasAddon) { MergeAddOn(addonSystems, sr2.Name, ds1, copiedCountry); } EM2_FixUprating(ds1.sr, upratingFactors1, upratingFactors2, countryShortName, alpha, 1, treatAsMarket); allSystems.Add(ds1); if (checkRadioMonetary.Checked) { DecompSystem ds2 = new DecompSystem(); ds2.sr = CountryConfigFacade.CopySystemRow(sr2.Name + "ind_on_" + dbr1.Name + systemNameExt, ccf.GetSystemRowByID(sr2.ID)); copiedCountry.GetDataConfigFacade().CopyDBSystemConfigRows(ccf.GetSystemRowByID(sr2.ID), ds2.sr); ds2.dbr = dbr1; if (hasAddon) { MergeAddOn(addonSystems, sr2.Name, ds2, copiedCountry); } EM2_FixUprating(ds2.sr, upratingFactors1, upratingFactors2, countryShortName, alpha, 2, treatAsMarket); allSystems.Add(ds2); DecompSystem ds3 = new DecompSystem(); ds3.sr = CountryConfigFacade.CopySystemRow(sr1.Name + "ind" + systemNameExt, ccf.GetSystemRowByID(sr1.ID)); copiedCountry.GetDataConfigFacade().CopyDBSystemConfigRows(ccf.GetSystemRowByID(sr1.ID), ds3.sr); ds3.dbr = dbr1; if (hasAddon) { MergeAddOn(addonSystems, sr1.Name, ds3, copiedCountry); } EM2_FixUprating(ds3.sr, upratingFactors1, upratingFactors2, countryShortName, alpha, 3, treatAsMarket); allSystems.Add(ds3); } } if (checkRadioData2.Checked || checkRadioDataBoth.Checked) { DecompSystem ds1 = new DecompSystem(); ds1.sr = CountryConfigFacade.CopySystemRow(sr1.Name + "_on_" + dbr2.Name + systemNameExt, ccf.GetSystemRowByID(sr1.ID)); copiedCountry.GetDataConfigFacade().CopyDBSystemConfigRows(ccf.GetSystemRowByID(sr1.ID), ds1.sr); ds1.dbr = dbr2; if (hasAddon) { MergeAddOn(addonSystems, sr1.Name, ds1, copiedCountry); } EM2_FixUprating(ds1.sr, upratingFactors2, upratingFactors1, countryShortName, 1 / alpha, 1, treatAsMarket); allSystems.Add(ds1); if (checkRadioMonetary.Checked) { DecompSystem ds2 = new DecompSystem(); ds2.sr = CountryConfigFacade.CopySystemRow(sr1.Name + "ind_on_" + dbr2.Name + systemNameExt, ccf.GetSystemRowByID(sr2.ID)); copiedCountry.GetDataConfigFacade().CopyDBSystemConfigRows(ccf.GetSystemRowByID(sr1.ID), ds2.sr); ds2.dbr = dbr2; if (hasAddon) { MergeAddOn(addonSystems, sr1.Name, ds2, copiedCountry); } EM2_FixUprating(ds2.sr, upratingFactors2, upratingFactors1, countryShortName, 1 / alpha, 2, treatAsMarket); allSystems.Add(ds2); DecompSystem ds3 = new DecompSystem(); ds3.sr = CountryConfigFacade.CopySystemRow(sr2.Name + "ind" + systemNameExt, ccf.GetSystemRowByID(sr2.ID)); copiedCountry.GetDataConfigFacade().CopyDBSystemConfigRows(ccf.GetSystemRowByID(sr2.ID), ds3.sr); ds3.dbr = dbr1; if (hasAddon) { MergeAddOn(addonSystems, sr2.Name, ds3, copiedCountry); } EM2_FixUprating(ds3.sr, upratingFactors2, upratingFactors1, countryShortName, 1 / alpha, 3, treatAsMarket); allSystems.Add(ds3); } } } currentAction = "writting decomposed " + countryShortName + " in the temp folder"; copiedCountry.WriteXML(EMPath.Folder_Temp(EM_AppContext.FolderEuromodFiles)); currentAction = "running " + countryShortName + "'s decomposed systems"; foreach (DecompSystem ds in allSystems) { workers.Add(RunSystem(countryShortName, ds.sr.Name, dbr2.Name, EM2_CreateConfig(countryShortName, textBoxOutputPath.Text, ds.dbr, ds.sr))); updateInfoLabel(); } } catch (Exception ex) { em3_petInfo.AddSystemIndependentError($"There was a problem with {currentAction}: {ex.Message}"); } }
private void EM2_RunBaselineSystems() { // get the systems of the checked addon (if one was checked) string addon = GetCheckedAddon(); bool hasAddon = addon != string.Empty; List <AddOnSystemInfo> addonSystems = hasAddon ? AddOnInfoHelper.GetAddOnSystemInfo(addon) : null; foreach (DataRow row in policyDataTable.Rows) { if (row.Field <bool>("Check")) { string countryShortName = row["Country"].ToString(); Country copiedCountry = CountryAdministrator.GetCopyOfCountry(countryShortName); CountryConfigFacade ccf = copiedCountry.GetCountryConfigFacade(); DataConfigFacade _dataConfigFacade = copiedCountry.GetDataConfigFacade(); DataConfig.DataBaseRow dbr1 = null; DataConfig.DataBaseRow dbr2 = null; foreach (DataConfig.DataBaseRow dataSet in _dataConfigFacade.GetDataBaseRows()) { if (dataSet.Name == row["Data1"].ToString()) { dbr1 = dataSet; } if (dataSet.Name == row["Data2"].ToString()) { dbr2 = dataSet; } } string sn1 = showFull ? row["System1"].ToString() : countryShortName + "_" + comboBox1.Text; string sn2 = showFull ? row["System2"].ToString() : countryShortName + "_" + comboBox2.Text; CountryConfig.SystemRow sr1 = ccf.GetSystemRowByName(sn1); CountryConfig.SystemRow sr2 = ccf.GetSystemRowByName(sn2); if (sr1 == null) { throw new Exception("System '" + sn1 + "' does not exist!"); } if (sr2 == null) { throw new Exception("System '" + sn2 + "' does not exist!"); } if (hasAddon) { if (checkRadioData1.Checked || checkRadioDataBoth.Checked) { MergeAddOn(addonSystems, copiedCountry, ref sr1); } if (checkRadioData2.Checked || checkRadioDataBoth.Checked) { MergeAddOn(addonSystems, copiedCountry, ref sr2); } } copiedCountry.WriteXML(EMPath.Folder_Temp(EM_AppContext.FolderEuromodFiles)); if (checkBoxAlphaMII.Checked) { SystemBackgroundWorker w1, w2; w1 = RunSystem(countryShortName, sr1.Name, dbr1.Name, EM2_CreateConfig(countryShortName, textBoxOutputPath.Text, dbr1, sr1, true)); w2 = RunSystem(countryShortName, sr2.Name, dbr2.Name, EM2_CreateConfig(countryShortName, textBoxOutputPath.Text, dbr2, sr2, true)); w1.isBaseline = true; w2.isBaseline = true; w1.secondBaseline = w2; w2.secondBaseline = w1; workers.Add(w1); workers.Add(w2); updateInfoLabel(); } else { SystemBackgroundWorker w1 = null, w2 = null; if (checkRadioData1.Checked || checkRadioDataBoth.Checked) { w1 = RunSystem(countryShortName, sr1.Name, dbr1.Name, EM2_CreateConfig(countryShortName, textBoxOutputPath.Text, dbr1, sr1, hasAddon)); w1.isBaseline = true; } if (checkRadioData2.Checked || checkRadioDataBoth.Checked) { w2 = RunSystem(countryShortName, sr2.Name, dbr2.Name, EM2_CreateConfig(countryShortName, textBoxOutputPath.Text, dbr2, sr2, hasAddon)); w2.isBaseline = true; } if (hasAddon && checkRadioDataBoth.Checked) { w1.secondBaseline = w2; w2.secondBaseline = w1; } if (checkRadioData1.Checked || checkRadioDataBoth.Checked) { workers.Add(w1); } if (checkRadioData2.Checked || checkRadioDataBoth.Checked) { workers.Add(w2); } updateInfoLabel(); } } } }
static internal DataConfig.DBSystemConfigRow OvertakeDBSystemConfigRowFromAnotherCountry(DataConfig dataConfig, DataConfig.DBSystemConfigRow originalDBSystemConfigRow, DataConfig.DataBaseRow newDataBaseRow, CountryConfig.SystemRow newSystemRow, bool overtakeExtensionSwitches = true) { DataConfig.DBSystemConfigRow dbSystemConfigRow = dataConfig.DBSystemConfig.AddDBSystemConfigRow(newSystemRow.ID, newSystemRow.Name, newDataBaseRow, originalDBSystemConfigRow.UseDefault, originalDBSystemConfigRow.UseCommonDefault, originalDBSystemConfigRow.Uprate, originalDBSystemConfigRow.BestMatch); if (overtakeExtensionSwitches) { foreach (DataConfig.PolicySwitchRow extensionSwitchRow in originalDBSystemConfigRow.GetPolicySwitchRows()) { dataConfig.PolicySwitch.AddPolicySwitchRow(extensionSwitchRow.SwitchablePolicyID, newSystemRow.ID, newDataBaseRow.ID, extensionSwitchRow.Value); } } return(dbSystemConfigRow); }
static internal DataConfig.DataBaseRow CopyDataBaseRowFromAnotherCountry(DataConfig dataConfig, DataConfig.DataBaseRow originalDataBaseRow, bool keepID = false) { return(dataConfig.DataBase.AddDataBaseRow(keepID ? originalDataBaseRow.ID : Guid.NewGuid().ToString(), originalDataBaseRow.Name, originalDataBaseRow.Comment, originalDataBaseRow.YearCollection, originalDataBaseRow.YearInc, originalDataBaseRow.Currency, originalDataBaseRow.FilePath, originalDataBaseRow.DecimalSign, originalDataBaseRow.Private, originalDataBaseRow.UseCommonDefault, originalDataBaseRow.ReadXVariables, originalDataBaseRow.ListStringOutVar, originalDataBaseRow.IndirectTaxTableYear)); }
internal DataConfig.DBSystemConfigRow AddDBSystemConfigRow(string systemID, string sysName, DataConfig.DataBaseRow dataBaseRow) { return(_dataConfig.DBSystemConfig.AddDBSystemConfigRow(systemID, sysName, dataBaseRow, string.Empty, //UseDefault DefPar.Value.NO, //UseCommonDefault: parameter transferred to database-level, can be deleted once not used in any cc_DataConfig.xml anymore string.Empty, //Uprate DefPar.Value.NO)); //BestMatch }
internal override void PerformAction() { ConfigureDataForm configureDataForm = new ConfigureDataForm(_countryShortName); //firstly provide dialog with the information it needs to display (i.e. info on datasets and available system-dataset combinations) ... foreach (CountryConfig.SystemRow systemRow in CountryAdministrator.GetCountryConfigFacade(_countryShortName).GetSystemRows().OrderBy(s => long.Parse(s.Order))) { configureDataForm._systemInfo.Add(systemRow.ID, systemRow.Name); } foreach (DataConfig.DataBaseRow dataBaseRow in _dataConfigFacade.GetDataBaseRows()) { ConfigureDataForm.RowTag rowTag = new ConfigureDataForm.RowTag(); rowTag.ID = dataBaseRow.ID; rowTag.Name = dataBaseRow.Name; rowTag.Comment = dataBaseRow.Comment; rowTag.YearCollection = dataBaseRow.YearCollection; rowTag.YearInc = dataBaseRow.YearInc; rowTag.Currency = dataBaseRow.Currency; rowTag.FilePath = dataBaseRow.FilePath; rowTag.DecimalSign = dataBaseRow.DecimalSign; rowTag.Private = dataBaseRow.Private; rowTag.UseCommonDefault = dataBaseRow.UseCommonDefault; rowTag.ReadXVariables = string.IsNullOrEmpty(dataBaseRow.ReadXVariables) ? DefPar.Value.NO : dataBaseRow.ReadXVariables; rowTag.IsCommonDefaultNull = dataBaseRow.IsUseCommonDefaultNull(); rowTag.ListStringOutVar = dataBaseRow.ListStringOutVar; rowTag.IndirectTaxTableYear = dataBaseRow.IndirectTaxTableYear; foreach (DataConfig.DBSystemConfigRow dbSystemConfigRow in _dataConfigFacade.GetDBSystemConfigRows(dataBaseRow.ID)) { ConfigureDataForm.CellTag cellTag = new ConfigureDataForm.CellTag(); cellTag.SystemID = dbSystemConfigRow.SystemID; cellTag.UseDefault = dbSystemConfigRow.UseDefault; cellTag.UseCommonDefault = dbSystemConfigRow.UseCommonDefault; cellTag.Uprate = dbSystemConfigRow.Uprate; cellTag.BestMatch = dbSystemConfigRow.BestMatch; rowTag.CellTags.Add(dbSystemConfigRow.SystemID, cellTag); } configureDataForm._dataBaseInfo.Add(rowTag); } //... then show the dialog ... if (configureDataForm.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) { _actionIsCanceled = true; return; } //... finally store the modified information List <DataConfig.DataBaseRow> dataBaseRowsToDelete = new List <DataConfig.DataBaseRow>(); List <DataConfig.DBSystemConfigRow> dbSystemConfigRowsToDelete = new List <DataConfig.DBSystemConfigRow>(); foreach (ConfigureDataForm.RowTag dataBaseInfo in configureDataForm._dataBaseInfo) { DataConfig.DataBaseRow dataBaseRow = _dataConfigFacade.GetDataBaseRow(dataBaseInfo.ID); if (dataBaseInfo.ChangeState == ConfigureDataForm.ChangeStates.removed) { dataBaseRowsToDelete.Add(dataBaseRow); continue; } if (dataBaseInfo.ChangeState == ConfigureDataForm.ChangeStates.added) { dataBaseRow = _dataConfigFacade.AddDataBaseRow(dataBaseInfo.Name, dataBaseInfo.FilePath); _datasetAdded = true; } if (dataBaseInfo.ChangeState != ConfigureDataForm.ChangeStates.unchanged) { dataBaseRow.ID = dataBaseInfo.ID; dataBaseRow.Name = dataBaseInfo.Name; dataBaseRow.Comment = dataBaseInfo.Comment; dataBaseRow.YearCollection = dataBaseInfo.YearCollection; dataBaseRow.YearInc = dataBaseInfo.YearInc; dataBaseRow.Currency = dataBaseInfo.Currency; dataBaseRow.FilePath = dataBaseInfo.FilePath; dataBaseRow.DecimalSign = dataBaseInfo.DecimalSign; dataBaseRow.Private = dataBaseInfo.Private; dataBaseRow.UseCommonDefault = dataBaseInfo.UseCommonDefault; dataBaseRow.ReadXVariables = dataBaseInfo.ReadXVariables; dataBaseRow.ListStringOutVar = dataBaseInfo.ListStringOutVar; dataBaseRow.IndirectTaxTableYear = dataBaseInfo.IndirectTaxTableYear; } foreach (ConfigureDataForm.CellTag dbSystemCombination in dataBaseInfo.CellTags.Values) { DataConfig.DBSystemConfigRow dbSystemConfigRow = _dataConfigFacade.GetDBSystemConfigRow(dataBaseInfo.ID, dbSystemCombination.SystemID); if (dbSystemCombination.ChangeState == ConfigureDataForm.ChangeStates.removed) { dbSystemConfigRowsToDelete.Add(dbSystemConfigRow); continue; } if (dbSystemCombination.ChangeState == ConfigureDataForm.ChangeStates.added) { dbSystemConfigRow = _dataConfigFacade.AddDBSystemConfigRow(dbSystemCombination.SystemID, CountryAdministrator.GetCountryConfigFacade(_countryShortName).GetSystemRowByID(dbSystemCombination.SystemID).Name, dataBaseRow); } if (dbSystemCombination.ChangeState != ConfigureDataForm.ChangeStates.unchanged) { dbSystemConfigRow.SystemID = dbSystemCombination.SystemID; dbSystemConfigRow.UseDefault = dbSystemCombination.UseDefault; dbSystemConfigRow.UseCommonDefault = dbSystemCombination.UseCommonDefault; dbSystemConfigRow.Uprate = dbSystemCombination.Uprate; dbSystemConfigRow.BestMatch = dbSystemCombination.BestMatch; } } } foreach (DataConfig.DataBaseRow dataBaseRowToDelete in dataBaseRowsToDelete) { dataBaseRowToDelete.Delete(); } foreach (DataConfig.DBSystemConfigRow dbSystemConfigRowToDelete in dbSystemConfigRowsToDelete) { dbSystemConfigRowToDelete.Delete(); } }