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) (440 lignes)
using System; using System.Collections.Generic; using System.Text; using be.gaudry.model.config; using be.gaudry.bibliobrol.model; using be.gaudry.bibliobrol.model.enums; using System.IO; using be.gaudry.bibliobrol.model.dao.config; using be.gaudry.observer; using System.Configuration; namespace be.gaudry.bibliobrol.config { /// <summary> /// Provides configuration values to use into the BiblioBrol application /// See also <code>be.gaudry.bibliobrol.model.dao.config.AbstractDBConfig</code> to get config values for /// the selected persistence. /// </summary> public class Config : Observable { #region declarations /// <summary> /// Provides the brol identifier of reference Mediabrol. /// This Mediabrol is used to store default roles for the persons. /// </summary> public const int BibliobrolId = 1;//838; public const string EidDllPath = "beidlib.dll";//used to invoke eid methods public const string Kernel32DLL = "kernel32.dll"; private string defaultAWSSubscription = "0525E2PQ81DD7ZTWTK82"; /// <summary> /// Class used to read the configuration file /// </summary> private Settings brolSettings; private Person owner; /// <summary> /// Used only to store owner.Id in the settings /// </summary> private int ownerId; private string defaultDataDirPath; /// <summary> /// User settings /// </summary> private String dataDirPath, imgBrolDir, imgPersDir, imgAppDir, proxyAddress,awsSubscription; private bool pCriticalError, pOpsResult, dispConsoleForm, cCriticalError, cOpsResult, cLowError, cBasicOps, cAdvancedOps, cDebug, cPersistentOps; private bool mobileApplication; private PERSON_DISPLAY personDisplay; private PERSISTENCE_TYPE persistentType; private Version dbVersion; #endregion #region singleton /// <summary> /// Provides an access to the instance of the Config throught the static methods. /// No need to access from other classes. /// </summary> /// <summary> /// Explicit static constructor to tell C# compiler not to mark type as beforefieldinit /// </summary> static Config() { } /// <summary> /// Constructor of Config /// </summary> /// <remarks> /// Using any values from the <code>DBConfig</code> object will causes a deadlock /// because DBConfig needs to call Config values like dataDirPath. /// Any value read from the DB in the Config instance building time will crash. /// </remarks> private Config() { // Get values from the application config file (in the application executable directory, volatile). mobileApplication = Properties.Settings.Default.mobileApplication; defaultDataDirPath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "bibliobrol" ); imgAppDir = "images/application"; imgBrolDir = "images/ouvrages"; imgPersDir = "images/personnes"; // Get values from the xml config file (in the user defined directory, not volatile). loadXMLSettingsFile(); } /// <summary> /// Loads data from the settings file. /// </summary> /// <remarks> /// Using any values from the <code>DBConfig</code> object will causes a deadlock /// because DBConfig needs to call Config values like dataDirPath. /// Any value read from the DB in the Config instance building time will crash. /// </remarks> private void loadXMLSettingsFile() { #region set data dir path if (mobileApplication) { // The storage directory is a sub directory of the application directory. // The user may not use other name than bibliobrol. dataDirPath = Path.Combine( System.Windows.Forms.Application.StartupPath, "bibliobrol" ); } else { dataDirPath = Properties.Settings.Default.dataDir; if (string.Empty.Equals(dataDirPath)) { // Default storage path (in the user's documents directory). // The user may not use other name than bibliobrol. dataDirPath = defaultDataDirPath; } // Else a custom path is defined by the user. // The user may use any name, but this path must be redefined for each update (Click one implementation). } #endregion Path.Combine(dataDirPath, "settings.xml"), true ); dbVersion = null;// forces to reload db version #region load values ownerId = brolSettings.getSetting("application/owner", 0); try { int persistentTypeId = brolSettings.getSetting( "persistence/type", (int)PERSISTENCE_TYPE.Access ); persistentType = (PERSISTENCE_TYPE)persistentTypeId; } catch (ArgumentException) { persistentType = PERSISTENCE_TYPE.Access;} dispConsoleForm = brolSettings.getSetting("console/showExternal", false); pCriticalError = brolSettings.getSetting("popup/criticalError", true); pOpsResult = brolSettings.getSetting("popup/opsResult", true); cCriticalError = brolSettings.getSetting("console/criticalError", false); cOpsResult = brolSettings.getSetting("console/opsResult", false); cLowError = brolSettings.getSetting("console/lowError", false); cBasicOps = brolSettings.getSetting("console/basicOps", false); cAdvancedOps = brolSettings.getSetting("console/advancedOps", false); cDebug = brolSettings.getSetting("console/debug", false); cPersistentOps = brolSettings.getSetting("console/persistentOps", false); try { personDisplay = (PERSON_DISPLAY)brolSettings.getSetting("display/person", (int)PERSON_DISPLAY.pseudo); } catch (ArgumentException) { personDisplay = PERSON_DISPLAY.pseudo; } proxyAddress = brolSettings.getSetting("net/proxy", ""); awsSubscription = brolSettings.getSetting("net/awsId", ""); if (string.Empty.Equals(awsSubscription)) awsSubscription = defaultAWSSubscription; #endregion } #endregion #region critical properties /// <summary> /// Provides methods to load or save settings. /// </summary> public static Settings BrolSettings { get { return instance.brolSettings; } } /// <summary> /// True if the application is executed from a removable storage. /// Used to generate pathes. /// </summary> public static bool IsMobileApplication { get { return instance.mobileApplication; } set { instance.mobileApplication = value; instance.loadXMLSettingsFile(); } } public static PERSISTENCE_TYPE PersistentType { get { return instance.persistentType; } } /// <summary> /// Returns the path of the data directory. /// A "bibliobrol" directory in the user documents is used by default. /// If this BrolDev application is executed from a removable storage, /// the path is generated from the application path. /// </summary> public static string DataDirectory { get { return instance.dataDirPath; } } public static void saveDataDirectory(string dataPath) { Properties.Settings.Default.mobileApplication = instance.mobileApplication; Properties.Settings.Default.dataDir = (string.Empty.Equals(dataPath) || instance.defaultDataDirPath.Equals(dataPath)) ? "" : dataPath; Properties.Settings.Default.Save(); instance.loadXMLSettingsFile(); } public static void savePersistenceType(PERSISTENCE_TYPE persistentType) { instance.persistentType = persistentType; instance.brolSettings.putSetting("persistence/type", (int)persistentType, true); } #endregion #region misc properties /// <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); } 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; } } /// <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; instance.ownerId = value.Id; } } public static PERSON_DISPLAY PersonDisplay { get { return instance.personDisplay; } set { instance.personDisplay = value; } } #endregion #region notifications properties and methods public static void instanceAddObserver(IObserver o) { instance.addObserver(o); } public static void instanceRemoveObserver(IObserver o) { instance.removeObserver(o); } /// <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 ConsolePersistentOps { get { return instance.cPersistentOps; } set { instance.cPersistentOps = value; } } #endregion #region path properties /// <summary> /// Directory path of export files /// </summary> public static String ExportDir { get { return Path.Combine(DataDirectory, "export"); } } /// <summary> /// Directory path of brol's images /// </summary> public static String ImgBrolDir { get { return Path.Combine(DataDirectory, instance.imgBrolDir); } } /// <summary> /// Directory path of person's images /// </summary> public static String ImgPersDir { get { return Path.Combine(DataDirectory, instance.imgPersDir); } } /// <summary> /// Directory path of application's images /// </summary> public static String ImgAppDir { get { return Path.Combine(DataDirectory, instance.imgAppDir); } } #endregion #region save methods /// <summary> /// Save all settings /// </summary> public static void save() { instance.saveXMLSettingsFile(); } private void saveXMLSettingsFile() { brolSettings.putSetting("application/owner", ownerId, false); brolSettings.putSetting("persistence/type", (int)persistentType, false); brolSettings.putSetting("console/showExternal", dispConsoleForm, false); brolSettings.putSetting("popup/criticalError", pCriticalError, false); brolSettings.putSetting("popup/opsResult", pOpsResult, false); brolSettings.putSetting("console/criticalError", cCriticalError, false); brolSettings.putSetting("console/opsResult", cOpsResult, false); brolSettings.putSetting("console/lowError", cLowError, false); brolSettings.putSetting("console/basicOps", cBasicOps, false); brolSettings.putSetting("console/advancedOps", cAdvancedOps, false); brolSettings.putSetting("console/debug", cDebug, false); brolSettings.putSetting("console/persistentOps", cPersistentOps, false); brolSettings.putSetting("display/person", (int)personDisplay, false); brolSettings.putSetting("net/proxy", proxyAddress, false); if (!defaultAWSSubscription.Equals(awsSubscription)) { brolSettings.putSetting("net/awsId", awsSubscription, false); } brolSettings.save(); } #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 | 1734868812 22/12/2024 13:00:12 |
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.
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 16/10/2009 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/cs-bibliobrol-source-rf-config/Config.cs.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.