public void ReadConfig(string folderName, AppSetting appSet, BackgroundWorker worker, IWin32Window own) { worker.ReportProgress(0, new WaitingFormProperties(Resources.Chargement, Resources.LodingConfigFiles)); foreach (XmlFile.ConfigFilesTypes ct in Enum.GetValues(typeof(XmlFile.ConfigFilesTypes))) { var fi = new FileInfo(folderName + "\\configs\\" + ct + ".config"); if (fi.Exists) { ConfigFiles[(int)ct] = new XmlFile(fi.FullName, ct); } else { MetroMessageBox.Show(own, Resources.MainForm_ReadWebConfig_Ce_dossier_ne_contient_pas_de_fichier_config_web, Resources.Erreur, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } DeserializeMainTabloidConfig(own); //read appsetting properties appSet.ReadAppSetting(ConfigFiles[(int)XmlFile.ConfigFilesTypes.appSettings], true); appSet.ReadConnectionSetting(ConfigFiles[(int)XmlFile.ConfigFilesTypes.connections], true, own); ////read tabloid config menu var tabloidmn = ConfigFiles[(int)XmlFile.ConfigFilesTypes.tabloidMenu].Xml.SelectSingleNode("/TabloidMenu"); if (tabloidmn != null) { TabloidConfigMenu.Deserialize("<TabloidMenu>" + tabloidmn.InnerXml + "</TabloidMenu>"); tabloidmn.InnerXml = ""; //remove tabloid content when readed } worker.ReportProgress(0, new WaitingFormProperties(Resources.Chargement, Resources.LodingGeoStyle)); //read olstyle file OlStyleCollection.Load(folderName); worker.ReportProgress(0, new WaitingFormProperties(Resources.Chargement, Resources.AutomaticViewBuilding)); AutomaticViewBuilder.SetTable(appSet.Schema);//automatic view is added on load and remove on save worker.ReportProgress(0, new WaitingFormProperties(Resources.Chargement, Resources.Validation)); WizardEvents.onConfigLoaded(appSet.Schema, own); }
/// <summary> /// Generate xmlfile object from tabloidconfig /// </summary> public void updateXML() { // set config file var cf = ConfigFiles[(int)XmlFile.ConfigFilesTypes.tabloid]; var n = cf.Xml.SelectSingleNode("/Tabloid"); //remove automatic created view foreach (TabloidConfigView v in TabloidConfig.Config.Views) { if (v.AutomaticCreation) { TabloidConfig.Config.Views.Remove(v); } } //Add current config to file var tabloid = TabloidConfig.Config.Serialize(); //restaure automatic created view AutomaticViewBuilder.SetTable(Program.AppSet.Schema); if (n != null) { n.InnerXml = tabloid == "" ? "" : tabloid.Substring(9, tabloid.Length - 19); } // set config menu file ConfigFiles[(int)XmlFile.ConfigFilesTypes.tabloidMenu].Xml.InnerXml = TabloidConfigMenu.ConfigMenu.Serialize(); // set appSettings menu file var nt = ConfigFiles[(int)XmlFile.ConfigFilesTypes.appSettings].Xml.SelectSingleNode("/appSettings"); if (nt != null) { nt.InnerXml = "\n" + AppSetting.GetAppSettingNodes(Program.AppSet, true); } // set connectionStrings menu file nt = ConfigFiles[(int)XmlFile.ConfigFilesTypes.connections].Xml.SelectSingleNode("/connectionStrings"); if (nt != null) { nt.InnerXml = "\n" + AppSetting.GetConnectionStringsNodes(Program.AppSet, true) + "\n"; } }
public static void onConfigLoaded(string schema, IWin32Window own) { //for mysql verify if default schema is database name if (Program.AppSet.ProviderType == Provider.MySql && Program.AppSet.Schema != getDataBaseNameFromConnectionString(Program.AppSet.ConnectionString)) { if (MetroMessageBox.Show(own, Properties.Resources.MySQLDifferentBaseName, Properties.Resources.Question, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { var connectionDataBaseName = getDataBaseNameFromConnectionString(Program.AppSet.ConnectionString); WizardSQLHelper.SetAllViewSchema(connectionDataBaseName); Program.AppSet.Schema = connectionDataBaseName; } } //verify role columun existance var tableColumns = new Dictionary <string, Dictionary <string, FieldDescriptionType> > { { "roles", new Dictionary <string, FieldDescriptionType> { { "ad_group", new FieldDescriptionType { type = DbType.String, extra = "(255)" } }, { "droits_limiteecr", new FieldDescriptionType { type = DbType.Int64, extra = "(20) DEFAULT 0" } }, //"numeric(20,0) DEFAULT 0" { "droits_limite", new FieldDescriptionType { type = DbType.Int64, extra = "(20) DEFAULT 1" } } } }, { "utilisateurs", new Dictionary <string, FieldDescriptionType> { { "theme", new FieldDescriptionType { type = DbType.String, extra = "(100)" } }, { "lastchatid", new FieldDescriptionType { type = DbType.Int64, extra = " DEFAULT 0" } }, { "password", new FieldDescriptionType { type = DbType.String, extra = "(100)" } }, { "token", new FieldDescriptionType { type = DbType.String, extra = "(40)" } }, { "ref", new FieldDescriptionType { type = DbType.Boolean } } } } }; foreach (var t in tableColumns) { string lastError; DataTable tableColumnsList = null; if (Program.AppSet.ProviderType == Provider.Postgres) { foreach (var cschema in WizardTools.Tools.GetSearchPath(Program.AppSet.ConnectionString)) { tableColumnsList = DataTools.Data(SqlCommands.SqlGetColums(t.Key, cschema), Program.AppSet.ConnectionString, out lastError);//c0 if (!string.IsNullOrEmpty(lastError)) { throw new Exception(lastError); } if (tableColumnsList.Rows.Count > 0) { break; } } } else { tableColumnsList = DataTools.Data(SqlCommands.SqlGetColums(t.Key, null), Program.AppSet.ConnectionString, out lastError);//c0 if (!string.IsNullOrEmpty(lastError)) { throw new Exception(lastError); } } var fieldColumnName = tableColumnsList.Columns[0].ColumnName; foreach (var c in t.Value) { if (tableColumnsList.Select(fieldColumnName + "='" + c.Key + "'").Length == 0)//field doesn't exist { var param = new[] { t.Key, c.Key, c.Value.ToString(), Program.AppSet.Schema }; var result = WizardSQLHelper.ExecuteFromFile("addField.sql", param, Program.AppSet.ConnectionString, own); } } } //Detect old role implementation if (!WizardTools.Tools.isTableExist("lst_roles")) { var result = MetroMessageBox.Show(own, Properties.Resources.WrongConfigVersion, Properties.Resources.Information, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.Yes) { AutomaticViewBuilder.setOldUtilisateurs(schema); //.SetTable(schema); var view = TabloidConfig.Config.Views["utilisateurs"]; //Todo role field could not be c4 on manual déclaration WizardSQLHelper.ConvertSimpleList(view, view.Colonnes["c4"], "lst_roles", own); removeView("utilisateurs"); removeView("roles"); removeView("lst_roles"); removeView("perso"); } } //Detect roles/utilisateur/perso définition if (!TabloidConfig.Config.Views["roles"].AutomaticCreation || !TabloidConfig.Config.Views["utilisateurs"].AutomaticCreation || !TabloidConfig.Config.Views["perso"].AutomaticCreation) { var dr = MetroMessageBox.Show(own, Properties.Resources.CustumRoleUsed, Properties.Resources.Information, MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dr == DialogResult.Yes) { removeView("roles"); removeView("utilisateurs"); removeView("perso"); } } //Detect empty salt grain if (string.IsNullOrEmpty(Program.AppSet.grainDeSable)) { Program.AppSet.grainDeSable = GetUniqueKey(7); TabloidConfig.Config.updateCurrentKey(Program.AppSet.grainDeSable); } }