Beispiel #1
0
        internal bool RunExe(string country, string year, string dataFullPath, bool outputInEuro, out List <string> errors)
        {
            Dictionary <string, string> config = ExeRunConfig.GetBasicConfig(
                UISessionInfo.GetEuromodFilesFolder(),                               // EurmodFiles-folder
                country, $"{country}_{year}",                                        // country and system
                Path.GetDirectoryName(dataFullPath), Path.GetFileName(dataFullPath), // data-folder and data-file
                UISessionInfo.GetOutputFolder());                                    // output-folder

            if (outputInEuro)
            {
                config.Add(TAGS.CONFIG_FORCE_OUTPUT_EURO, DefPar.Value.YES);
            }

            List <string> err     = new List <string>();
            bool          success = new Control().Run(config, null, e => { err.Add((e.isWarning ? "Warning: " : "Error: ") + e.message); });

            errors = err;

            return(success);
        }
Beispiel #2
0
        public PresenterForm(Template template, List <FilePackageContent> filePackages, List <Template.TemplateInfo.UserVariable> userInput)
        {
            InitializeComponent();
            try
            {
                try
                {
                    if (requiresWarmUp)
                    {
                        requiresWarmUp = false;
                        string dummyHtml = Path.Combine(new EMPath(UISessionInfo.GetEuromodFilesFolder()).GetFolderTemp(), "dummy.html");
                        if (!File.Exists(dummyHtml))
                        {
                            File.WriteAllText(dummyHtml, Resources.dummy_html);
                        }
                        webBrowser.Url = new Uri(dummyHtml);
                        //webBrowser.Url = new Uri(@"C:\Users\Christine\Downloads\LIGHTS\A_PUBLISH\MultiUser\View\wwwroot\login.html");
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show("ojeoje: " + e.Message);
                }

                EM_StatisticsBackEndResponder backEndResponder = new EM_StatisticsBackEndResponder(backEnd, template, filePackages, userInput);
                responderKey = backEndResponder.responderKey;
                backEnd.Start(new Dictionary <string, EM_BackEndResponder>()
                {
                    { responderKey, backEndResponder }
                });
                webBrowser.Url = new Uri($"http://localhost:{backEnd.Port}/{responderKey}_{EM_StatisticsBackEndResponder.LOAD_STATISTICS_HTML}?packageKey={filePackages[0].Key}");
            }
            catch (Exception exception) { Error(exception.Message); }

            void Error(string message)
            {
                MessageBox.Show("Error starting Statistics Back-End:" + Environment.NewLine + message);
            }
        }
        readonly List <int> selectedIndices             = new List <int>(); // store the order of selection for Alts

        public SelectFilesForm(Template.TemplateInfo templateInfo)
        {
            InitializeComponent();

            this.templateInfo = templateInfo;

            labCaption.Text = templateInfo.name;

            // try to retieve selected path from UI-user-settings, if not successful set to UI-output-folder
            string storedBaseOutputFolder = UISessionInfo.GetRetainedUserSetting(StatisticsPresenter.USER_SETTINGS_ID, StatisticsPresenter.BASE_OUTPUT_FOLDER);

            textPath.Text = string.IsNullOrEmpty(storedBaseOutputFolder) ? UISessionInfo.GetOutputFolder() : storedBaseOutputFolder;

            if (templateInfo.maxFiles == 1)
            {
                listFiles.SelectionMode  = SelectionMode.One;
                lblMultiSelect.Visible   = false;
                lblOrderRetained.Visible = false;
            }
            else
            {
                listFiles.SelectionMode = SelectionMode.MultiExtended;
            }
        }
        private void btnOK_Click(object sender, System.EventArgs e)
        {
            if (!LoadTemplateInfo())
            {
                return;
            }

            Visible = false;

            if (givenFilePackages == null)
            {
                SelectFilePackages();
            }
            else
            {
                filePackages = givenFilePackages; DialogResult = DialogResult.OK;
            }

            if (givenUserInput != null)
            {
                userInput = givenUserInput;
            }
            else if (DialogResult != DialogResult.Cancel && templateInfo.GetUserVariables().Count != 0)
            {
                TakeUserInput takeUserInput = new TakeUserInput(templateInfo);
                takeUserInput.ShowDialog();
                userInput    = takeUserInput.userVariables;
                DialogResult = takeUserInput.DialogResult;
            }

            // if all done, fully parse the selected template
            if (DialogResult == DialogResult.OK)
            {
                if (givenTemplate != null)
                {
                    template = givenTemplate;
                }
                else if (templatePath != "")
                {
                    if (!XML_handling.ParseTemplate(templatePath, out template, out ErrorCollector errorCollector))
                    {
                        DialogResult = DialogResult.Cancel;
                    }
                    if (errorCollector.HasErrors())
                    {
                        MessageBox.Show(errorCollector.GetErrorMessage());
                    }
                }
                else
                {
                    MessageBox.Show("Error! no template or templatepath given!");
                    DialogResult = DialogResult.Cancel;
                }
                if (template != null)
                {
                    template.info = templateInfo;
                }
            }

            if (sender != null && template != null && template.info != null && template.info.name != null)
            {
                // save selected template in session info
                TSDictionary pluginSessionInfo = new TSDictionary();
                pluginSessionInfo.SetItem(StatisticsPresenter.LAST_SELECTED_TEMPLATE, template.info.name);
                UISessionInfo.SetSessionUserSettings(StatisticsPresenter.USER_SETTINGS_ID, pluginSessionInfo);
            }

            Close();
        }
Beispiel #5
0
        private void btnVarDataCheck_Click(object sender, EventArgs e)
        {
            string varPath       = GetOutPath("VarUsage");
            string inputFilePath = UISessionInfo.GetInputFolder();
            string newVarPath    = GetOutPath("UpdatedVarUsage");

            if (!File.Exists(varPath))
            {
                MessageBox.Show("File '" + varPath + "' not found. Please run 'Variable Usage' first.");
                return;
            }
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            fbd.Description  = "Please select the folder with the input files to compare";
            fbd.SelectedPath = inputFilePath;
            if (fbd.ShowDialog(this) == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }
            inputFilePath = fbd.SelectedPath;

            // read the varusage file
            List <List <string> > varInfo = new List <List <string> >();

            foreach (string line in File.ReadLines(varPath))
            {
                varInfo.Add(new List <string>(line.Split('\t')));
            }

            // read the haders of all data
            Dictionary <string, List <string> > allInputInfo = new Dictionary <string, List <string> >();

            foreach (string inputFile in Directory.EnumerateFiles(inputFilePath))
            {
                allInputInfo.Add(Path.GetFileNameWithoutExtension(inputFile), File.ReadLines(inputFile).First().Split('\t').ToList());
            }

            // check usage of vars in input files
            List <string> inputInfo = new List <string>()
            {
                "Exists in Data"
            };

            for (int i = 1; i < varInfo.Count; i++)
            {
                string varName            = varInfo[i][0];
                string containingDatasets = string.Empty;
                foreach (KeyValuePair <string, List <string> > data in allInputInfo)
                {
                    if (data.Value.Contains(varName, StringComparer.Create(System.Globalization.CultureInfo.InvariantCulture, true)))
                    {
                        containingDatasets += " " + data.Key;
                    }
                }
                if (containingDatasets != string.Empty)
                {
                    containingDatasets = containingDatasets.Substring(1);
                }
                inputInfo.Add(containingDatasets);
            }

            // write the new file
            List <string> print = new List <string>();

            for (int i = 0; i < varInfo.Count; i++)
            {
                print.Add(String.Join("\t", new string[] { varInfo[i][0], varInfo[i][1], varInfo[i][2], inputInfo[i], varInfo[i][3], varInfo[i][4] }));
            }
            File.WriteAllLines(newVarPath, print);
            MessageBox.Show("Updated VarUsage completed: '" + newVarPath + "'");
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (listBase.SelectedIndex < 0)
            {
                MessageBox.Show("Please select a file for the base scenario."); return;
            }

            int selCount = listAlt.SelectedIndices.Count;

            if (selCount < templateInfo.minFiles || selCount > templateInfo.maxFiles)
            {
                if (templateInfo.maxFiles == 1)
                {
                    MessageBox.Show("Please select a file for the alternative scenario.");                             // is the same as selCount=0 (as list is in single-selection mode)
                }
                else if (templateInfo.minFiles == templateInfo.maxFiles)
                {
                    MessageBox.Show(string.Format("Please select {0} files for the alternative scenarios.", templateInfo.maxFiles));
                }
                else if (templateInfo.maxFiles == int.MaxValue)
                {
                    MessageBox.Show(string.Format("Please select at least {0} files for the alternative scenarios.", templateInfo.minFiles));
                }
                else
                {
                    MessageBox.Show(string.Format("Please select {0} to {1} files for the alternative scenarios.", templateInfo.minFiles, templateInfo.maxFiles));
                }
                return;
            }

            FilePackageContent filePackage = new FilePackageContent()
            {
                PathBase = Path.Combine(textBasePath.Text, listBase.SelectedItem.ToString())
            };

            foreach (string altFile in selectedIndices.Select(i => listAlt.Items[i]))  // get alt selections in order
            {
                filePackage.PathsAlt.Add(Path.Combine(textAltPath.Text, altFile));
            }

            // in fact the dialog always returns exactly one file-package, the list is just for consistency-reasons with SelectFilesForm and SelectTemplateForm
            filePackages = new List <FilePackageContent>()
            {
                filePackage
            };

            // save selected paths in UI-user-settings (see description in SelectFileForm.cs )
            if (!EMPath.IsSamePath(textBasePath.Text.ToLower(), UISessionInfo.GetOutputFolder().ToLower()))
            {
                UISessionInfo.SetRetainedUserSetting(StatisticsPresenter.USER_SETTINGS_ID, StatisticsPresenter.BASE_OUTPUT_FOLDER, textBasePath.Text);
            }
            else
            {
                UISessionInfo.RemoveRetainedUserSetting(StatisticsPresenter.USER_SETTINGS_ID, StatisticsPresenter.BASE_OUTPUT_FOLDER);
            }
            if (!EMPath.IsSamePath(textAltPath.Text.ToLower(), UISessionInfo.GetOutputFolder().ToLower()))
            {
                UISessionInfo.SetRetainedUserSetting(StatisticsPresenter.USER_SETTINGS_ID, StatisticsPresenter.REFORM_OUTPUT_FOLDER, textAltPath.Text);
            }
            else
            {
                UISessionInfo.RemoveRetainedUserSetting(StatisticsPresenter.USER_SETTINGS_ID, StatisticsPresenter.REFORM_OUTPUT_FOLDER);
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Beispiel #7
0
        internal static string VarUsage(List <string> print, BackgroundWorker bkWorker)
        {
            Dictionary <string, VarUsePattern> varUsages = new Dictionary <string, VarUsePattern>();

            foreach (VarConfig.VariableRow v in VariablesChecker.varData.Variable)
            {
                varUsages.Add(v.Name, new VarUsePattern()
                {
                    autoLabel = v.AutoLabel
                });
            }

            string ccFolderPath = Path.Combine(UISessionInfo.GetEuromodFilesFolder(), @"XMLParam\Countries");

            DirectoryInfo[] ccFolders = new DirectoryInfo(ccFolderPath).GetDirectories(); double done = 0; bool canceled = false;

            Parallel.ForEach(ccFolders, ccFolder =>
            {
                if (bkWorker.CancellationPending)
                {
                    canceled = true; return;
                }

                List <CountryParValue> parValues; string shortName;
                if (!ReadCountry(Path.Combine(ccFolderPath, ccFolder.Name, ccFolder.Name + ".xml"), out parValues, out shortName))
                {
                    return;
                }

                List <string> usedVar = new List <string>(), naVar = new List <string>(), noLabelVar = new List <string>();
                foreach (VarConfig.VariableRow v in VariablesChecker.varData.Variable)
                {
                    if (bkWorker.CancellationPending)
                    {
                        canceled = true; return;
                    }
                    bool?used = false;
                    foreach (CountryParValue parValue in parValues)
                    {
                        if (UsedInFormula(v.Name.Trim().ToLower(), parValue.formula))
                        {
                            if (parValue.isNa)
                            {
                                used = null;                // means used as n/a - note: no break, i.e. can still be overwritten by true
                            }
                            else
                            {
                                used = true; break;
                            }
                        }
                    }
                    if (used == false)
                    {
                        continue;
                    }
                    if (used == true)
                    {
                        usedVar.Add(v.Name);
                    }
                    else
                    {
                        naVar.Add(v.Name);
                    }
                    var ccDesc = (from l in v.GetCountryLabelRows() where l.Country.ToLower().Trim() == shortName.ToLower().Trim() select l);
                    if (ccDesc.Count() == 0 || ccDesc.First().Label.Trim() == string.Empty || ccDesc.First().Label.Trim() == "-")
                    {
                        noLabelVar.Add(v.Name);
                    }
                }

                lock (varListLock)
                {
                    foreach (string v in usedVar)
                    {
                        varUsages[v].useCountries += shortName + " ";
                    }
                    foreach (string v in naVar)
                    {
                        varUsages[v].naCountries += shortName + " ";
                    }
                    foreach (string v in noLabelVar)
                    {
                        varUsages[v].noLabelCountries += shortName + " ";
                    }
                    bkWorker.ReportProgress((int)Math.Round(++done / ccFolders.Count() * 100));
                }
            });

            if (canceled)
            {
                return("Checking variable usage canceled");
            }

            int unused = 0;

            print.Add(string.Format("{0}\t{1}\t{2}\t{3}\t{4}", "Variable", "Used in", "Used in n/a only", "No description for", "Auto-description"));
            foreach (var vu in varUsages)
            {
                if (vu.Value.useCountries == string.Empty && vu.Value.naCountries == string.Empty)
                {
                    vu.Value.useCountries = "not used"; ++unused;
                }
                print.Add(string.Format("{0}\t{1}\t{2}\t{3}\t{4}",
                                        vu.Key, vu.Value.useCountries.TrimEnd(), vu.Value.naCountries.TrimEnd(), vu.Value.noLabelCountries.TrimEnd(), vu.Value.autoLabel));
            }

            return((unused == 0) ? "No unused variables found" : unused + " unused variables found");
        }