config.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections.Generic;
  3. using Utils;
  4. namespace SiteCore
  5. {
  6. /// <summary>
  7. /// 网站的配置信息
  8. /// </summary>
  9. public class config
  10. {
  11. private Dictionary<string, string> _dics;
  12. /// <summary>
  13. /// 网站的配置信息
  14. /// </summary>
  15. public Dictionary<string, string> dics
  16. {
  17. get { return _dics; }
  18. }
  19. //------------------------------------------------------------
  20. private config() { loadAll(); }
  21. private static volatile config _instance;
  22. private static readonly Object _syncRoot = new object();
  23. public static config Instance
  24. {
  25. get
  26. {
  27. if (_instance == null)
  28. {
  29. lock (_syncRoot)
  30. {
  31. if (_instance == null) _instance = new config();
  32. }
  33. }
  34. return _instance;
  35. }
  36. }
  37. public void Reload()
  38. {
  39. loadAll();
  40. }
  41. private void loadAll()
  42. {
  43. initSiteSettings();
  44. }
  45. // ------------------------- site settings -------------------------
  46. private void initSiteSettings()
  47. {
  48. _dics = cfgHelper.Read(siteconfigAbsPath);
  49. //if (dic.Count <= 0) return;
  50. }
  51. private String getVal(Dictionary<String, String> dic, String key)
  52. {
  53. String val;
  54. dic.TryGetValue(key, out val);
  55. return val;
  56. }
  57. internal static readonly String siteconfigAbsPath = getSiteConfigAbsPath();
  58. private static String getSiteConfigAbsPath()
  59. {
  60. return PathHelper.Map(strUtil.Join(cfgHelper.ConfigRoot, "site.config"));
  61. }
  62. }
  63. }