_Config.cs
Description du code
_Config.cs est un fichier du projet BiblioBrol.Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/src/.
Projet BiblioBrol :
Gestion de media en CSharp.
Pour plus d'infos, vous pouvez consulter la brève analyse.
Code source ou contenu du fichier
Code c# (_Config.cs) (590 lignes)
using System; using System.Collections.Generic; using System.Text; using be.gaudry.bibliobrol.model; using System.Configuration; using System.IO; using System.Windows.Forms; using be.gaudry.observer; using be.gaudry.model.config; using be.gaudry.bibliobrol.model.enums; using be.gaudry.model.enums; using be.gaudry.model.exceptions; namespace be.gaudry.bibliobrol { public class Config : Observable { #region declarations /// <summary> /// Used to get the brol identifier of reference Bibliobrol. /// This brol is used to store default roles for the persons. /// </summary> public const int BibliobrolId = 1;//838; public const string eidDllPath = "beidlib.dll"; public const string Kernel32DLL = "kernel32.dll"; /// <summary> /// Class used to read the configuration file /// </summary> private Settings brolSettings; private Person owner; /// <summary> /// Used only to store for a short time owner.Id instead of creating a new Person /// </summary> private int ownerId; private String refDataDirPath, dataDirPath, imgBrolDir, imgPersDir, imgAppDir, useDB, accessSourceDB, awsSubscription, proxyAddress; private ACCESS_VERSION accessVersion; private Version dbVersion; private bool pCriticalError, pOpsResult, dispConsoleForm, cCriticalError, cOpsResult, cLowError, cBasicOps, cAdvancedOps, cDebug, firstUse; private PERSON_DISPLAY personDisplay; #endregion #region singleton // Explicit static constructor to tell C# compiler // not to mark type as beforefieldinit static Config() { } private Config() { refDataDirPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + Path.DirectorySeparatorChar + "bibliobrol"; dataDirPath = Properties.Settings.Default.dataDir; String.Format("{0}{1}settings.xml", getDataPath(), Path.DirectorySeparatorChar) ); awsSubscription = brolSettings.GetSetting("login/aws", "0525E2PQ81DD7ZTWTK82"); ownerId = brolSettings.GetSetting("general/ownerId", 0); //owner = BiblioBrol.Model.DAO.DAOFactory.Instance.getConfigDao().loadOwner(); imgAppDir = "images/application"; imgBrolDir = "images/ouvrages"; imgPersDir = "images/personnes"; useDB = brolSettings.GetSetting("persistance/useDB", "Access"); accessSourceDB = brolSettings.GetSetting("persistance/Access/filename", "data.bdb"); try { accessVersion = (ACCESS_VERSION)brolSettings.GetSetting("persistance/Access/version", (int)ACCESS_VERSION.Access03); } catch (ArgumentException) { accessVersion = ACCESS_VERSION.Access03; } dispConsoleForm = "true".Equals(brolSettings.GetSetting("console/visible", "false")); pCriticalError = "true".Equals(brolSettings.GetSetting("popup/criticalError", "true")); pOpsResult = "true".Equals(brolSettings.GetSetting("popup/opsResult", "true")); cCriticalError = "true".Equals(brolSettings.GetSetting("console/criticalError", "false")); cOpsResult = "true".Equals(brolSettings.GetSetting("console/opsResult", "false")); cLowError = "true".Equals(brolSettings.GetSetting("console/lowError", "false")); cBasicOps = "true".Equals(brolSettings.GetSetting("console/basicOps", "false")); cAdvancedOps = "true".Equals(brolSettings.GetSetting("console/advancedOps", "false")); cDebug = "true".Equals(brolSettings.GetSetting("console/debug", "false")); firstUse = "true".Equals(brolSettings.GetSetting("firstUse", "true")); try { personDisplay = (PERSON_DISPLAY)brolSettings.GetSetting("display/person", (int)PERSON_DISPLAY.pseudo); } catch (ArgumentException) { personDisplay = PERSON_DISPLAY.pseudo; } proxyAddress = brolSettings.GetSetting("net/proxy", ""); } public static Config Instance { get { return instance; } } #endregion #region getters and setters /// <summary> /// Version of the persistant layer. /// Used to detect if a schema modification is needed /// </summary> public static Version DBVersion { get { if (Instance.dbVersion == null) { try { string[] versionArray = model.dao.DAOFactory.Instance.getConfigDao().loadConfig("persistanceVersion").Split(new char[] { '.' }); int major, minor, build, revision; int.TryParse(versionArray[0], out major); int.TryParse(versionArray[1], out minor); int.TryParse(versionArray[2], out build); int.TryParse(versionArray[3], out revision); System.Console.WriteLine("test : " + major + "," + minor + "," + build + "," + revision); } catch { } } return Instance.dbVersion; } } /// <summary> /// Subscription on Amazon webservice /// </summary> public static String AwsSubscription { get { return Instance.awsSubscription; } set { Instance.awsSubscription = value; } } /// <summary> /// Address of the client proxy to access the web /// </summary> public static string ProxyAddress { get { return Instance.proxyAddress; } set { Instance.proxyAddress = value; //Instance.brolSettings.PutSetting("net/proxy", value); } } /// <summary> /// Owner of this application /// </summary> public static Person Owner { get { if (Instance.ownerId == 0) { Instance.owner = be.gaudry.bibliobrol.model.dao.DAOFactory.Instance.getPersonDao().loadPerson(Instance.ownerId, false); } return Instance.owner; } set { Instance.owner = value; } } /// <summary> /// Directory path to store all brol data /// </summary> public static String DataDirPath { get { return Instance.getDataPath(); } set { /*if (Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments).Equals(value)) { Instance.dataDirPath = ""; } else*/ Instance.dataDirPath = value; } } private string getDataPath() { return (String.Empty.Equals(dataDirPath)) ? refDataDirPath : dataDirPath; } /// <summary> /// Directory path of export files /// </summary> public static String ExportDir { get { s.Append(Path.DirectorySeparatorChar); s.Append("export"); s.Append(Path.DirectorySeparatorChar); return s.ToString(); } } /// <summary> /// Directory path of brol's images /// </summary> public static String ImgBrolDir { get { return Instance.imgBrolDir; } set { Instance.imgBrolDir = value; } } /// <summary> /// Directory relative path of brol's images /// </summary> public static String RelImgBrolDir { get { s.Append(Path.DirectorySeparatorChar); s.Append(Instance.imgBrolDir); s.Append(Path.DirectorySeparatorChar); return s.ToString(); } } /// <summary> /// Directory path of person's images /// </summary> public static String ImgPersDir { get { return Instance.imgPersDir; } set { Instance.imgPersDir = value; } } /// <summary> /// Directory relative path of person's images /// </summary> public static String RelImgPersDir { get { s.Append(Path.DirectorySeparatorChar); s.Append(Instance.imgPersDir); s.Append(Path.DirectorySeparatorChar); return s.ToString(); } } /// <summary> /// Directory path of application's images /// </summary> public static String ImgAppDir { get { return Instance.imgAppDir; } set { Instance.imgAppDir = value; } } /// <summary> /// Directory relative path of application's images /// </summary> public static String RelImgAppDir { get { s.Append(Path.DirectorySeparatorChar); s.Append(Instance.imgAppDir); s.Append(Path.DirectorySeparatorChar); return s.ToString(); } } public static String UseDB { get { return Instance.useDB; } } public static String AccessSourceDB { get { if (Instance.accessSourceDB.Contains(":")) { return Instance.accessSourceDB; } s.Append(Path.DirectorySeparatorChar); s.Append(Instance.accessSourceDB); return s.ToString(); } set { StringBuilder s; if (String.Empty.Equals(value)) { } else { s.Replace(Config.DataDirPath + Path.DirectorySeparatorChar, ""); } Instance.accessSourceDB = s.ToString(); Instance.brolSettings.PutSetting("persistance/Access/filename", Instance.accessSourceDB); } } public static ACCESS_VERSION AccessVersion { get { return Instance.accessVersion; } set { Instance.brolSettings.PutSetting("persistance/Access/version", (int)Instance.accessVersion); } } public static PERSON_DISPLAY PersonDisplay { get { return Instance.personDisplay; } set { Instance.personDisplay = value; } } /// <summary> /// Shows or hides the <code>be.gaudry.bibliobrol.view.ConsoleForm</code> /// </summary> public static bool ShowConsoleForm { get { return Instance.dispConsoleForm; } set { Instance.dispConsoleForm = value; Instance.notify(new Notification(Notification.VERBOSE.internalNotification, "display console", value.ToString(), Instance)); } } public static bool PopupCriticalError { get { return Instance.pCriticalError; } set { Instance.pCriticalError = value; } } public static bool PopupOpsResult { get { return Instance.pOpsResult; } set { Instance.pOpsResult = value; } } public static bool ConsoleCriticalError { get { return Instance.cCriticalError; } set { Instance.cCriticalError = value; } } public static bool ConsoleOpsResult { get { return Instance.cOpsResult; } set { Instance.cOpsResult = value; } } public static bool ConsoleLowError { get { return Instance.cLowError; } set { Instance.cLowError = value; } } public static bool ConsoleBasicOps { get { return Instance.cBasicOps; } set { Instance.cBasicOps = value; } } public static bool ConsoleAdvancedOps { get { return Instance.cAdvancedOps; } set { Instance.cAdvancedOps = value; } } public static bool ConsoleDebug { get { return Instance.cDebug; } set { Instance.cDebug = value; } } public static bool FirstUse { get { return Instance.firstUse; } set { Instance.firstUse = value; } } #endregion #region static methods #region specific save /// <summary> /// Set the Config.DataDirPath value and save it on the config file /// in the same directory than the executable file /// </summary> /// <param name="path">(String) Path of the data directory</param> public static void saveDataDir(String path) { Config.DataDirPath = path; if (Instance.refDataDirPath.Equals(Config.DataDirPath)) //saveAppSetting("dataPath", ""); Properties.Settings.Default.dataDir = ""; else //saveAppSetting("dataPath", Instance.dataDirPath); Properties.Settings.Default.dataDir = Instance.dataDirPath; Properties.Settings.Default.Save(); } /// <summary> /// Set the Config.Owner value, and save it /// </summary> /// <param name="owner"></param> public static void saveOwner(Person owner) { Config.Owner = owner; Instance.brolSettings.PutSetting("general/ownerId", owner.Id); } public static void savePersonDisplay(PERSON_DISPLAY personDisplay) { Config.PersonDisplay = personDisplay; Instance.brolSettings.PutSetting("display/person", (int)personDisplay); } public static void savePersonDisplay(int personDisplay) { try { savePersonDisplay((PERSON_DISPLAY)personDisplay); } catch (ArgumentException) { savePersonDisplay(PERSON_DISPLAY.pseudo); } } /// <summary> /// Set the Config.DataDirPath value and save it on the config file /// in the same directory than the executable file /// </summary> public static void saveAwsSubscription(String amazonSubscription) { Config.AwsSubscription = amazonSubscription; Instance.brolSettings.PutSetting("login/aws", amazonSubscription); } #endregion #region multi save public static void save() { //BiblioBrol.Model.DAO.DAOFactory.Instance.getConfigDao().saveOwner(owner); Instance.brolSettings.PutSetting("general/ownerId", Config.Owner.Id); str.AppendLine("\n\nPropriétaire :"); str.Append(Config.Owner.ToString()); //str.Append(" ["); //str.Append(Config.Owner.Id.ToString()); //str.Append("]"); saveDirsPath(str); saveConsolePrefs(str); } public static void saveConsolePrefs(StringBuilder str) { str.AppendLine("\n\nPréférences notifications : "); Instance.brolSettings.PutSetting("console/visible", Instance.dispConsoleForm); str.Append("\nAfficher la console : "); str.Append(Instance.dispConsoleForm.ToString()); Instance.brolSettings.PutSetting("popup/criticalError", Instance.pCriticalError); str.Append("\nErreur critique (popup) : "); str.Append(Instance.pCriticalError.ToString()); Instance.brolSettings.PutSetting("console/criticalError", Instance.cCriticalError); str.Append("\nErreur critique (console) : "); str.Append(Instance.cCriticalError.ToString()); Instance.brolSettings.PutSetting("popup/opsResult", Instance.pOpsResult); str.Append("\nRésultat d'opération (popup) : "); str.Append(Instance.pOpsResult.ToString()); Instance.brolSettings.PutSetting("console/opsResult", Instance.cOpsResult); str.Append("\nRésultat d'opération (console) : "); str.Append(Instance.cOpsResult.ToString()); Instance.brolSettings.PutSetting("console/basicOps", Instance.cBasicOps); str.Append("\nOpération de base : "); str.Append(Instance.cBasicOps.ToString()); Instance.brolSettings.PutSetting("console/advancedOps", Instance.cAdvancedOps); str.Append("\nOpération avancée : "); str.Append(Instance.cAdvancedOps.ToString()); Instance.brolSettings.PutSetting("console/lowError", Instance.cLowError); str.Append("\nErreur non bloquante : "); str.Append(Instance.cLowError.ToString()); Instance.brolSettings.PutSetting("console/debug", Instance.cDebug); str.Append("\nDebug (requêtes) : "); str.Append(Instance.cDebug.ToString()); } private static void saveDirsPath(StringBuilder str) { str.AppendLine("\n\nRépertoire : "); String key = "dataPath"; String value = ""; if (!Instance.refDataDirPath.Equals(Config.DataDirPath)) value = Instance.dataDirPath; if(saveAppSetting(key, value)) str.AppendLine((value == "") ? Config.DataDirPath : value); else str.AppendLine("Valeur non sauvée"); } #endregion #region save application settings (in the exe directory) /// <summary> /// Be carefull : the value may be lost after an application update /// Save a setting from memory to config file /// We don't need to provide the value (value is read from the setting into memory) /// </summary> /// <param name="key"></param> /// <returns></returns> public static bool saveAppSetting(String key) { try { String value = ConfigurationManager.AppSettings[key]; return Config.saveAppSetting(key, value); } catch (NullReferenceException nre) { Instance.notify(new Notification(Notification.VERBOSE.error, "Sauvegarde de la configuration", "soit le fichier de configuration n'est pas présent (il doit se trouver dans le même répertoire que l'application), soit il est incomplet ou endommagé.", nre, Instance)); } catch (Exception e) { Instance.notify(new Notification(Notification.VERBOSE.error, "Sauvegarde de la configuration", e, Instance)); } return false; } /// <summary> /// Be carefull : the value may be lost after an application update /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <returns></returns> public static bool saveAppSetting(String key, String value) { String exePath = System.IO.Path.Combine(Environment.CurrentDirectory, "BiblioBrol.exe"); Configuration config = ConfigurationManager.OpenExeConfiguration(exePath); try { config.AppSettings.Settings[key].Value = value; ConfigurationManager.AppSettings[key] = value; } catch (NullReferenceException nre) { Instance.notify(new Notification(Notification.VERBOSE.criticalError, "Sauvegarde d'une valeur de configuration", "Soit le fichier de configuration n'est pas présent (il doit se trouver dans le même répertoire que l'application), soit il est incomplet ou endommagé.", nre, Instance)); } catch (Exception e) { Instance.notify(new Notification(Notification.VERBOSE.error, "Sauvegarde d'une valeur de configuration", e, Instance)); } try { config.Save(ConfigurationSaveMode.Modified); Instance.notify(new Notification(Notification.VERBOSE.advancedOperation, "Configuration " + key + " sauvée avec la valeur " + value, Instance)); } catch (ConfigurationException cEEx) { Instance.notify(new Notification(Notification.VERBOSE.error, "Sauvegarde d'une valeur de configuration", cEEx, Instance)); return false; } return true; } #endregion #endregion } }
Structure et Fichiers du projet
Afficher/masquer...Icône | Nom | Taille | Modification |
Pas de sous-répertoires. | |||
Icône | Nom | Taille | Modification |
| _ | Répertoire parent | 0 octets | 1732432401 24/11/2024 08:13:21 |
Utilisation de l'explorateur de code
- Navigation :
- Un clic sur une icône de répertoire ouvre ce répertoire pour en afficher les fichiers.
- Lorsque le répertoire en cours ne contient pas de sous-répertoires il est possible de remonter vers le répertoire parent.
- La structure de répertoires en treetable (tableau en forme d'arborescence) n'est plus possibledans cette version.
- Un clic sur une icône de fichier ouvre ce fichier pour en afficher le code avec la coloration syntaxique adaptée en fonction du langage principal utilisé dans le fichier.
- Affichage :
- Il est possible de trier les répertoires ou les fichiers selon certains critères (nom, taille, date).
- Actions :
- Les actions possible sur les fichiers dépendent de vos droits d'utilisateur sur le site. Veuillez activer le mode utilisateur pour activer les actions.
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 16/10/2009, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/cs-bibliobrol-source-rf-config/_Config.cs.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.