Esempio n. 1
0
        internal static void CleanLogFile()
        {
            string logFile = new EMPath(EM_AppContext.FolderEuromodFiles).GetEmLogFilePath();

            EM_UI_MainForm mainForm = EM_AppContext.Instance.GetActiveCountryMainForm();

            if (mainForm != null)
            {
                mainForm.Cursor = Cursors.WaitCursor;
            }
            string error = AdaptLogFile(logFile);

            if (mainForm != null)
            {
                mainForm.Cursor = Cursors.Default;
            }

            if (error == string.Empty)
            {
                UserInfoHandler.ShowSuccess("Successfully cleaned " + logFile + ".");
            }
            else
            {
                UserInfoHandler.ShowError("Failed to clean " + logFile + ":" + Environment.NewLine + error);
            }
        }
Esempio n. 2
0
        internal void GenerateInfo(string outputFilePath, List <string> _countries)
        {
            EM_UI_MainForm mainForm = EM_AppContext.Instance.GetActiveCountryMainForm(); if (mainForm != null)

            {
                mainForm.Cursor = Cursors.WaitCursor;
            }

            try
            {
                countries = _countries;
                AssessCountryInfo();
                InitExcelFile(outputFilePath);
                FillExcelFile();
                spreadsheetControl.SaveDocument();
                UserInfoHandler.ShowSuccess(string.Format("Successfully generated Release info file '{0}'.", outputFilePath)); // perhaps open ???
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowException(exception, string.Format("Failed to generate Release info file '{0}'.", outputFilePath), false);
            }
            finally { if (mainForm != null)
                      {
                          mainForm.Cursor = Cursors.Default;
                      }
            }
        }
 internal static void ReportSuccessAndInfo(string successfulAction, string backUpFolder, bool autoRestore = true)
 {
     UserInfoHandler.ShowSuccess(successfulAction + " succeeded!" + Environment.NewLine + Environment.NewLine +
                                 "Please note that a back-up of the version before the action is stored under " + Environment.NewLine +
                                 EMPath.Folder_BackUps(EM_AppContext.FolderEuromodFiles) + backUpFolder + "." + Environment.NewLine + Environment.NewLine +
                                 (autoRestore ? "You may restore it via the button 'Restore' in the ribbon 'Country Tools'." : string.Empty));
 }
        private static void SetExtensionPrivateGlobal(string extName, bool set)
        {
            string message = "Setting components of extension '" + extName + "' to " + (set ? "private" : "'not private'");

            if (EM_AppContext.Instance.IsAnythingOpen(false))
            {
                if (UserInfoHandler.GetInfo(message + " requires all countries to be closed." + Environment.NewLine + "All open countries will be closed.",
                                            MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                {
                    return;
                }
                EM_AppContext.Instance.CloseAllMainForms(false, false);
            }
            if (EM_AppContext.Instance.IsAnythingOpen(false))
            {
                return;                                               // user may have refused to save changes for an open country
            }
            using (ProgressIndicator progressIndicator = new ProgressIndicator(SetPrivate_BackgroundEventHandler, message, new Tuple <string, bool>(extName, set)))
            {
                if (progressIndicator.ShowDialog() == DialogResult.OK)
                {
                    UserInfoHandler.ShowSuccess(message + " successfully accomplished.");
                }
            }
        }
 private void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         string path = Path.Combine(EM_AppContext.FolderOutput, "ReleaseValidation_HHVarInfo.txt");
         using (StreamWriter sw = new StreamWriter(path))
         {
             foreach (DataGridViewRow row in dgvVar.Rows)
             {
                 string line = $"{row.Cells[0].Value.ToString()}\t";
                 string info = row.Cells[1].Value.ToString();
                 if (!info.Contains(SEPARATOR))
                 {
                     line += info;
                 }
                 else
                 {
                     foreach (string i in info.Split(SEPARATOR.First()))
                     {
                         line += $"{i.Trim()}\t";
                     }
                 }
                 sw.WriteLine(line.Trim());
             }
         }
         UserInfoHandler.ShowSuccess($"Saved to {path}");
     }
     catch (Exception exception) { UserInfoHandler.ShowException(exception); }
 }
        internal static bool RestoreCountry(EM_UI_MainForm mainForm, string backUpFolder = "")
        {
            bool reportSuccess = false;

            if (backUpFolder == string.Empty) //called via button in MainForm
            {
                FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
                folderBrowserDialog.SelectedPath = EMPath.Folder_BackUps(EM_AppContext.FolderEuromodFiles);
                folderBrowserDialog.Description  = "Please select the back-up folder";
                if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
                {
                    return(true);
                }
                backUpFolder  = folderBrowserDialog.SelectedPath;
                reportSuccess = true;
            }
            else //called from a catch-branch, i.e. using just generated back-up in Temp/BackUp
            {
                backUpFolder = EMPath.Folder_BackUps(EM_AppContext.FolderEuromodFiles) + backUpFolder;
            }

            string countryShortName = mainForm.GetCountryShortName();
            bool   isAddOn          = CountryAdministrator.IsAddOn(countryShortName);

            try
            {
                //check if backUpFolder contains the necessary files and if the files actually contain a backup of the loaded country/add-on ...
                string errorMessage;
                if (!Country.DoesFolderContainValidXMLFiles(countryShortName, out errorMessage, backUpFolder, isAddOn,
                                                            true)) //check if countryShortName corresponds to country's short name as stored in the XML-file
                {
                    throw new System.ArgumentException(errorMessage);
                }

                //... if yes, copy files form backup-folder to Countries-folder
                if (!Country.CopyXMLFiles(countryShortName, out errorMessage, backUpFolder))
                {
                    throw new System.ArgumentException(errorMessage);
                }

                mainForm.ReloadCountry();

                if (reportSuccess) //report success only if called via button (and not if called by a failed function)
                {
                    UserInfoHandler.ShowSuccess("Successfully restored using back-up stored in" + Environment.NewLine + backUpFolder + ".");
                }

                return(true);
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowError("Restore failed because of the error stated below." + Environment.NewLine +
                                          "You may want to try a manual restore via the button in the ribbon 'Country Tools'." + Environment.NewLine + Environment.NewLine +
                                          exception.Message);
                return(false);
            }
        }
        static internal void RemovePrivateComponents()
        {
            ProgressIndicator progressIndicator = new ProgressIndicator(RemovePrivate_BackgroundEventHandler, //the handler passed to the progress indicator will do the work (see below)
                                                                        "Removing Private Components");

            if (progressIndicator.ShowDialog() == System.Windows.Forms.DialogResult.OK) //regular termination, i.e user did not cancel the procedure
            {
                UserInfoHandler.ShowSuccess("Private components removed.");
            }
        }
Esempio n. 8
0
        void btnGenerate_Click(object sender, EventArgs e)
        {
            try
            {
                List <string> selectedCountries = new List <string>();
                foreach (object checkedItem in lstCountries.CheckedItems)
                {
                    selectedCountries.Add(checkedItem as string);
                }

                //outsource the time-consuming reading of country files to a backgroundworker showhing progress
                ProgressIndicator progressIndicator = new ProgressIndicator(Generate_BackgroundEventHandler, "Generating required info ...", selectedCountries);
                if (progressIndicator.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }

                //fill the tables (rather done here than in the backgroundworker is the latter causes problems with access to the tables (which belong to another process)
                Cursor = Cursors.WaitCursor;

                List <object> configFacades = progressIndicator.Result as List <object>;
                List <CountryConfigFacade> countryConfigFacades = configFacades.ElementAt(0) as List <CountryConfigFacade>;
                List <DataConfigFacade>    dataConfigFacades    = configFacades.ElementAt(1) as List <DataConfigFacade>;

                if (chkGenerateSystemProgress.Checked) //fill system progress table
                {
                    FillSystemTable(countryConfigFacades);
                }
                if (chkGenerateDatasetProgress.Checked) //fill dataset progress table
                {
                    FillDatasetTable(dataConfigFacades, selectedCountries);
                }
                if (chkGenerateCombinations.Checked) //fill combination table
                {
                    FillCombinationsTable(dataConfigFacades);
                }

                UserInfoHandler.ShowSuccess("Tables successfully generated.");
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowException(exception);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
Esempio n. 9
0
        internal void WriteToFile()
        {
            try
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Title           = "Write discrepancy marker info to file ...";
                openFileDialog.Filter          = "Text files (*.txt)|*.txt";
                openFileDialog.CheckPathExists = true;
                openFileDialog.CheckFileExists = false;
                openFileDialog.AddExtension    = true;
                openFileDialog.Multiselect     = false;

                if (openFileDialog.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }

                //store creation-date of info
                System.IO.StreamWriter txtWriter = new System.IO.StreamWriter(openFileDialog.FileName);
                txtWriter.WriteLine(_creationDate);

                //store concerned systems
                string strConcernedSystems = string.Empty;
                foreach (string systemID in _concernedSystems.Keys)
                {
                    strConcernedSystems += systemID + _idSeparator + _concernedSystems[systemID] + _entrySeparator;
                }
                txtWriter.WriteLine(strConcernedSystems);

                //store discrepancies
                string strDiscrepancies = string.Empty;
                foreach (string id in _discrepancies.Keys)
                {
                    strDiscrepancies += id + _idSeparator + _discrepancies[id].ToStoreFormat() + _entrySeparator;
                }
                txtWriter.WriteLine(strDiscrepancies);
                txtWriter.Close();

                UserInfoHandler.ShowSuccess("Information successfully stored in file " + openFileDialog.FileName);
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowException(exception);
            }
        }
Esempio n. 10
0
        static internal void Generate()
        {
            //get the necessary information from the user (path and version number)
            PublicVersionForm publicVersionForm = new PublicVersionForm();

            if (publicVersionForm.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            _publicVersionPath   = EMPath.AddSlash(publicVersionForm.GetPath());
            _publicVersionNumber = publicVersionForm.GetVersionNumber();

            ProgressIndicator progressIndicator = new ProgressIndicator(Generate_BackgroundEventHandler, //the handler passed to the progress indicator will do the work (see below)
                                                                        "Generating Public Version");

            if (progressIndicator.ShowDialog() == System.Windows.Forms.DialogResult.OK) //regular termination, i.e user did not cancel the procedure
            {
                UserInfoHandler.ShowSuccess("Pulic version successfully stored at '" + _publicVersionPath + ".'" + Environment.NewLine +
                                            "Change user interface's current project (via the menu item 'Open Project') to check the result.");
            }
        }
Esempio n. 11
0
        void btnRemoveBundles_Click(object sender, EventArgs e)
        {
            if (lvBundles.CheckedItems.Count == 0)
            {
                UserInfoHandler.ShowInfo("Please select the bundles you want to remove."); return;
            }

            string warningContent = (_removeReleases) ? Environment.NewLine + Environment.NewLine + "This will remove an already commited merge!" : string.Empty;

            if (UserInfoHandler.GetInfo("Are you sure you want to irrevocably delete " +
                                        (lvBundles.CheckedItems.Count == 1 && warningContent == string.Empty ? "this item?" : "these items?" +
                                         warningContent), MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            List <ReleaseInfo> bundles = new List <ReleaseInfo>();

            foreach (ListViewItem item in lvBundles.CheckedItems)
            {
                bundles.Add(item.Tag as ReleaseInfo);
            }

            Cursor = Cursors.WaitCursor;
            bool success = _vcAPI.RemoveReleases(bundles, _vcAPI.vc_projectInfo.ProjectId);

            if (success)
            {
                UserInfoHandler.ShowSuccess("Removal accomplished.");
            }
            else
            {
                UserInfoHandler.ShowError(_vcAPI.GetErrorMessage());
            }
            Cursor = Cursors.Default;

            Close();
        }
Esempio n. 12
0
        void btnOK_Click(object sender, EventArgs e)
        {
            if (GetSelectedCountries().Count == 0)
            {
                UserInfoHandler.ShowError("Please select one or more countries.");
                return;
            }

            try
            {
                string exportPath = EMPath.AddSlash(txtFolder.Text);
                if (!Directory.Exists(exportPath))
                {
                    UserInfoHandler.ShowError("'" + txtFolder.Text + "' is not a valid path.");
                    return;
                }

                List <string> arguments = new List <string>();
                arguments.Add(txtFolder.Text);
                arguments.Add(radTextFormat.Checked ? textFormat : withLineBreaks);
                arguments.AddRange(GetSelectedCountries());
                ProgressIndicator progressIndicator = new ProgressIndicator(SaveAsText_BackgroundEventHandler, "Saving parameter files formatted ...", arguments);
                if (progressIndicator.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }

                if (EM_Helpers.SaveConvertToBoolean(progressIndicator.Result) == true)
                {
                    UserInfoHandler.ShowSuccess("Successfully stored parameter files formatted at " + txtFolder.Text + ".");
                }
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowException(exception);
            }
        }
        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;
        }
Esempio n. 14
0
        internal bool LoadFromFile()
        {
            try
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Title           = "Load discrepancy marker info from file ...";
                openFileDialog.Filter          = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
                openFileDialog.CheckPathExists = true;
                openFileDialog.CheckFileExists = true;
                openFileDialog.AddExtension    = true;
                openFileDialog.Multiselect     = false;

                if (openFileDialog.ShowDialog() == DialogResult.Cancel)
                {
                    return(false);
                }

                System.IO.StreamReader txtReader = new System.IO.StreamReader(openFileDialog.FileName);

                //read creation-date of info
                string strCreationDate = txtReader.ReadLine();
                _creationDate = Convert.ToDateTime(strCreationDate);

                //read concerned systems
                _concernedSystems.Clear();
                string strConcernedSystems = txtReader.ReadLine();
                foreach (string strConcernedSystem in strConcernedSystems.Split(new string[] { _entrySeparator }, StringSplitOptions.None))
                {
                    List <string> idAndName = strConcernedSystem.Split(new string[] { _idSeparator }, StringSplitOptions.None).ToList <string>();
                    if (idAndName.Count == 2)
                    {
                        _concernedSystems.Add(idAndName.ElementAt(0), idAndName.ElementAt(1));
                    }
                }

                //read discrepancies
                _discrepancies.Clear();
                string strDiscrepancies = txtReader.ReadToEnd();
                foreach (string strDiscrepancy in strDiscrepancies.Split(new string[] { _entrySeparator }, StringSplitOptions.None))
                {
                    List <string> idAndDiscrepancy = strDiscrepancy.Split(new string[] { _idSeparator }, StringSplitOptions.None).ToList <string>();
                    if (idAndDiscrepancy.Count == 2)
                    {
                        Discrepancy discrepancy = new Discrepancy();
                        discrepancy.FromStoreFormat(idAndDiscrepancy.ElementAt(1));
                        _discrepancies.Add(idAndDiscrepancy.ElementAt(0), discrepancy);
                    }
                }

                if (_creationDate == null || _concernedSystems.Count == 0 || _discrepancies.Count == 0)
                {
                    throw new System.ArgumentException("The selected file does not seem to contain the relevant information."); //to hand the error to the error handler
                }
                UserInfoHandler.ShowSuccess("Information successfully loaded.");
                return(true);
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowError("Failed to read info for markers from file because of the following error:"
                                          + Environment.NewLine + Environment.NewLine + exception.Message);
                return(false);
            }
        }