private static void SetPrivate_BackgroundEventHandler(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker backgroundWorker = sender as BackgroundWorker; if (backgroundWorker.CancellationPending)
            {
                e.Cancel = true; return;
            }
            Tuple <string, bool> settings = e.Argument as Tuple <string, bool>; string extName = settings.Item1; bool set = settings.Item2;

            try
            {
                List <Country> countries = CountryAdministrator.GetCountries();
                for (int i = 0; i < countries.Count; ++i)
                {
                    if (backgroundWorker.CancellationPending)
                    {
                        e.Cancel = true; return;
                    }
                    Country country = countries[i]; CountryConfigFacade ccf = country.GetCountryConfigFacade();
                    ExtensionSetPrivateAction action = new ExtensionSetPrivateAction(extName, countries[i]._shortName, set);
                    action.PerformAction();
                    if (!action.ActionIsCanceled()) // happens if extension has no content
                    {
                        country.WriteXML(); country.SetCountryConfigFacade(null); country.SetDataConfigFacade(null);
                    }
                    backgroundWorker.ReportProgress(Convert.ToInt32((i + 1.0) / (countries.Count * 1.0) * 100.0));
                }
                if (backgroundWorker.CancellationPending)
                {
                    e.Cancel = true; return;
                }
            }
            catch (Exception exception) { UserInfoHandler.ShowException(exception); e.Cancel = true; }
        }
        private static void Migrate_BackgroundEventHandler(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            BackgroundWorker backgroundWorker = sender as BackgroundWorker;

            try
            {
                List <Country> countries = CountryAdministrator.GetCountries();
                for (int i = 0; i < countries.Count; ++i)
                {
                    if (backgroundWorker.CancellationPending)
                    {
                        e.Result = null; e.Cancel = true; return;
                    }

                    CountryConfigFacade ccf = countries[i].GetCountryConfigFacade(); if (ccf == null)
                    {
                        continue;
                    }
                    countries[i].WriteXML();

                    backgroundWorker.ReportProgress(Convert.ToInt32((i + 1.0) / (countries.Count * 1.0) * 100.0));
                }
            }
            catch (Exception exception) { e.Result = exception.Message; backgroundWorker.ReportProgress(100); }
        }
Esempio n. 3
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); }
        }
        public ExtractProjectForm()
        {
            InitializeComponent();

            foreach (Country c in CountryAdministrator.GetCountries())
            {
                lstCountries.Items.Add(c._shortName);
            }
            FillInYears();
        }
Esempio n. 5
0
        internal UpdatingProgressForm()
        {
            InitializeComponent();

            txtFolder.Text = EM_AppContext.FolderOutput;

            foreach (Country country in CountryAdministrator.GetCountries())
            {
                lstCountries.Items.Add(country._shortName);
            }
        }
        static void GetCountryExchangeRates_BackgroundEventHandler(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker backgroundWorker = sender as BackgroundWorker;

            try
            {
                List <ExchangeRate> exRates   = new List <ExchangeRate>();
                List <Country>      countries = CountryAdministrator.GetCountries();
                for (int i = 0; i < countries.Count; ++i)
                {
                    if (backgroundWorker.CancellationPending)
                    {
                        e.Result = null; e.Cancel = true; return;
                    }

                    CountryConfigFacade ccf = countries[i].GetCountryConfigFacade(); if (ccf == null)
                    {
                        continue;
                    }
                    Dictionary <double, string> sysRates = new Dictionary <double, string>();
                    foreach (CountryConfig.SystemRow system in ccf.GetSystemRows())
                    {
                        if (system.IsExchangeRateEuroNull())
                        {
                            continue;                                  // rather unlikely
                        }
                        double rate; if (!double.TryParse(system.ExchangeRateEuro, out rate))
                        {
                            continue;                                                                   // also rather unlikely
                        }
                        if (sysRates.ContainsKey(rate))
                        {
                            sysRates[rate] = ExchangeRate.AddToValidFor(sysRates[rate], system.Name);
                        }
                        else
                        {
                            sysRates.Add(rate, system.Name.ToLower());
                        }
                    }
                    foreach (var sr in sysRates)
                    {
                        ExchangeRate exRatesCY = new ExchangeRate()
                        {
                            Country = countries[i]._shortName, June30 = sr.Key, ValidFor = sr.Value
                        };
                        exRates.Add(exRatesCY);
                    }
                    backgroundWorker.ReportProgress(Convert.ToInt32((i + 1.0) / (countries.Count * 1.0) * 100.0));
                }
                e.Result = exRates;
            }
            catch (Exception exception) { e.Result = exception.Message; backgroundWorker.ReportProgress(100); }
        }
Esempio n. 7
0
        internal SaveParameterFilesAsTextForm()
        {
            InitializeComponent();

            txtFolder.Text = EM_AppContext.FolderOutput;

            foreach (Country country in CountryAdministrator.GetCountries())
            {
                lvCountries.Items.Add(country._shortName);
            }

            CheckCountries(true);
        }
Esempio n. 8
0
        public RVConfigurationForm(List <string> validationItems)
        {
            InitializeComponent();

            foreach (Country country in CountryAdministrator.GetCountries())
            {
                lstCountries.Items.Add(country._shortName);
            }
            btnAllNo_Click(btnAllCountries);

            foreach (string validationItem in validationItems)
            {
                lstValidationItems.Items.Add(validationItem);
            }
            btnAllNo_Click(btnAllItems);

            txtInfoOutputFolder.Text = EM_AppContext.FolderOutput;
            txtInfoOutputFile.Text   = "ReleaseInfo.xlsx";
            txtDataFolder.Text       = EM_AppContext.FolderInput;
        }
Esempio n. 9
0
        static List <string> LoadCountryConfigFacades(RVConfigurationForm rvConfigurationForm)
        {
            // if validation is to be performed: load the selected countries only; if info-file is to be generated: load all countries
            List <string> countries = rvConfigurationForm.selectedFunction == RVConfigurationForm.CREATE_INFO_FILE
                ? (from c in CountryAdministrator.GetCountries() select c._shortName).ToList() : rvConfigurationForm.countries;

            //the handler passed to the progress indicator will do the work (see below)
            ProgressIndicator progressIndicator = new ProgressIndicator(GetCountryInfo_BackgroundEventHandler, "Assessing Country Info ...", countries);

            if (progressIndicator.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return(null);                                                                        // user pressed Cancel
            }
            List <string> result = progressIndicator.Result as List <string>;

            if (result == null) // an exception was thrown while loading countries
            {
                UserInfoHandler.ShowError(string.Format("Validation failed with the following error:{0}{1}", Environment.NewLine, progressIndicator.Result.ToString()));
                return(null);
            }
            return(result); // overtake the perhaps now shorter list of countries (due to non-ability to load a country)
        }
        static void GetCountryHICPs_BackgroundEventHandler(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker backgroundWorker = sender as BackgroundWorker;

            try
            {
                List <Tuple <string, int, double, string> > hicps = new List <Tuple <string, int, double, string> >();
                List <Country> countries = CountryAdministrator.GetCountries();
                for (int i = 0; i < countries.Count; ++i)
                {
                    if (backgroundWorker.CancellationPending)
                    {
                        e.Result = null; e.Cancel = true; return;
                    }

                    CountryConfigFacade ccf = countries[i].GetCountryConfigFacade(); if (ccf == null)
                    {
                        continue;
                    }
                    CountryConfig.UpratingIndexRow hicp = ccf.GetUpratingIndex("$HICP"); if (hicp == null)
                    {
                        continue;
                    }
                    // put parameter values into structure that can be stored in HICP table
                    List <Tuple <string, int, double, string> > hicpsCC = new List <Tuple <string, int, double, string> >();
                    foreach (var yv in ccf.GetUpratingIndexYearValues(hicp))
                    {
                        hicpsCC.Add(new Tuple <string, int, double, string>(countries[i]._shortName, yv.Key, yv.Value, hicp.Comment));
                    }
                    hicps.AddRange(hicpsCC);

                    backgroundWorker.ReportProgress(Convert.ToInt32((i + 1.0) / (countries.Count * 1.0) * 100.0));
                }
                e.Result = hicps;
            }
            catch (Exception exception) { e.Result = exception.Message; backgroundWorker.ReportProgress(100); }
        }
Esempio n. 11
0
        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
            {
                double i = 0; Dictionary <string, List <string> > cmpInfo = new Dictionary <string, List <string> >();
                foreach (Country cLoc in CountryAdministrator.GetCountries())
                {
                    backgroundWorker.ReportProgress(Convert.ToInt32(i / CountryAdministrator.GetCountries().Count * 100.0)); ++i;

                    CountryConfigFacade ccfLoc = cLoc.GetCountryConfigFacade(); if (ccfLoc == null)
                    {
                        continue;
                    }
                    DataConfigFacade dcfLoc = cLoc.GetDataConfigFacade(); if (dcfLoc == null)
                    {
                        continue;
                    }

                    string cmpCountryFolder = e.Argument.ToString() + cLoc._shortName; if (!Directory.Exists(cmpCountryFolder))
                    {
                        continue;
                    }
                    Country             cCmp   = new Country(); cCmp._shortName = cLoc._shortName;
                    CountryConfigFacade ccfCmp = cCmp.GetCountryConfigFacade(true, cmpCountryFolder); if (ccfCmp == null)
                    {
                        continue;
                    }
                    DataConfigFacade dcfCmp = cCmp.GetDataConfigFacade(true, cmpCountryFolder); if (dcfCmp == null)
                    {
                        continue;
                    }

                    string        addData = string.Empty, addSys = string.Empty, addPol = string.Empty, delData = string.Empty, delSys = string.Empty, delPol = string.Empty;
                    List <string> cmpData = new List <string>(), cmpSys = new List <string>(), cmpPol = new List <string>();

                    foreach (DataConfig.DataBaseRow d in dcfCmp.GetDataBaseRows())
                    {
                        cmpData.Add(d.Name.EndsWith(".txt") ? d.Name.ToLower() : (d.Name + ".txt").ToLower());
                    }
                    foreach (CountryConfig.SystemRow s in ccfCmp.GetSystemRows())
                    {
                        cmpSys.Add(s.Name.ToLower());
                    }
                    if (cmpSys.Count > 0)
                    {
                        foreach (CountryConfig.PolicyRow p in ccfCmp.GetSystemRows().First().GetPolicyRows())
                        {
                            if (!p.Name.ToLower().StartsWith(UpratingIndices.UpratingIndicesForm._policyUprateFactors_Name))
                            {
                                cmpPol.Add(p.Name.ToLower());
                            }
                        }
                    }

                    foreach (DataConfig.DataBaseRow d in dcfLoc.GetDataBaseRows())
                    {
                        string dataName = d.Name.EndsWith(".txt") ? d.Name.ToLower() : (d.Name + ".txt").ToLower();
                        if (cmpData.Contains(dataName))
                        {
                            cmpData.Remove(dataName);
                        }
                        else
                        {
                            addData += dataName + ", ";
                        }
                    }
                    foreach (string d in cmpData)
                    {
                        if (d != string.Empty)
                        {
                            delData += d + ", ";
                        }
                    }

                    foreach (CountryConfig.SystemRow s in ccfLoc.GetSystemRows())
                    {
                        if (cmpSys.Contains(s.Name.ToLower()))
                        {
                            cmpSys.Remove(s.Name.ToLower());
                        }
                        else
                        {
                            addSys += s.Name.ToLower() + ", ";
                        }
                    }
                    foreach (string s in cmpSys)
                    {
                        if (s != string.Empty)
                        {
                            delSys += s + ", ";
                        }
                    }

                    if (ccfLoc.GetSystemRows().Count > 0)
                    {
                        foreach (CountryConfig.PolicyRow p in ccfLoc.GetSystemRows().First().GetPolicyRows())
                        {
                            if (p.Name.ToLower().StartsWith(UpratingIndices.UpratingIndicesForm._policyUprateFactors_Name))
                            {
                                continue;
                            }
                            if (cmpPol.Contains(p.Name.ToLower()))
                            {
                                cmpPol.Remove(p.Name.ToLower());
                            }
                            else
                            {
                                addPol += p.Name.ToLower() + ", ";
                            }
                        }
                    }
                    foreach (string p in cmpPol)
                    {
                        if (p != string.Empty)
                        {
                            delPol += p + ", ";
                        }
                    }

                    char[] t = new char[] { ',', ' ' };
                    cmpInfo.Add(cLoc._shortName, new List <string>()
                    {
                        addData.TrimEnd(t), delData.TrimEnd(t), addSys.TrimEnd(t), delSys.TrimEnd(t), addPol.TrimEnd(t), delPol.TrimEnd(t)
                    });
                }

                backgroundWorker.ReportProgress(100);
                e.Result = cmpInfo;
            }
            catch (Exception exception) { e.Result = exception.Message; backgroundWorker.ReportProgress(100); }
        }
        internal ExchangeRatesForm(List <ExchangeRatesConfig.ExchangeRatesRow> exRates)
        {
            InitializeComponent();

            try
            {
                if (!dgvRates.InitDataSource())
                {
                    ShowGridLastError(); return;
                }
                dgvRates.allowAddRows     = false; dgvRates.showDelRowWarning = true;
                dgvRates.pasteableColumns = new List <string>()
                {
                    this.colJune30.Name,
                    this.colYearAverage.Name,
                    this.colFirstSemester.Name,
                    this.colSecondSemester.Name
                };

                if (!dgvRates.AddColumn(false, colCountry.Name, typeof(string)))
                {
                    ShowGridLastError(); return;
                }
                if (!dgvRates.AddColumn(false, colJune30.Name, typeof(double)))
                {
                    ShowGridLastError(); return;
                }
                if (!dgvRates.AddColumn(false, colYearAverage.Name, typeof(double)))
                {
                    ShowGridLastError(); return;
                }
                if (!dgvRates.AddColumn(false, colFirstSemester.Name, typeof(double)))
                {
                    ShowGridLastError(); return;
                }
                if (!dgvRates.AddColumn(false, colSecondSemester.Name, typeof(double)))
                {
                    ShowGridLastError(); return;
                }
                if (!dgvRates.AddColumn(false, colDefault.Name, typeof(string)))
                {
                    ShowGridLastError(); return;
                }
                if (!dgvRates.AddColumn(false, colValidFor.Name, typeof(string)))
                {
                    ShowGridLastError(); return;
                }
                if (!dgvRates.AddColumn(false, colID.Name, typeof(Int16), -1, true))
                {
                    ShowGridLastError(); return;
                }

                foreach (ExchangeRatesConfig.ExchangeRatesRow exRate in exRates)
                {
                    DataRow dataRow;
                    if (!dgvRates.AddRow(false, out dataRow))
                    {
                        ShowGridLastError(); return;
                    }
                    if (!dgvRates.SetCellValue(dataRow, colCountry.Name, exRate.Country))
                    {
                        ShowGridLastError(); return;
                    }
                    if (exRate.June30 > 0)
                    {
                        if (!dgvRates.SetCellValue(dataRow, colJune30.Name, exRate.June30))
                        {
                            ShowGridLastError(); return;
                        }
                    }
                    if (exRate.YearAverage > 0)
                    {
                        if (!dgvRates.SetCellValue(dataRow, colYearAverage.Name, exRate.YearAverage))
                        {
                            ShowGridLastError(); return;
                        }
                    }
                    if (exRate.FirstSemester > 0)
                    {
                        if (!dgvRates.SetCellValue(dataRow, colFirstSemester.Name, exRate.FirstSemester))
                        {
                            ShowGridLastError(); return;
                        }
                    }
                    if (exRate.SecondSemester > 0)
                    {
                        if (!dgvRates.SetCellValue(dataRow, colSecondSemester.Name, exRate.SecondSemester))
                        {
                            ShowGridLastError(); return;
                        }
                    }
                    if (!dgvRates.SetCellValue(dataRow, colDefault.Name, exRate.Default))
                    {
                        ShowGridLastError(); return;
                    }
                    if (!dgvRates.SetCellValue(dataRow, colValidFor.Name, exRate.ValidFor))
                    {
                        ShowGridLastError(); return;
                    }

                    initalExRates.Add(new ExchangeRate(exRate)); // remember for checking if any country files need updating once user stores the changes
                }

                List <string> countries = (from c in CountryAdministrator.GetCountries() select c._shortName.ToUpper()).ToList();
                foreach (string country in countries)
                {
                    cmbCountryToAdd.Items.Add(country);
                }

                if (!dgvRates.StartUndoManager())
                {
                    ShowGridLastError();
                }
            }
            catch (Exception exception) { UserInfoHandler.ShowException(exception); }
        }
        static void RemovePrivate_BackgroundEventHandler(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            BackgroundWorker backgroundWorker = sender as BackgroundWorker;

            if (backgroundWorker.CancellationPending)
            {
                e.Cancel = true; return;
            }                                                                      //user pressed Cancel button: stop the process and allow progress indicator to set dialog result to Cancel

            //then adapt the copy
            try
            {
                List <Country> countries = CountryAdministrator.GetCountries();

                //remove private systems, policies and datasets of each country
                for (int i = 0; i < countries.Count; ++i)
                {
                    if (backgroundWorker.CancellationPending)
                    {
                        e.Cancel = true; return;
                    }                                                                      //user pressed Cancel button: see above

                    Country             country             = countries[i];
                    CountryConfigFacade countryConfigFacade = country.GetCountryConfigFacade();
                    DataConfigFacade    dataConfigFacade    = country.GetDataConfigFacade();

                    //assess which systems, policies and datasets are private
                    List <CountryConfig.SystemRow>    privateSystems    = new List <CountryConfig.SystemRow>();    //systems
                    List <CountryConfig.PolicyRow>    privatePolicies   = new List <CountryConfig.PolicyRow>();    //policies
                    List <CountryConfig.FunctionRow>  privateFunctions  = new List <CountryConfig.FunctionRow>();  //functions
                    List <CountryConfig.ParameterRow> privateParameters = new List <CountryConfig.ParameterRow>(); //parameters
                    List <string> privateSystemIDs = new List <string>();                                          //necessary for afterwards identifying database-connections of private systems
                    foreach (CountryConfig.SystemRow system in countryConfigFacade.GetSystemRows())
                    {
                        if (system.Private.ToLower() == DefPar.Value.YES.ToLower())
                        {
                            privateSystems.Add(system);
                            privateSystemIDs.Add(system.ID);
                        }
                        else
                        {
                            foreach (CountryConfig.PolicyRow policy in system.GetPolicyRows())
                            {
                                if (policy.Private == DefPar.Value.YES)
                                {
                                    privatePolicies.Add(policy);
                                }
                                else
                                {
                                    if (policy.PrivateComment != null && policy.PrivateComment != string.Empty)
                                    {
                                        policy.PrivateComment = string.Empty; //remove private policy-comment if there is any
                                    }
                                    foreach (CountryConfig.FunctionRow function in policy.GetFunctionRows())
                                    {
                                        if (function.Private == DefPar.Value.YES)
                                        {
                                            privateFunctions.Add(function);
                                        }
                                        else
                                        {
                                            if (function.PrivateComment != null && function.PrivateComment != string.Empty)
                                            {
                                                function.PrivateComment = string.Empty; //remove private function-comment if there is any
                                            }
                                            foreach (CountryConfig.ParameterRow parameter in function.GetParameterRows())
                                            {
                                                if (parameter.Private == DefPar.Value.YES)
                                                {
                                                    privateParameters.Add(parameter);
                                                }
                                                else if (parameter.PrivateComment != null && parameter.PrivateComment != string.Empty)
                                                {
                                                    parameter.PrivateComment = string.Empty; //remove private parameter-comment if there is any
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    List <DataConfig.DataBaseRow>       privateDataSets        = new List <DataConfig.DataBaseRow>();       //datasets
                    List <DataConfig.DBSystemConfigRow> privateDBSystemConfigs = new List <DataConfig.DBSystemConfigRow>(); //database-connections of private systems
                    foreach (DataConfig.DataBaseRow dataSet in dataConfigFacade.GetDataBaseRows())
                    {
                        if (dataSet.Private.ToLower() == DefPar.Value.YES.ToLower())
                        {
                            privateDataSets.Add(dataSet);
                        }
                        else
                        {
                            foreach (DataConfig.DBSystemConfigRow dbSystemConfig in dataConfigFacade.GetDBSystemConfigRows(dataSet.ID))
                            {
                                if (privateSystemIDs.Contains(dbSystemConfig.SystemID))
                                {
                                    privateDBSystemConfigs.Add(dbSystemConfig);
                                }
                            }
                        }
                    }

                    //remove user-set node colors
                    countryConfigFacade.RemoveAllNodeColors();

                    //restore or install default base-system-colouring
                    countryConfigFacade.setAutomaticConditionalFormatting(true);

                    //remove private systems
                    if (countryConfigFacade.GetCountryRow().Private == DefPar.Value.YES || //if country is private or
                        privateSystems.Count == countryConfigFacade.GetSystemRows().Count) //there are no systems left, delete country
                    {
                        Directory.Delete(EMPath.Folder_Countries(EM_AppContext.FolderEuromodFiles) + country._shortName, true);
                        country.SetCountryConfigFacade(null);
                        country.SetDataConfigFacade(null);
                        continue;
                    }
                    else //otherwise delete private systems
                    {
                        foreach (CountryConfig.SystemRow privateSystem in privateSystems)
                        {
                            privateSystem.Delete();
                        }
                    }

                    //remove private parameters
                    foreach (CountryConfig.ParameterRow privateParameter in privateParameters)
                    {
                        privateParameter.Delete();
                    }

                    //remove private functions
                    foreach (CountryConfig.FunctionRow privateFunction in privateFunctions)
                    {
                        privateFunction.Delete();
                    }

                    //remove private policies
                    foreach (CountryConfig.PolicyRow privatePolicy in privatePolicies)
                    {
                        privatePolicy.Delete();
                    }

                    //remove private datasets
                    foreach (DataConfig.DataBaseRow privateDataSet in privateDataSets)
                    {
                        privateDataSet.Delete();
                    }

                    //remove database-connections of private systems
                    foreach (DataConfig.DBSystemConfigRow privateDBSystemConfig in privateDBSystemConfigs)
                    {
                        privateDBSystemConfig.Delete();
                    }

                    country.WriteXML();
                    country.SetCountryConfigFacade(null);
                    country.SetDataConfigFacade(null);

                    backgroundWorker.ReportProgress(Convert.ToInt32((i + 1.0) / (countries.Count * 1.0) * 100.0));
                }

                //remove private add-ons
                foreach (Country addOn in CountryAdministrator.GetAddOns())
                {
                    bool oldStyle = CountryAdministrator.ConsiderOldAddOnFileStructure(true);
                    CountryConfigFacade addOnConfigFacade = addOn.GetCountryConfigFacade();
                    if (addOnConfigFacade.GetCountryRow().Private != DefPar.Value.YES)
                    {
                        continue;
                    }
                    if (oldStyle)
                    {
                        File.Delete(EMPath.Folder_AddOns(EM_AppContext.FolderEuromodFiles) + addOn._shortName + ".xml");
                    }
                    else
                    {
                        Directory.Delete(EMPath.Folder_AddOns(EM_AppContext.FolderEuromodFiles) + addOn._shortName, true);
                    }
                    addOn.SetCountryConfigFacade(null);
                }

                // remove the "other" column from the variables file
                VarConfigFacade vcf = EM_AppContext.Instance.GetVarConfigFacade();
                foreach (VarConfig.CountryLabelRow r in from l in vcf._varConfig.CountryLabel where l.Country.ToLower() == "other" select l)
                {
                    r.Delete();
                }
                vcf.Commit(); vcf.WriteXML();

                if (backgroundWorker.CancellationPending)
                {
                    e.Cancel = true; return;
                }                                                                      //user pressed Cancel button: see above
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowException(exception);
                e.Cancel = true; //stop the process and allow progress indicator to set dialog result to Cancel
            }
        }
        static void CheckPrivateComponents_BackgroundEventHandler(object sender, System.ComponentModel.DoWorkEventArgs e)
        { //assess which datasets, systems and policies are private (as a background process of the progress indicator)
            BackgroundWorker backgroundWorker = sender as BackgroundWorker;

            if (backgroundWorker.CancellationPending)
            {
                e.Cancel = true; return;
            }                                                                      //user pressed Cancel button: stop the process and allow progress indicator to set dialog result to Cancel

            try
            {
                List <Country> countries = CountryAdministrator.GetCountries();

                _privateComponents = string.Empty;
                for (int i = 0; i < countries.Count; i++)
                {
                    if (backgroundWorker.CancellationPending)
                    {
                        e.Cancel = true; return;
                    }                                                                      //user pressed Cancel button: see above

                    Country             country             = countries[i];
                    CountryConfigFacade countryConfigFacade = country.GetCountryConfigFacade();
                    DataConfigFacade    dataConfigFacade    = country.GetDataConfigFacade();

                    //assess which systems are private
                    List <CountryConfig.SystemRow> privateSystems = new List <CountryConfig.SystemRow>();
                    foreach (CountryConfig.SystemRow system in countryConfigFacade.GetSystemRows())
                    {
                        if (backgroundWorker.CancellationPending)
                        {
                            e.Cancel = true; return;
                        }                                                                      //user pressed Cancel button: see above

                        if (system.Private.ToLower() == DefPar.Value.YES.ToLower())
                        {
                            privateSystems.Add(system);
                        }
                    }

                    //assess which policies are private
                    List <CountryConfig.PolicyRow>    privatePolicies   = new List <CountryConfig.PolicyRow>();
                    List <CountryConfig.FunctionRow>  privateFunctions  = new List <CountryConfig.FunctionRow>();
                    List <CountryConfig.ParameterRow> privateParameters = new List <CountryConfig.ParameterRow>();
                    if (countryConfigFacade.GetSystemRows().Count > privateSystems.Count)
                    {//only necessary to do for first system, as policies can only be marked private for all systems, but check if not all systems are private
                        foreach (CountryConfig.PolicyRow policy in countryConfigFacade.GetSystemRows()[0].GetPolicyRows())
                        {
                            if (backgroundWorker.CancellationPending)
                            {
                                e.Cancel = true; return;
                            }                                                                      //user pressed Cancel button: see above

                            if (policy.Private == DefPar.Value.YES)
                            {
                                privatePolicies.Add(policy);
                            }
                            else
                            {
                                foreach (CountryConfig.FunctionRow function in policy.GetFunctionRows())
                                {
                                    if (function.Private == DefPar.Value.YES)
                                    {
                                        privateFunctions.Add(function);
                                    }
                                    else
                                    {
                                        foreach (CountryConfig.ParameterRow parameter in function.GetParameterRows())
                                        {
                                            if (parameter.Private == DefPar.Value.YES)
                                            {
                                                privateParameters.Add(parameter);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    //assess which datasets are private
                    List <DataConfig.DataBaseRow> privateDataSets = new List <DataConfig.DataBaseRow>();
                    foreach (DataConfig.DataBaseRow dataSet in dataConfigFacade.GetDataBaseRows())
                    {
                        if (backgroundWorker.CancellationPending)
                        {
                            e.Cancel = true; return;
                        }                                                                      //user pressed Cancel button: see above

                        if (dataSet.Private.ToLower() == DefPar.Value.YES.ToLower())
                        {
                            privateDataSets.Add(dataSet);
                        }
                    }

                    backgroundWorker.ReportProgress(Convert.ToInt32((i + 1.0) / (countries.Count * 1.0) * 100.0)); //increase progress (for each country)

                    if (privateDataSets.Count == 0 && privateSystems.Count == 0 && privatePolicies.Count == 0)
                    {
                        continue;
                    }

                    //fill _privateComponents into string which is to be output in btnCheckPrivate_Click
                    _privateComponents += country._shortName.ToUpper() + Environment.NewLine;

                    if (countryConfigFacade.GetCountryRow().Private == DefPar.Value.YES)
                    {
                        _privateComponents += "\tPRIVATE COUNTRY" + Environment.NewLine;
                    }

                    if (privateDataSets.Count != 0)
                    {
                        _privateComponents += "\tPRIVATE DATASETS" + Environment.NewLine;
                        foreach (DataConfig.DataBaseRow dataSet in privateDataSets)
                        {
                            _privateComponents += "\t\t" + dataSet.Name + Environment.NewLine;
                        }
                    }
                    if (privateSystems.Count != 0)
                    {
                        _privateComponents += "\tPRIVATE SYSTEMS" + Environment.NewLine;
                        foreach (CountryConfig.SystemRow system in privateSystems)
                        {
                            _privateComponents += "\t\t" + system.Name + Environment.NewLine;
                        }
                    }
                    if (privatePolicies.Count != 0)
                    {
                        _privateComponents += "\tPRIVATE POLICIES" + Environment.NewLine;
                        foreach (CountryConfig.PolicyRow policy in privatePolicies)
                        {
                            _privateComponents += "\t\t" + policy.Name + Environment.NewLine;
                        }
                    }
                    if (privateFunctions.Count != 0)
                    {
                        _privateComponents += "\tPRIVATE FUNCTIONS" + Environment.NewLine;
                        foreach (CountryConfig.FunctionRow function in privateFunctions)
                        {
                            _privateComponents += "\t\t" + function.Name + " in policy " + function.PolicyRow.Name + " (order " + function.Order + ")" + Environment.NewLine;
                        }
                    }
                    if (privateParameters.Count != 0)
                    {
                        _privateComponents += "\tPRIVATE PARAMETERS" + Environment.NewLine;
                        foreach (CountryConfig.ParameterRow parameter in privateParameters)
                        {
                            _privateComponents += "\t\t" + parameter.Name + " in function " + parameter.FunctionRow.Name + " in policy " + parameter.FunctionRow.PolicyRow.Name +
                                                  " (function-order " + parameter.FunctionRow.Order + ", parameter-order " + parameter.Order + ")" + Environment.NewLine;
                        }
                    }
                    _privateComponents += "_________________________________________________________" + Environment.NewLine;
                }

                foreach (Country addOn in CountryAdministrator.GetAddOns())
                {
                    CountryConfigFacade addOnConfigFacade = addOn.GetCountryConfigFacade();
                    if (addOnConfigFacade.GetCountryRow().Private != DefPar.Value.YES)
                    {
                        continue;
                    }
                    _privateComponents += addOn._shortName.ToUpper() + Environment.NewLine;
                    _privateComponents += "\tPRIVATE ADD-ON" + Environment.NewLine;
                    _privateComponents += "_________________________________________________________" + Environment.NewLine;
                }
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowException(exception);
                e.Cancel = true; //stop the process and allow progress indicator to set dialog result to Cancel
            }
        }
        internal HICPForm(List <HICPConfig.HICPRow> hicps)
        {
            InitializeComponent();

            try
            {
                if (!dgvHICP.InitDataSource())
                {
                    ShowGridLastError(); return;
                }

                if (!dgvHICP.AddColumn(false, colCountry, typeof(string)))
                {
                    ShowGridLastError(); return;
                }

                List <string> countries = (from c in CountryAdministrator.GetCountries() select c._shortName.ToUpper()).ToList();
                List <int>    years     = (from y in hicps select y.Year).Distinct().ToList(); years.Sort();
                foreach (int year in years)
                {
                    if (!AddYear(year))
                    {
                        return;
                    }
                }

                if (!dgvHICP.AddColumn(false, colComment, typeof(string)))
                {
                    ShowGridLastError(); return;
                }
                dgvHICP.pasteableColumns.Add(colComment);
                if (!dgvHICP.AddColumn(false, colID, typeof(Int16), -1, true))
                {
                    ShowGridLastError(); return;
                }

                Dictionary <string, DataRow> countryRowIndex = new Dictionary <string, DataRow>();
                foreach (string country in countries)
                {
                    DataRow dataRow; if (!AddCountryRow(out dataRow, years.Count, country))
                    {
                        return;
                    }
                    countryRowIndex.Add(country, dataRow);
                }

                foreach (HICPConfig.HICPRow hicp in hicps)
                {
                    string country = hicp.Country.ToUpper();
                    if (!countryRowIndex.ContainsKey(country)) // a country that does not belong to the countries of the loaded version (and is not yet added to the table)
                    {
                        DataRow dataRow; if (!AddCountryRow(out dataRow, years.Count, hicp.Country, hicp.Comment))
                        {
                            return;
                        }
                        countryRowIndex.Add(country, dataRow);
                        cmbCountryToDelete.Items.Add(country); // only allow deleting rows for countries which are not part of the loaded version (i.e. are likely to be just fake or error)
                    }
                    dgvHICP.SetCellValue(countryRowIndex[country], hicp.Year.ToString(), hicp.Value);
                    dgvHICP.SetCellValue(countryRowIndex[country], colComment, hicp.Comment);
                }
                FormatGridViewColumns();

                cmbCountryToDelete.Visible  = cmbCountryToDelete.Items.Count > 0; // only show the option to delete a country-row in the unlikely case that there are "unknown" countries
                btnDeleteCountryRow.Visible = cmbCountryToDelete.Items.Count > 0;

                if (!dgvHICP.StartUndoManager())
                {
                    ShowGridLastError();
                }
            }
            catch (Exception exception) { UserInfoHandler.ShowException(exception); }
        }
Esempio n. 16
0
        static void Generate_BackgroundEventHandler(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            BackgroundWorker backgroundWorker = sender as BackgroundWorker;

            if (backgroundWorker.CancellationPending)
            {
                e.Cancel = true; return;
            }                                                                      //user pressed Cancel button: stop the process and allow progress indicator to set dialog result to Cancel

            //assess the name of the new EuromodFiles-folder in accordance to the version number
            DirectoryInfo sourceFolder = new DirectoryInfo(EM_AppContext.FolderEuromodFiles);
            string        folderEMF    = "EuromodFiles_" + _publicVersionNumber;

            if (!EM_Helpers.IsValidFileName(folderEMF))
            {
                UserInfoHandler.ShowInfo(folderEMF + " is not a valid folder name. Please change the version number.");
                e.Cancel = true; return;
            }

            //first copy the whole EuromodFiles folder to the respective path
            if (!XCopy.Folder(EM_AppContext.FolderEuromodFiles, _publicVersionPath, folderEMF))
            {
                e.Cancel = true; return;
            }

            string fullPublicPath = _publicVersionPath + EMPath.AddSlash(folderEMF);

            //then adapt the copy
            string folderCountries =
                EMPath.AddSlash( //at the new path assess the folder that contains the files (usually EuromodFiles)
                    EMPath.Folder_Countries(EM_AppContext.FolderEuromodFiles).Replace(EM_AppContext.FolderEuromodFiles, fullPublicPath));

            try
            {
                List <Country> countries = CountryAdministrator.GetCountries();

                //remove private systems, policies and datasets of each country
                for (int i = 0; i < countries.Count; ++i)
                {
                    if (backgroundWorker.CancellationPending)
                    {
                        e.Cancel = true; return;
                    }                                                                      //user pressed Cancel button: see above

                    Country             country             = countries[i];
                    CountryConfigFacade countryConfigFacade = country.GetCountryConfigFacade(true, folderCountries + country._shortName);
                    DataConfigFacade    dataConfigFacade    = country.GetDataConfigFacade(true, folderCountries + country._shortName);

                    //assess which systems, policies and datasets are private
                    List <CountryConfig.SystemRow>    privateSystems    = new List <CountryConfig.SystemRow>();    //systems
                    List <CountryConfig.PolicyRow>    privatePolicies   = new List <CountryConfig.PolicyRow>();    //policies
                    List <CountryConfig.FunctionRow>  privateFunctions  = new List <CountryConfig.FunctionRow>();  //functions
                    List <CountryConfig.ParameterRow> privateParameters = new List <CountryConfig.ParameterRow>(); //parameters
                    List <string> privateSystemIDs = new List <string>();                                          //necessary for afterwards identifying database-connections of private systems
                    foreach (CountryConfig.SystemRow system in countryConfigFacade.GetSystemRows())
                    {
                        if (system.Private.ToLower() == DefPar.Value.YES.ToLower())
                        {
                            privateSystems.Add(system);
                            privateSystemIDs.Add(system.ID);
                        }
                        else
                        {
                            foreach (CountryConfig.PolicyRow policy in system.GetPolicyRows())
                            {
                                if (policy.Private == DefPar.Value.YES)
                                {
                                    privatePolicies.Add(policy);
                                }
                                else
                                {
                                    if (policy.PrivateComment != null && policy.PrivateComment != string.Empty)
                                    {
                                        policy.PrivateComment = string.Empty; //remove private policy-comment if there is any
                                    }
                                    foreach (CountryConfig.FunctionRow function in policy.GetFunctionRows())
                                    {
                                        if (function.Private == DefPar.Value.YES)
                                        {
                                            privateFunctions.Add(function);
                                        }
                                        else
                                        {
                                            if (function.PrivateComment != null && function.PrivateComment != string.Empty)
                                            {
                                                function.PrivateComment = string.Empty; //remove private function-comment if there is any
                                            }
                                            foreach (CountryConfig.ParameterRow parameter in function.GetParameterRows())
                                            {
                                                if (parameter.Private == DefPar.Value.YES)
                                                {
                                                    privateParameters.Add(parameter);
                                                }
                                                else if (parameter.PrivateComment != null && parameter.PrivateComment != string.Empty)
                                                {
                                                    parameter.PrivateComment = string.Empty; //remove private parameter-comment if there is any
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    List <DataConfig.DataBaseRow>       privateDataSets        = new List <DataConfig.DataBaseRow>();       //datasets
                    List <DataConfig.DBSystemConfigRow> privateDBSystemConfigs = new List <DataConfig.DBSystemConfigRow>(); //database-connections of private systems
                    foreach (DataConfig.DataBaseRow dataSet in dataConfigFacade.GetDataBaseRows())
                    {
                        if (dataSet.Private.ToLower() == DefPar.Value.YES.ToLower())
                        {
                            privateDataSets.Add(dataSet);
                        }
                        else
                        {
                            foreach (DataConfig.DBSystemConfigRow dbSystemConfig in dataConfigFacade.GetDBSystemConfigRows(dataSet.ID))
                            {
                                if (privateSystemIDs.Contains(dbSystemConfig.SystemID))
                                {
                                    privateDBSystemConfigs.Add(dbSystemConfig);
                                }
                            }
                        }
                    }

                    //remove user-set node colors
                    countryConfigFacade.RemoveAllNodeColors();

                    //restore or install default base-system-colouring
                    countryConfigFacade.setAutomaticConditionalFormatting(true);

                    //remove private systems
                    if (countryConfigFacade.GetCountryRow().Private == DefPar.Value.YES || //if country is private or
                        privateSystems.Count == countryConfigFacade.GetSystemRows().Count) //there are no systems left, delete country
                    {
                        Directory.Delete(folderCountries + country._shortName, true);
                        country.SetCountryConfigFacade(null);
                        country.SetDataConfigFacade(null);
                        continue;
                    }
                    else //otherwise delete private systems
                    {
                        foreach (CountryConfig.SystemRow privateSystem in privateSystems)
                        {
                            privateSystem.Delete();
                        }
                    }

                    //remove private parameters
                    foreach (CountryConfig.ParameterRow privateParameter in privateParameters)
                    {
                        privateParameter.Delete();
                    }

                    //remove private functions
                    foreach (CountryConfig.FunctionRow privateFunction in privateFunctions)
                    {
                        privateFunction.Delete();
                    }

                    //remove private policies
                    foreach (CountryConfig.PolicyRow privatePolicy in privatePolicies)
                    {
                        privatePolicy.Delete();
                    }

                    //remove private datasets
                    foreach (DataConfig.DataBaseRow privateDataSet in privateDataSets)
                    {
                        privateDataSet.Delete();
                    }

                    //remove database-connections of private systems
                    foreach (DataConfig.DBSystemConfigRow privateDBSystemConfig in privateDBSystemConfigs)
                    {
                        privateDBSystemConfig.Delete();
                    }

                    country.WriteXML(folderCountries + country._shortName);
                    country.SetCountryConfigFacade(null);
                    country.SetDataConfigFacade(null);

                    backgroundWorker.ReportProgress(Convert.ToInt32((i + 1.0) / (countries.Count * 1.0) * 80.0));
                }

                //remove private add-ons
                string folderAddOns = EMPath.AddSlash( //at the new path assess the folder that contains the files (usually EuromodFiles)
                    EMPath.Folder_AddOns(EM_AppContext.FolderEuromodFiles).Replace(EM_AppContext.FolderEuromodFiles, fullPublicPath));
                foreach (Country addOn in CountryAdministrator.GetAddOns())
                {
                    bool oldStyle = CountryAdministrator.ConsiderOldAddOnFileStructure(true);
                    CountryConfigFacade addOnConfigFacade = addOn.GetCountryConfigFacade(true, folderAddOns + (oldStyle ? string.Empty : addOn._shortName));
                    if (addOnConfigFacade.GetCountryRow().Private != DefPar.Value.YES)
                    {
                        continue;
                    }
                    if (oldStyle)
                    {
                        File.Delete(folderAddOns + addOn._shortName + ".xml");
                    }
                    else
                    {
                        Directory.Delete(folderAddOns + addOn._shortName, true);
                    }
                    addOn.SetCountryConfigFacade(null);
                }

                // remove the "other" column from the variables file
                string          pathVarConfig = new EMPath(EM_AppContext.FolderEuromodFiles).GetVarFilePath(true).Replace(EM_AppContext.FolderEuromodFiles, fullPublicPath);
                VarConfigFacade vcf           = new VarConfigFacade(pathVarConfig);
                if (vcf.LoadVarConfig())
                {
                    foreach (VarConfig.CountryLabelRow r in
                             from l in vcf._varConfig.CountryLabel where l.Country.ToLower() == "other" select l)
                    {
                        r.Delete();
                    }
                    vcf.Commit(); vcf.WriteXML(pathVarConfig);
                }

                if (backgroundWorker.CancellationPending)
                {
                    e.Cancel = true; return;
                }                                                                      //user pressed Cancel button: see above

                //change version number
                string txtVersionPath = EMPath.Folder_Config(EM_AppContext.FolderEuromodFiles) + "EuromodVersion.txt";
                txtVersionPath = txtVersionPath.Replace(EM_AppContext.FolderEuromodFiles, fullPublicPath);
                using (StreamWriter versionFile = new StreamWriter(txtVersionPath))
                {
                    versionFile.WriteLine(_publicVersionNumber);
                    versionFile.WriteLine("PUBLIC VERSION");
                }

                //remove private rows from log file
                string logFile = new EMPath(EM_AppContext.FolderEuromodFiles).GetEmLogFilePath(); // determine the path of the em_log-file in the public folder
                logFile = logFile.Replace(EM_AppContext.FolderEuromodFiles, fullPublicPath);
                backgroundWorker.ReportProgress(100);
                if (File.Exists(logFile))
                {
                    AdaptLogFile(logFile);
                }

                //take care to not have any "xx_in_use.txt" files in the release
                try
                {
                    foreach (string inUseFile in Directory.GetFiles(fullPublicPath, "*_in_use.txt", SearchOption.AllDirectories))
                    {
                        File.Delete(inUseFile);
                    }
                }
                catch (Exception exception)
                {
                    //do nothing if this fails
                    UserInfoHandler.RecordIgnoredException("PublicVersion.Generate_BackgroundEventHandler", exception);
                }
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowException(exception);
                e.Cancel = true; //stop the process and allow progress indicator to set dialog result to Cancel
            }
        }