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

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using be.gaudry.model.config;
  5. using be.gaudry.bibliobrol.model;
  6. using be.gaudry.bibliobrol.model.enums;
  7. using System.IO;
  8. using be.gaudry.bibliobrol.model.dao.config;
  9. using be.gaudry.observer;
  10. using System.Configuration;
  11.  
  12. namespace be.gaudry.bibliobrol.config
  13. {
  14. /// <summary>
  15. /// Provides configuration values to use into the BiblioBrol application
  16. /// See also <code>be.gaudry.bibliobrol.model.dao.config.AbstractDBConfig</code> to get config values for
  17. /// the selected persistence.
  18. /// </summary>
  19. public class Config : Observable
  20. {
  21. #region declarations
  22. /// <summary>
  23. /// Provides the brol identifier of reference Mediabrol.
  24. /// This Mediabrol is used to store default roles for the persons.
  25. /// </summary>
  26. public const int BibliobrolId = 1;//838;
  27. public const string EidDllPath = "beidlib.dll";//used to invoke eid methods
  28. public const string Kernel32DLL = "kernel32.dll";
  29. private string defaultAWSSubscription = "0525E2PQ81DD7ZTWTK82";
  30. /// <summary>
  31. /// Class used to read the configuration file
  32. /// </summary>
  33. private Settings brolSettings;
  34. private Person owner;
  35. /// <summary>
  36. /// Used only to store owner.Id in the settings
  37. /// </summary>
  38. private int ownerId;
  39. private string defaultDataDirPath;
  40. /// <summary>
  41. /// User settings
  42. /// </summary>
  43. private String dataDirPath, imgBrolDir, imgPersDir, imgAppDir, proxyAddress,awsSubscription;
  44. private bool pCriticalError, pOpsResult, dispConsoleForm, cCriticalError, cOpsResult, cLowError, cBasicOps, cAdvancedOps, cDebug, cPersistentOps;
  45. private bool mobileApplication;
  46. private PERSON_DISPLAY personDisplay;
  47. private PERSISTENCE_TYPE persistentType;
  48. private Version dbVersion;
  49. #endregion
  50.  
  51. #region singleton
  52. /// <summary>
  53. /// Provides an access to the instance of the Config throught the static methods.
  54. /// No need to access from other classes.
  55. /// </summary>
  56. private static readonly Config instance = new Config();
  57.  
  58. /// <summary>
  59. /// Explicit static constructor to tell C# compiler not to mark type as beforefieldinit
  60. /// </summary>
  61. static Config()
  62. {
  63. }
  64. /// <summary>
  65. /// Constructor of Config
  66. /// </summary>
  67. /// <remarks>
  68. /// Using any values from the <code>DBConfig</code> object will causes a deadlock
  69. /// because DBConfig needs to call Config values like dataDirPath.
  70. /// Any value read from the DB in the Config instance building time will crash.
  71. /// </remarks>
  72. private Config()
  73. {
  74. // Get values from the application config file (in the application executable directory, volatile).
  75. mobileApplication = Properties.Settings.Default.mobileApplication;
  76. defaultDataDirPath = Path.Combine(
  77. Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
  78. "bibliobrol"
  79. );
  80. imgAppDir = "images/application";
  81. imgBrolDir = "images/ouvrages";
  82. imgPersDir = "images/personnes";
  83. // Get values from the xml config file (in the user defined directory, not volatile).
  84. loadXMLSettingsFile();
  85. }
  86.  
  87. /// <summary>
  88. /// Loads data from the settings file.
  89. /// </summary>
  90. /// <remarks>
  91. /// Using any values from the <code>DBConfig</code> object will causes a deadlock
  92. /// because DBConfig needs to call Config values like dataDirPath.
  93. /// Any value read from the DB in the Config instance building time will crash.
  94. /// </remarks>
  95. private void loadXMLSettingsFile()
  96. {
  97. #region set data dir path
  98. if (mobileApplication)
  99. {
  100. // The storage directory is a sub directory of the application directory.
  101. // The user may not use other name than bibliobrol.
  102. dataDirPath = Path.Combine(
  103. System.Windows.Forms.Application.StartupPath,
  104. "bibliobrol"
  105. );
  106. }
  107. else
  108. {
  109. dataDirPath = Properties.Settings.Default.dataDir;
  110. if (string.Empty.Equals(dataDirPath))
  111. {
  112. // Default storage path (in the user's documents directory).
  113. // The user may not use other name than bibliobrol.
  114. dataDirPath = defaultDataDirPath;
  115. }
  116. // Else a custom path is defined by the user.
  117. // The user may use any name, but this path must be redefined for each update (Click one implementation).
  118. }
  119. #endregion
  120.  
  121. brolSettings = new Settings(
  122. Path.Combine(dataDirPath, "settings.xml"),
  123. true
  124. );
  125. dbVersion = null;// forces to reload db version
  126.  
  127. #region load values
  128. ownerId = brolSettings.getSetting("application/owner", 0);
  129. try
  130. {
  131. int persistentTypeId = brolSettings.getSetting(
  132. "persistence/type",
  133. (int)PERSISTENCE_TYPE.Access
  134. );
  135. persistentType = (PERSISTENCE_TYPE)persistentTypeId;
  136. }
  137. catch (ArgumentException) { persistentType = PERSISTENCE_TYPE.Access;}
  138.  
  139. dispConsoleForm = brolSettings.getSetting("console/showExternal", false);
  140. pCriticalError = brolSettings.getSetting("popup/criticalError", true);
  141. pOpsResult = brolSettings.getSetting("popup/opsResult", true);
  142. cCriticalError = brolSettings.getSetting("console/criticalError", false);
  143. cOpsResult = brolSettings.getSetting("console/opsResult", false);
  144. cLowError = brolSettings.getSetting("console/lowError", false);
  145. cBasicOps = brolSettings.getSetting("console/basicOps", false);
  146. cAdvancedOps = brolSettings.getSetting("console/advancedOps", false);
  147. cDebug = brolSettings.getSetting("console/debug", false);
  148. cPersistentOps = brolSettings.getSetting("console/persistentOps", false);
  149.  
  150. try
  151. {
  152. personDisplay = (PERSON_DISPLAY)brolSettings.getSetting("display/person", (int)PERSON_DISPLAY.pseudo);
  153. }
  154. catch (ArgumentException) { personDisplay = PERSON_DISPLAY.pseudo; }
  155.  
  156. proxyAddress = brolSettings.getSetting("net/proxy", "");
  157. awsSubscription = brolSettings.getSetting("net/awsId", "");
  158. if (string.Empty.Equals(awsSubscription)) awsSubscription = defaultAWSSubscription;
  159. #endregion
  160. }
  161. #endregion
  162.  
  163. #region critical properties
  164. /// <summary>
  165. /// Provides methods to load or save settings.
  166. /// </summary>
  167. public static Settings BrolSettings
  168. {
  169. get { return instance.brolSettings; }
  170. }
  171. /// <summary>
  172. /// True if the application is executed from a removable storage.
  173. /// Used to generate pathes.
  174. /// </summary>
  175. public static bool IsMobileApplication
  176. {
  177. get { return instance.mobileApplication; }
  178. set
  179. {
  180. instance.mobileApplication = value;
  181. instance.loadXMLSettingsFile();
  182. }
  183. }
  184. public static PERSISTENCE_TYPE PersistentType
  185. {
  186. get { return instance.persistentType; }
  187. }
  188. /// <summary>
  189. /// Returns the path of the data directory.
  190. /// A "bibliobrol" directory in the user documents is used by default.
  191. /// If this BrolDev application is executed from a removable storage,
  192. /// the path is generated from the application path.
  193. /// </summary>
  194. public static string DataDirectory
  195. {
  196. get { return instance.dataDirPath; }
  197. }
  198. public static void saveDataDirectory(string dataPath)
  199. {
  200. Properties.Settings.Default.mobileApplication = instance.mobileApplication;
  201. Properties.Settings.Default.dataDir = (string.Empty.Equals(dataPath) || instance.defaultDataDirPath.Equals(dataPath)) ? "" : dataPath;
  202. Properties.Settings.Default.Save();
  203. instance.loadXMLSettingsFile();
  204. }
  205. public static void savePersistenceType(PERSISTENCE_TYPE persistentType)
  206. {
  207. instance.persistentType = persistentType;
  208. instance.brolSettings.putSetting("persistence/type", (int)persistentType, true);
  209. }
  210. #endregion
  211.  
  212. #region misc properties
  213.  
  214. /// <summary>
  215. /// Version of the persistant layer.
  216. /// Used to detect if a schema modification is needed
  217. /// </summary>
  218. public static Version DBVersion
  219. {
  220. get
  221. {
  222. if (instance.dbVersion == null)
  223. {
  224. try
  225. {
  226. string[] versionArray = model.dao.DAOFactory.Instance.getConfigDao().loadConfig("persistanceVersion").Split(new char[] { '.' });
  227.  
  228. int major, minor, build, revision;
  229. int.TryParse(versionArray[0], out major);
  230. int.TryParse(versionArray[1], out minor);
  231. int.TryParse(versionArray[2], out build);
  232. int.TryParse(versionArray[3], out revision);
  233.  
  234. instance.dbVersion = new Version(major, minor, build, revision);
  235. }
  236. catch
  237. {
  238. instance.dbVersion = new Version(0, 0, 0, 0);
  239. }
  240. }
  241. return instance.dbVersion;
  242. }
  243. }
  244.  
  245. /// <summary>
  246. /// Subscription on Amazon webservice
  247. /// </summary>
  248. public static String AwsSubscription
  249. {
  250. get { return instance.awsSubscription; }
  251. set { instance.awsSubscription = value; }
  252. }
  253.  
  254. /// <summary>
  255. /// Address of the client proxy to access the web
  256. /// </summary>
  257. public static string ProxyAddress
  258. {
  259. get { return instance.proxyAddress; }
  260. set { instance.proxyAddress = value; }
  261. }
  262. /// <summary>
  263. /// Owner of this application
  264. /// </summary>
  265. public static Person Owner
  266. {
  267. get
  268. {
  269. if (instance.ownerId <= 0)
  270. instance.notify(new Notification(Notification.VERBOSE.criticalError, "Configuration", new Exception("Aucun propriétaire n'est défini pour l'application. Veuillez en définir un."), instance));
  271. if (instance.owner == null || instance.owner.Equals(new Person()))
  272. {
  273. instance.owner = be.gaudry.bibliobrol.model.dao.DAOFactory.Instance.getPersonDao().loadPerson(instance.ownerId, false);
  274. }
  275. return instance.owner;
  276. }
  277. set
  278. {
  279. instance.owner = value;
  280. instance.ownerId = value.Id;
  281. }
  282. }
  283.  
  284. public static PERSON_DISPLAY PersonDisplay
  285. {
  286. get { return instance.personDisplay; }
  287. set { instance.personDisplay = value; }
  288. }
  289.  
  290.  
  291. #endregion
  292.  
  293. #region notifications properties and methods
  294. public static void instanceAddObserver(IObserver o)
  295. {
  296. instance.addObserver(o);
  297. }
  298. public static void instanceRemoveObserver(IObserver o)
  299. {
  300. instance.removeObserver(o);
  301. }
  302.  
  303. /// <summary>
  304. /// Shows or hides the <code>be.gaudry.bibliobrol.view.ConsoleForm</code>
  305. /// </summary>
  306. public static bool ShowConsoleForm
  307. {
  308. get { return instance.dispConsoleForm; }
  309. set
  310. {
  311. instance.dispConsoleForm = value;
  312. instance.notify(new Notification(Notification.VERBOSE.internalNotification, "display console", value.ToString(), instance));
  313. }
  314. }
  315. public static bool PopupCriticalError
  316. {
  317. get { return instance.pCriticalError; }
  318. set { instance.pCriticalError = value; }
  319. }
  320. public static bool PopupOpsResult
  321. {
  322. get { return instance.pOpsResult; }
  323. set { instance.pOpsResult = value; }
  324. }
  325. public static bool ConsoleCriticalError
  326. {
  327. get { return instance.cCriticalError; }
  328. set { instance.cCriticalError = value; }
  329. }
  330. public static bool ConsoleOpsResult
  331. {
  332. get { return instance.cOpsResult; }
  333. set { instance.cOpsResult = value; }
  334. }
  335. public static bool ConsoleLowError
  336. {
  337. get { return instance.cLowError; }
  338. set { instance.cLowError = value; }
  339. }
  340. public static bool ConsoleBasicOps
  341. {
  342. get { return instance.cBasicOps; }
  343. set { instance.cBasicOps = value; }
  344. }
  345. public static bool ConsoleAdvancedOps
  346. {
  347. get { return instance.cAdvancedOps; }
  348. set { instance.cAdvancedOps = value; }
  349. }
  350. public static bool ConsoleDebug
  351. {
  352. get { return instance.cDebug; }
  353. set { instance.cDebug = value; }
  354. }
  355. public static bool ConsolePersistentOps
  356. {
  357. get { return instance.cPersistentOps; }
  358. set { instance.cPersistentOps = value; }
  359. }
  360. #endregion
  361.  
  362. #region path properties
  363. /// <summary>
  364. /// Directory path of export files
  365. /// </summary>
  366. public static String ExportDir
  367. {
  368. get
  369. {
  370. return Path.Combine(DataDirectory, "export");
  371. }
  372. }
  373. /// <summary>
  374. /// Directory path of brol's images
  375. /// </summary>
  376. public static String ImgBrolDir
  377. {
  378. get
  379. {
  380. return Path.Combine(DataDirectory, instance.imgBrolDir);
  381. }
  382. }
  383. /// <summary>
  384. /// Directory path of person's images
  385. /// </summary>
  386. public static String ImgPersDir
  387. {
  388. get
  389. {
  390. return Path.Combine(DataDirectory, instance.imgPersDir);
  391. }
  392. }
  393. /// <summary>
  394. /// Directory path of application's images
  395. /// </summary>
  396. public static String ImgAppDir
  397. {
  398. get
  399. {
  400. return Path.Combine(DataDirectory, instance.imgAppDir);
  401. }
  402. }
  403. #endregion
  404.  
  405. #region save methods
  406. /// <summary>
  407. /// Save all settings
  408. /// </summary>
  409. public static void save()
  410. {
  411. instance.saveXMLSettingsFile();
  412. }
  413. private void saveXMLSettingsFile()
  414. {
  415. brolSettings.putSetting("application/owner", ownerId, false);
  416. brolSettings.putSetting("persistence/type", (int)persistentType, false);
  417.  
  418. brolSettings.putSetting("console/showExternal", dispConsoleForm, false);
  419. brolSettings.putSetting("popup/criticalError", pCriticalError, false);
  420. brolSettings.putSetting("popup/opsResult", pOpsResult, false);
  421. brolSettings.putSetting("console/criticalError", cCriticalError, false);
  422. brolSettings.putSetting("console/opsResult", cOpsResult, false);
  423. brolSettings.putSetting("console/lowError", cLowError, false);
  424. brolSettings.putSetting("console/basicOps", cBasicOps, false);
  425. brolSettings.putSetting("console/advancedOps", cAdvancedOps, false);
  426. brolSettings.putSetting("console/debug", cDebug, false);
  427. brolSettings.putSetting("console/persistentOps", cPersistentOps, false);
  428.  
  429. brolSettings.putSetting("display/person", (int)personDisplay, false);
  430.  
  431. brolSettings.putSetting("net/proxy", proxyAddress, false);
  432. if (!defaultAWSSubscription.Equals(awsSubscription))
  433. {
  434. brolSettings.putSetting("net/awsId", awsSubscription, false);
  435. }
  436. brolSettings.save();
  437. }
  438. #endregion
  439. }
  440. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/src/config/ 
IcôneNomTailleModification
Pas de sous-répertoires.
IcôneNomTailleModification
| _ Répertoire parent0 octets1734851563 22/12/2024 08:12:43
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/src/config/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.cs_Config.cs22.75 Ko31/10/2018 18:32:23-refusé-
Afficher le fichier .cs|.csConfig.cs16.76 Ko31/10/2018 18:32:23-refusé-

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.

Deutsche Übersetzung

Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.

Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.

Vielen Dank im Voraus.

Dokument erstellt 16/10/2009, zuletzt geändert 26/10/2018
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/cs-bibliobrol-source-rf-config/Config.cs.html

Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.