private void btnOK_Click(object sender, EventArgs e)
        {
            if (lstCountries.SelectedItems.Count == 0 && lstSystems.SelectedItems.Count == 0)
            {
                UserInfoHandler.ShowInfo("Please select the countries and/or systems you want to include into the project."); return;
            }

            if (txtProjectName.Text == string.Empty || txtProjectPath.Text == string.Empty)
            {
                UserInfoHandler.ShowError("Please select a valid Project Name and/or Project Path."); return;
            }
            projectPath = EMPath.AddSlash(EMPath.AddSlash(txtProjectPath.Text) + txtProjectName.Text);
            if (!EM_Helpers.IsValidFileName(projectPath))
            {
                UserInfoHandler.ShowInfo(projectPath + " is not a valid folder name for the new project."); return;
            }

            Cursor = Cursors.WaitCursor; bool undo = false;
            try
            {
                // first copy the whole EuromodFiles folder to the respective path, to then adapt the copy
                if (!XCopy.Folder(EM_AppContext.FolderEuromodFiles, txtProjectPath.Text, txtProjectName.Text))
                {
                    Cursor = Cursors.Default; return;
                }
                undo = true;

                // delete all unnecessary files and folders (but do not report or stop if any of this fails)
                EMPath emPath = new EMPath(EM_AppContext.FolderEuromodFiles);
                DeleteFolder(ReplacePath(emPath.GetFolderLog()));
                ClearFolder(ReplacePath(EM_AppContext.FolderOutput));
                ClearFolder(ReplacePath(emPath.GetFolderTemp()));
                DeleteFile(ReplacePath(Path.Combine(emPath.GetFolderConfig(true), "VersionControl.xml")));

                string        folderCountries = ReplacePath(EMPath.Folder_Countries(EM_AppContext.FolderEuromodFiles));
                List <string> selCountries    = new List <string>(); foreach (var item in lstCountries.SelectedItems)
                {
                    selCountries.Add(item.ToString().ToLower());
                }
                ClearFolder(folderCountries, selCountries);

                // delete all unnecessary systems
                List <string> selSystems = null;
                if (lstSystems.SelectedItems.Count > 0 && lstSystems.SelectedItems.Count != lstSystems.Items.Count)
                {
                    selSystems = new List <string>(); foreach (var item in lstSystems.SelectedItems)
                    {
                        selSystems.Add(item.ToString().ToLower());
                    }
                }
                foreach (string cc in selCountries)
                {
                    DeleteFile(EMPath.AddSlash(projectPath + cc) + cc + "_in_use.txt");

                    if (selSystems == null)
                    {
                        continue;                     // if all system/years are selected or nothing is selected, assume that user does not want to "reduce" systems
                    }
                    Country             country = new Country(cc);
                    CountryConfigFacade ccf     = country.GetCountryConfigFacade(true, folderCountries + country._shortName);
                    DataConfigFacade    dcf     = country.GetDataConfigFacade(true, folderCountries + country._shortName);

                    List <CountryConfig.SystemRow> delSystems = new List <CountryConfig.SystemRow>();
                    foreach (CountryConfig.SystemRow system in ccf.GetSystemRows())
                    {
                        if (radShowSystems.Checked)
                        {
                            if (!selSystems.Contains(system.Name.ToLower()))
                            {
                                delSystems.Add(system);
                            }
                        }
                        else
                        {
                            string systemYear = system.Year == null || system.Year == string.Empty ? EM_Helpers.ExtractSystemYear(system.Name) : system.Year;
                            if (!selSystems.Contains(systemYear))
                            {
                                delSystems.Add(system);
                            }
                        }
                    }

                    List <DataConfig.DBSystemConfigRow> delDBSysCons = new List <DataConfig.DBSystemConfigRow>();
                    List <string> delSystemIds = (from d in delSystems select d.ID).ToList();
                    foreach (DataConfig.DataBaseRow dataSet in dcf.GetDataBaseRows())
                    {
                        foreach (DataConfig.DBSystemConfigRow dbSystemConfig in dcf.GetDBSystemConfigRows(dataSet.ID))
                        {
                            if (delSystemIds.Contains(dbSystemConfig.SystemID))
                            {
                                delDBSysCons.Add(dbSystemConfig);
                            }
                        }
                    }

                    foreach (CountryConfig.SystemRow delSystem in delSystems)
                    {
                        delSystem.Delete();
                    }
                    foreach (DataConfig.DBSystemConfigRow delDBSysCon in delDBSysCons)
                    {
                        delDBSysCon.Delete();
                    }

                    country.WriteXML(folderCountries + country._shortName);
                }
                UserInfoHandler.ShowSuccess("Successfully created project folder " + projectPath + ".");
                Close();
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowError(exception.Message);
                if (undo)
                {
                    try { if (Directory.Exists(projectPath))
                          {
                              Directory.Delete(projectPath, true);
                          }
                    } catch { }
                }
            }
            Cursor = Cursors.Default;
        }
Exemple #2
0
        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();
        }
Exemple #3
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
            }
        }
        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
            }
        }
Exemple #5
0
        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();
            }
        }