private void btnCheckPath_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; bool hasInsertedPath = true; string selectedPath = String.Empty; string insertedPath = txtImportFolder.Text; if (insertedPath == null || insertedPath == "") { Tools.UserInfoHandler.ShowError("Please insert or select a folder."); this.Cursor = Cursors.Default; return; } if (CountryAdministrator.ConsiderOldAddOnFileStructure(_fromAddOn)) { _importCountry = ImportExportAdministrator.GetImportAddOn_OldStyle(out selectedPath, hasInsertedPath, insertedPath); } else { _importCountry = ImportExportAdministrator.GetImportCountry(out selectedPath, _fromAddOn, hasInsertedPath, insertedPath); } if (_importCountry == null) { this.Cursor = Cursors.Default; return; } displayCountrySystems(); this.Cursor = Cursors.Default; }
private void btnOK_Click(object sender, EventArgs e) { if (txtImportFolder.Text == string.Empty) { UserInfoHandler.ShowError("Please select a version to compare with."); return; } Cursor = Cursors.WaitCursor; bool hasInsertedPath = true; string insertedPath = txtImportFolder.Text; string selectedPath = String.Empty; if (CountryAdministrator.ConsiderOldAddOnFileStructure(_fromAddOn)) { _importCountry = ImportExportAdministrator.GetImportAddOn_OldStyle(out selectedPath, hasInsertedPath, insertedPath); } else { _importCountry = ImportExportAdministrator.GetImportCountry(out selectedPath, _fromAddOn, hasInsertedPath, insertedPath); } if (_importCountry == null) { Cursor = Cursors.Default; return; } DialogResult = DialogResult.OK; Close(); }
private void btnSelectImportFolder_Click(object sender, EventArgs e) { string path = String.Empty; if (CountryAdministrator.ConsiderOldAddOnFileStructure(_fromAddOn)) { ImportExportAdministrator.GetImportAddOnPath_OldStyle(out string addOnPath, out string addOnShortName, out string fileName); path = fileName; } else { ImportExportAdministrator.GetImportCountryPath(_fromAddOn, out string importPath, out string countryShortName); path = importPath; } txtImportFolder.Text = path; }
void btnSelectImportFolder_Click(object sender, EventArgs e) { string path = string.Empty; if (CountryAdministrator.ConsiderOldAddOnFileStructure(_fromAddOn)) { _importCountry = ImportExportAdministrator.GetImportAddOn_OldStyle(out path); } else { _importCountry = ImportExportAdministrator.GetImportCountry(out path, _fromAddOn); } if (_importCountry == null) { return; } txtImportFolder.Text = path; displayCountrySystems(); }
void btnSelectVersion_Click(object sender, EventArgs e) { string shortName_varFileName, path, textToDisplay; if (_getVariablesChoices) { if (!GetImportVariablesPath(out path, out shortName_varFileName)) { return; } textToDisplay = EMPath.AddSlash(path) + shortName_varFileName; } else { bool oldStyle = CountryAdministrator.ConsiderOldAddOnFileStructure(_isAddOn); if (!(oldStyle ? ImportExportAdministrator.GetImportAddOnPath_OldStyle(out path, out shortName_varFileName, out string fileNameNew) : ImportExportAdministrator.GetImportCountryPath(_isAddOn, out path, out shortName_varFileName))) { return; } textToDisplay = !oldStyle ? path : EMPath.AddSlash(path) + Country.GetCountryXMLFileName(shortName_varFileName); } if (sender == btnSelectRemoteVersion) { txtRemoteVersion.Text = textToDisplay; _pathRemoteVersion = path; _nameRemoteVersion = shortName_varFileName; } else { txtParentVersion.Text = textToDisplay; _pathParentVersion = path; _nameParentVersion = shortName_varFileName; } }
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 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 } }
Boolean validateInsertedFields(string insertedPath, bool remote) { string countryShortName = string.Empty; string path; string fileName; string errorMessage; bool oldStyle = CountryAdministrator.ConsiderOldAddOnFileStructure(_isAddOn); //Variables if (_getVariablesChoices || oldStyle) { if (Path.GetExtension(insertedPath) != ".xml") { UserInfoHandler.ShowError("File extension should be .xml."); return(false); } if (_getVariablesChoices) { FileInfo fileInfo = new FileInfo(insertedPath); fileName = fileInfo.Name; if (!fileName.ToLower().Equals(EMPath.EM2_FILE_VARS.ToLower()) && !fileName.ToLower().Equals(EMPath.EM2_FILE_EXRATES.ToLower()) && !fileName.ToLower().Equals(EMPath.EM2_FILE_EXTENSIONS.ToLower()) && !fileName.ToLower().Equals(EMPath.EM2_FILE_HICP.ToLower())) { UserInfoHandler.ShowError("Only VARCONFIG.xml, HICPCONFIG.xml, EXCHANGERATESCONFIG.xml and SWITCHABLEPOLICYCONFIG.xml can be compared."); return(false); } } if (!File.Exists(insertedPath)) { UserInfoHandler.ShowError("File cannot be found: " + insertedPath + "."); return(false); } else { if (_getVariablesChoices) { FileInfo fileInfo = new FileInfo(insertedPath); path = fileInfo.Directory.FullName; fileName = fileInfo.Name; } else { FileInfo fileInfo = new FileInfo(insertedPath); fileName = fileInfo.Name.ToLower().EndsWith(".xml") ? fileInfo.Name.Substring(0, fileInfo.Name.Length - 4) : fileInfo.Name; if (!Country.DoesFolderContainValidXMLFiles(fileName, out errorMessage, fileInfo.DirectoryName, true)) { Tools.UserInfoHandler.ShowError("Failed to load add-on XML-files from '" + fileInfo.DirectoryName + "'."); return(false); } path = fileInfo.DirectoryName; } } } else //AddOn (new Style) or country files { //separate the country folder from the rest of the path, i.e. split '...\exportedToSomewhere\IT' into '...\exportedToSomewhere\' and 'IT' if (insertedPath.EndsWith("\\") || insertedPath.EndsWith("/")) { insertedPath = insertedPath.Substring(0, insertedPath.Length - 1); } int indexCountryFolder = insertedPath.LastIndexOfAny(new char[] { '\\', '/' }); if (indexCountryFolder < 0) { return(false); //unlikely, therefore dispense with error message } countryShortName = insertedPath.Substring(indexCountryFolder + 1); //name of folder is supposed to be name of country (this is accomplished like this by export and allows to load systems of other countries) if (!Country.DoesFolderContainValidXMLFiles(countryShortName, out errorMessage, insertedPath, _isAddOn)) { UserInfoHandler.ShowError("Failed to load country XML-files from '" + insertedPath + "'."); return(false); } path = insertedPath; fileName = countryShortName; } if (remote) { _pathRemoteVersion = path; _nameRemoteVersion = fileName; } else { _pathParentVersion = path; _nameParentVersion = fileName; } return(true); }