static void GetCountryInfo_BackgroundEventHandler(object sender, DoWorkEventArgs e) { BackgroundWorker backgroundWorker = sender as BackgroundWorker; if (backgroundWorker.CancellationPending) { e.Result = null; e.Cancel = true; return; } //user pressed Cancel button: stop the process and allow progress indicator to set dialog result to Cancel try // this is just to read the country- and data-XML-files, not to do anything with them or store the ConfigFacades { // the CountryAdministrator will keept them in memory and thus quick-access by the RVTable-derived classes is possible List <string> countries = e.Argument as List <string>; List <int> faultyCountries = new List <int>(); for (int i = 0; i < countries.Count; ++i) { if (CountryAdministrator.GetCountryConfigFacade(countries[i]) == null || CountryAdministrator.GetDataConfigFacade(countries[i]) == null) { faultyCountries.Add(i); } backgroundWorker.ReportProgress(Convert.ToInt32((i + 1.0) / (countries.Count * 1.0) * 100.0)); } for (int f = faultyCountries.Count - 1; f >= 0; --f) { countries.RemoveAt(f); } e.Result = countries; } catch (Exception exception) { e.Result = exception.Message; backgroundWorker.ReportProgress(100); } }
internal override void PerformValidation(List <string> countries, bool showProblemsOnly) { base.PerformValidation(countries, showProblemsOnly); string noHICP = string.Empty, notDollarF = string.Empty, emptyFactors = string.Empty, zeroFactors = string.Empty, noYearForSystem = string.Empty, noYearForData = string.Empty, noIncomeYear = string.Empty; foreach (string country in countries) { CountryConfigFacade ccf = CountryAdministrator.GetCountryConfigFacade(country); DataConfigFacade dcf = CountryAdministrator.GetDataConfigFacade(country); List <CountryConfig.UpratingIndexRow> indices = (from ui in ccf.GetUpratingIndices() select ui).ToList(); List <CountryConfig.SystemRow> publicSystems = GetPublicSystems(country); List <DataConfig.DataBaseRow> datasets = (from d in dcf.GetDataBaseRows() where d.Private != DefPar.Value.YES select d).ToList(); List <string> indexYears = ccf.GetAllUpratingIndexYears(); RegisterProblems(country, NotDollarF(indices), ref notDollarF); RegisterProblems(country, NoYearForSystem(publicSystems, indexYears), ref noYearForSystem); RegisterProblems(country, NoYearForData(datasets, indexYears), ref noYearForData); RegisterProblems(country, NoIncomeYear(datasets), ref noIncomeYear); RegisterProblems(country, EmptyFactors(ccf, indices, false), ref emptyFactors); RegisterProblems(country, EmptyFactors(ccf, indices, true), ref zeroFactors); } AddDataGridRow("Factors not starting with $f_", notDollarF); AddDataGridRow("Systems for which factor-table does not provide year", noYearForSystem); AddDataGridRow("Databases for which factor-table does not provide year", noYearForData); AddDataGridRow("Databases with undefined income year", noIncomeYear); AddDataGridRow("Factors with empty values", emptyFactors); AddDataGridRow("Factors with zero values (warning)", zeroFactors); }
internal static void SaveDirectXMLAction(EM_UI_MainForm mainForm) { string countryShortName = mainForm.GetCountryShortName(); CountryAdministrator.GetCountryConfigFacade(countryShortName).GetCountryConfig().AcceptChanges(); if (!CountryAdministrator.IsAddOn(countryShortName)) { CountryAdministrator.GetDataConfigFacade(countryShortName).GetDataConfig().AcceptChanges(); } mainForm.GetUndoManager().Reset(); //reset undo-manager with the drawback that actions up until now cannot be undone lock (EM_UI_MainForm._performActionLock) //to not get into conflict with auto-saving { CountryAdministrator.WriteXML(countryShortName); } }
internal override void PerformAction() { SetExtensionSwitchesForm setSwitchesDialog = new SetExtensionSwitchesForm(_cc); if (setSwitchesDialog.ShowDialog() == DialogResult.Cancel) { _actionIsCanceled = true; return; } //store the redefined switches in the data-config foreach (ExtensionSwitchDefaultValue extensionSwitchDefaultValue in setSwitchesDialog.GetExtensionDefaultSwitches()) { ExtensionAndGroupManager.SetExtensionDefaultSwitch(CountryAdministrator.GetDataConfigFacade(_cc).GetDataConfig(), extensionSwitchDefaultValue._dbSystemConfigRow, extensionSwitchDefaultValue._extensionID, extensionSwitchDefaultValue._defaultValue); } //remove any "relics", i.e. default values of switchable policies, which were deleted ExtensionAndGroupManager.ExtensionDefaultSwitches_RemoveRelics(_cc); }
internal SetExtensionSwitchesForm(string countryShortName) { InitializeComponent(); try { _countryShortName = countryShortName; labelCountry.Text = _countryShortName; _dataConfig = CountryAdministrator.GetDataConfigFacade(_countryShortName).GetDataConfig(); _extensionDefaultSwitches = new List <ExtensionSwitchDefaultValue>(); foreach (GlobLocExtensionRow e in ExtensionAndGroupManager.GetExtensions(_countryShortName)) { ListViewItem item = lvSwitchablePolicies.Items.Add(e.Name); item.SubItems.Add(e.ShortName); item.Tag = e.ID; //store initial default values of the policy switches in this structure, //which is necessary as the dialog changes between switchable policies and the changed values need to be buffered //(actual database changes are performed after closing the dialog with OK) foreach (DataConfig.DataBaseRow dataBaseRow in from db in _dataConfig.DataBase select db) { foreach (DataConfig.DBSystemConfigRow dbSystemConfigRow in from ds in _dataConfig.DBSystemConfig where ds.DataBaseID == dataBaseRow.ID select ds) { _extensionDefaultSwitches.Add(new ExtensionSwitchDefaultValue(e.ID, dbSystemConfigRow, ExtensionAndGroupManager.GetExtensionDefaultSwitch(dbSystemConfigRow, e.ID))); //returns n/a if switch does not (yet) exist } } } InitSwitchTable(); //draw columns (systems) and rows (datasets) of the table if (lvSwitchablePolicies.Items.Count > 0) { lvSwitchablePolicies.Items[0].Checked = true; //select the first switchable policy } UpdateSwitchTable(); //fill the table with the switch values of this policy } catch (Exception exception) { UserInfoHandler.ShowException(exception); } }
void Generate_BackgroundEventHandler(object sender, System.ComponentModel.DoWorkEventArgs e) { try { BackgroundWorker backgroundWorker = sender as BackgroundWorker; //gather the country-configs of the selected countries, to be used by the tabel filling functions List <CountryConfigFacade> countryConfigFacades = new List <CountryConfigFacade>(); List <DataConfigFacade> dataConfigFacades = new List <DataConfigFacade>(); int actionCounter = 0; List <string> selectedCountries = e.Argument as List <string>; foreach (string countryShortName in selectedCountries) { if (backgroundWorker.CancellationPending) { e.Cancel = true; return; } //user pressed Cancel button countryConfigFacades.Add(CountryAdministrator.GetCountryConfigFacade(countryShortName)); dataConfigFacades.Add(CountryAdministrator.GetDataConfigFacade(countryShortName)); backgroundWorker.ReportProgress(Convert.ToInt32((actionCounter++ + 1) / (selectedCountries.Count * 1.0) * 100.0)); } //rather difficult to put two-fold information in the result-object, but List<object> works List <object> configFacades = new List <object>(); configFacades.Add(countryConfigFacades); configFacades.Add(dataConfigFacades); e.Result = configFacades; } catch (Exception exception) { e.Cancel = true; UserInfoHandler.ShowException(exception); } }
internal static List <SystemAndData> AssessData(List <CountryConfig.SystemRow> systems, string country) { List <SystemAndData> systemsAndData = new List <SystemAndData>(); DataConfigFacade dcf = CountryAdministrator.GetDataConfigFacade(country); foreach (CountryConfig.SystemRow sys in systems) { SystemAndData sad = new SystemAndData(sys); foreach (DataConfig.DBSystemConfigRow dbs in dcf.GetDBSystemConfigRowsBySystem(sys.Name)) { if (dbs.DataBaseRow.Private == DefPar.Value.YES) { continue; // do not take-up private data into this structure !!! } sad.allData.Add(dbs); if (dbs.BestMatch == DefPar.Value.YES) { sad.bestMatches.Add(dbs); } } systemsAndData.Add(sad); } return(systemsAndData); }
private static DataConfig GetDataConfig(string cc) { return(CountryAdministrator.GetDataConfigFacade(cc).GetDataConfig()); }
void AssessCountryInfo() { rvCountryInfo = new List <RVCountryInfo>(); systemYears = new List <int>(); systemYearsPublic = new List <int>(); CountryConfigFacade ccfMTR = CountryAdministrator.GetCountryConfigFacade("MTR"); CountryConfigFacade ccfLMA = CountryAdministrator.GetCountryConfigFacade("LMA"); CountryConfigFacade ccfNRR = CountryAdministrator.GetCountryConfigFacade("NRR"); foreach (string country in countries) { CountryConfigFacade ccf = CountryAdministrator.GetCountryConfigFacade(country); DataConfigFacade dcf = CountryAdministrator.GetDataConfigFacade(country); RVCountryInfo ccInfo = new RVCountryInfo(country); List <int> ccSystemYearsPublic = new List <int>(); foreach (CountryConfig.SystemRow system in CountryAdministrator.GetCountryConfigFacade(country).GetSystemRows()) { int year = RVItem_SystemConfiguration.GetSystemYear(system); if (year == -1) { continue; } bool isPrivate = system.Private == DefPar.Value.YES; if (!ccInfo.systemYearInfo.ContainsKey(year)) { ccInfo.systemYearInfo.Add(year, isPrivate); } else if (ccInfo.systemYearInfo[year] == true) { ccInfo.systemYearInfo[year] = isPrivate; // if there is a public and a private system for the year, let the public dominate } if (!systemYears.Contains(year)) { systemYears.Add(year); } if (!isPrivate) { ccSystemYearsPublic.Add(year); if (!systemYearsPublic.Contains(year)) { systemYearsPublic.Add(year); } } List <DataConfig.DBSystemConfigRow> bm = (from d in dcf.GetDataConfig().DBSystemConfig where d.SystemID == system.ID & d.BestMatch == DefPar.Value.YES select d).ToList(); if (bm.Count > 0 && !ccInfo.bestMatchInfo.ContainsKey(year)) { ccInfo.bestMatchInfo.Add(year, bm.First().DataBaseRow.Name); } } //ccInfo.privateComponents = (from p in ccf.GetPolicyRowsOrderedAndDistinct() // where p.Private == DefPar.Value.YES select p.Name).ToList(); int oPol = 0; foreach (CountryConfig.PolicyRow pol in ccf.GetPolicyRowsOrderedAndDistinct()) { ++oPol; int oFun = 0; string privFun = string.Empty; ccInfo.idOrderInfo.Add(pol.ID, $"{oPol}"); if (pol.Private == DefPar.Value.YES) { ccInfo.privatePolicies.Add(string.Format("{0} {1}", oPol, pol.Name)); continue; } foreach (CountryConfig.FunctionRow fun in (from f in pol.GetFunctionRows() select f).OrderBy(f => long.Parse(f.Order))) { ++oFun; int oPar = 0; string privPar = string.Empty; ccInfo.idOrderInfo.Add(fun.ID, $"{oPol}.{oFun}"); if (fun.Private == DefPar.Value.YES) { privFun += string.Format("{0} {1} ", oFun, fun.Name); continue; } foreach (CountryConfig.ParameterRow par in (from p in fun.GetParameterRows() select p).OrderBy(p => long.Parse(p.Order))) { ++oPar; ccInfo.idOrderInfo.Add(par.ID, $"{oPol}.{oFun}.{oPar}"); if (par.Private == DefPar.Value.YES) { privPar += string.Format("{0} {1} ", oPar, par.Name); continue; } } if (privPar != string.Empty) { ccInfo.privateParameters.Add(string.Format("{0}.{1} {2}/{3}/...: {4}", oPol.ToString(), oFun.ToString(), pol.Name, fun.Name, privPar)); } } if (privFun != string.Empty) { ccInfo.privateFunctions.Add(string.Format("{0} {1}/...: {2}", oPol, pol.Name, privFun)); } } foreach (DataConfig.DataBaseRow data in dcf.GetDataBaseRows()) { if (ccInfo.dataInfo.ContainsKey(data.Name)) { continue; } bool isPrivate = data.Private == DefPar.Value.YES; ccInfo.dataInfo.Add(data.Name, isPrivate); if (data.Name.ToLower().StartsWith("training")) { ccInfo.hasTrainingData = true; ccInfo.isTrainingPublic = !isPrivate; } if (data.Name.ToLower().StartsWith("hypo")) { ccInfo.hasHypoData = true; } if (isPrivate) { continue; } ccInfo.dataNA.Add(data.Name, new List <string>()); if (!data.Name.ToLower().Contains("hhot")) { foreach (int systemYearPublic in ccSystemYearsPublic) { bool isAvailable = false; foreach (DataConfig.DBSystemConfigRow dbs in dcf.GetDBSystemConfigRows(data.ID)) { CountryConfig.SystemRow systemRow = CountryAdministrator.GetCountryConfigFacade(country).GetSystemRowByName(dbs.SystemName); if (RVItem_SystemConfiguration.GetSystemYear(systemRow) == systemYearPublic) { isAvailable = true; break; } } if (!isAvailable) { ccInfo.dataNA[data.Name].Add(systemYearPublic.ToString()); } } } } foreach (string extId in (from s in dcf.GetDataConfig().PolicySwitch select s.SwitchablePolicyID).Distinct()) { AssessExtensionInfo(ccf, dcf, extId, DefPar.Value.ON, ref ccInfo.switchInfoOn); AssessExtensionInfo(ccf, dcf, extId, DefPar.Value.OFF, ref ccInfo.switchInfoOff); } AssessExtensionContent(ccf, dcf, ccInfo.idOrderInfo, ref ccInfo.extensionContent); foreach (DataConfig.ExtensionRow er in dcf.GetDataConfig().Extension) { ; } foreach (GlobLocExtensionRow er in ExtensionAndGroupManager.GetLocalExtensions(ccInfo.country)) { countriesExtensionInfo.Add(new Tuple <string, string, bool>(er.ID, er.Name, IsWholeContentPrivate(ccf.GetCountryConfig(), er.ID))); } ccInfo.mtrImplemented = AddOnImplemented(ccfMTR, country, "mtr"); ccInfo.lmaImplemented = AddOnImplemented(ccfLMA, country, "lma"); ccInfo.nrrImplemented = AddOnImplemented(ccfNRR, country, "nrr"); rvCountryInfo.Add(ccInfo); } systemYears.Sort(); systemYearsPublic.Sort(); }
private void EM3_WriteLog() { List <RunLogger.RunInfo> runInfoList = new List <RunLogger.RunInfo>(); foreach (Run run in _runs) { // some info needs to be looked up in country-files string country = run._contentConfig[TAGS.EM2CONFIG_COUNTRY_FILE]; if (country.ToLower().EndsWith(".xml")) { country = country.Substring(0, country.Length - 4); } CountryConfigFacade ccf = CountryAdministrator.GetCountryConfigFacade(country); DataConfigFacade dcf = CountryAdministrator.GetDataConfigFacade(country); string sysID = (from e in run._contentConfig where e.Key.StartsWith(TAGS.EM2CONFIG_SYSTEM_ID) select e.Value).FirstOrDefault(); // SYSTEM_ID is followed by a GUID string dataID = run._contentConfig[TAGS.EM2CONFIG_DATASET_ID]; if (!EM_AppContext.Instance._runExeViaLib && run._process != null) { run.em3RunInfo.duration = new RunLogger.Duration(run._process.StartTime, run._process.ExitTime); run.em3RunInfo.finishStatus = run._processStatus == Run._processStatus_Finished ? RunLogger.RunInfo.FINISH_STATUS.finished : RunLogger.RunInfo.FINISH_STATUS.aborted; } run.em3RunInfo.systemName = ccf.GetSystemRowByID(sysID).Name; run.em3RunInfo.ExtractAddonSystemNames(run._contentConfig, TAGS.EM2CONFIG_ADDON); run.em3RunInfo.databaseName = dcf.GetDataBaseRow(dataID).Name; run.em3RunInfo.currency = run._contentConfig.ContainsKey(TAGS.EM2CONFIG_EXCHANGE_RATE_DATE) ? DefPar.Value.EURO : ccf.GetSystemRowByID(sysID).CurrencyOutput; // config contains entry EXCHANGE_RATE_DATE only if "All Output in €" is checked run.em3RunInfo.exchangeRate = GetExchangeRate(run, country, ccf.GetSystemRowByID(sysID).Name); run.em3RunInfo.ExtractExtensionSwitches(run._contentConfig, TAGS.EM2CONFIG_POLICY_SWITCH); string runOutputPath = run._contentConfig.GetOrEmpty(TAGS.EM2CONFIG_OUTPUTPATH); if (!string.IsNullOrEmpty(runOutputPath) && !EMPath.IsSamePath(runOutputPath, _outputPath)) { run.em3RunInfo.nonDefaultOutputPath = runOutputPath; } runInfoList.Add(run.em3RunInfo); } new RunLogger(EM_AppContext.Instance.GetProjectName(), runInfoList).TxtWriteEMLog(_outputPath); string GetExchangeRate(Run run, string country, string sysName) { ExchangeRatesConfigFacade excf = EM_AppContext.Instance.GetExchangeRatesConfigFacade(false); if (excf == null) { return(Dialogs.ConfigureSystemsForm.DEFAULT_EXCHANGE_RATE); } foreach (ExchangeRatesConfig.ExchangeRatesRow exRate in excf.GetExchangeRates(country)) { if (!exRate.ValidFor.ToLower().Trim().EndsWith(sysName.ToLower()) && !exRate.ValidFor.ToLower().Contains(sysName.ToLower() + ",")) { continue; } string date = run._contentConfig.ContainsKey(TAGS.EM2CONFIG_EXCHANGE_RATE_DATE) && run._contentConfig[TAGS.EM2CONFIG_EXCHANGE_RATE_DATE].ToLower() != "default" ? run._contentConfig[TAGS.EM2CONFIG_EXCHANGE_RATE_DATE].ToLower() : exRate.Default.ToLower(); double value = 1.0; if (date.StartsWith("june")) { value = exRate.June30; } else if (date.StartsWith("year")) { value = exRate.YearAverage; } else if (date.StartsWith("first")) { value = exRate.FirstSemester; } else if (date.StartsWith("second")) { value = exRate.SecondSemester; } return(value.ToString()); } return(Dialogs.ConfigureSystemsForm.DEFAULT_EXCHANGE_RATE); } }
internal override void PerformAction() { DataConfig dataConfig = CountryAdministrator.GetDataConfigFacade(cc).GetDataConfig(); List <ExtensionOrGroup> extensions = new List <ExtensionOrGroup>(); foreach (DataConfig.ExtensionRow ext in from e in dataConfig.Extension select e) { extensions.Add(new ExtensionOrGroup(ext)); } using (AdminExtensionsOrGroupsForm adminDialog = new AdminExtensionsOrGroupsForm("Administrate Country Specific Extensions", extensions)) { if (adminDialog.ShowDialog() == DialogResult.Cancel) { actionIsCanceled = true; return; } foreach (ExtensionOrGroup addEx in adminDialog.added) { dataConfig.Extension.AddExtensionRow(Guid.NewGuid().ToString(), addEx.name, addEx.shortName, addEx.look.ToXml()); } foreach (ExtensionOrGroup changeEx in adminDialog.changed) { DataConfig.ExtensionRow exRow = (from e in dataConfig.Extension where e.ID == changeEx.id select e).First(); exRow.Name = changeEx.name; exRow.ShortName = changeEx.shortName; exRow.Look = changeEx.look.ToXml(); } List <DataConfig.ExtensionRow> ex = (from e in dataConfig.Extension select e).ToList(); for (int i = ex.Count - 1; i >= 0; --i) { if (adminDialog.deletedIds.Contains(ex[i].ID)) { ex[i].Delete(); } } // prepare for DoAfterCommitWork (updating tree) CountryConfig countryConfig = CountryAdministrator.GetCountryConfigFacade(cc).GetCountryConfig(); foreach (string polID in from ep in countryConfig.Extension_Policy where adminDialog.deletedIds.Contains(ep.ExtensionID) select ep.PolicyID) { delExPolRows.Add((from p in countryConfig.Policy where p.ID == polID select p).FirstOrDefault()); } foreach (string funID in from ef in countryConfig.Extension_Function where adminDialog.deletedIds.Contains(ef.ExtensionID) select ef.FunctionID) { delExFunRows.Add((from f in countryConfig.Function where f.ID == funID select f).FirstOrDefault()); } // deleteExtensionContent List <CountryConfig.Extension_PolicyRow> delPolicyRows = new List <CountryConfig.Extension_PolicyRow>(); List <CountryConfig.Extension_FunctionRow> delFunctionRows = new List <CountryConfig.Extension_FunctionRow>(); List <CountryConfig.Extension_ParameterRow> delParameterRows = new List <CountryConfig.Extension_ParameterRow>(); foreach (string extensionID in adminDialog.deletedIds) { delPolicyRows.AddRange((from pe in countryConfig.Extension_Policy where pe.ExtensionID == extensionID select pe).ToList()); delFunctionRows.AddRange((from fe in countryConfig.Extension_Function where fe.ExtensionID == extensionID select fe).ToList()); delParameterRows.AddRange((from pe in countryConfig.Extension_Parameter where pe.ExtensionID == extensionID select pe).ToList()); } for (int i = delPolicyRows.Count - 1; i >= 0; --i) { delPolicyRows[i].Delete(); } for (int i = delFunctionRows.Count - 1; i >= 0; --i) { delFunctionRows[i].Delete(); } for (int i = delParameterRows.Count - 1; i >= 0; --i) { delParameterRows[i].Delete(); } } }
void DeleteSystem_MenuItemClick(object sender, EventArgs e) { _mainForm.PerformAction(new DeleteSystemAction(_senderColumn, CountryAdministrator.GetDataConfigFacade(_mainForm.GetCountryShortName())), true, true); }