TVConfigs.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Xml;
  5. namespace CB.TVUCenter.Config
  6. {
  7. public class TVConfigs
  8. {
  9. private static string configPath = AppDomain.CurrentDomain.BaseDirectory + "Config\\TV.config";
  10. private static long _version = 0;
  11. private static TVConfigInfo _config = null;
  12. private TVConfigs() { }
  13. static TVConfigs()
  14. {
  15. LoadConfig();
  16. }
  17. public static void LoadConfig()
  18. {
  19. if (!File.Exists(configPath))
  20. return;
  21. var config = new TVConfigInfo();
  22. XmlDocument doc = new XmlDocument();
  23. doc.Load(configPath);
  24. var root = doc.SelectSingleNode("TVConfig");
  25. if (null != root)
  26. {
  27. var node = root.SelectSingleNode("Debug");
  28. config.Debug = null == node ? false : (node.InnerText.Trim() == "1" ? true : false);
  29. node = root.SelectSingleNode("ExEncryptKey");
  30. config.ExEncryptKey = null == node ? "5pyA5aW955qE55S16KeG6LWw5Yq/5Zu+5Zyo5b2p5ZCn572R" : node.InnerText.Trim();
  31. node = root.SelectSingleNode("TrendChartEncryptKey");
  32. config.TrendChartEncryptKey = null == node ? "5pyA5aW955qE55S16KeG6LWw5Yq/5Zu+5Zyo5b2p5ZCn572R" : node.InnerText.Trim();
  33. node = root.SelectSingleNode("InitImg");
  34. config.InitImg = null == node ? "" : node.InnerText.Trim();
  35. node = root.SelectSingleNode("InitVerticalImg");
  36. config.InitVerticalImg = null == node ? "" : node.InnerText.Trim();
  37. node = root.SelectSingleNode("BackgroundImg");
  38. config.BackgroundImg = null == node ? "" : node.InnerText.Trim();
  39. node = root.SelectSingleNode("BackgroundVerticalImg");
  40. config.BackgroundVerticalImg = null == node ? "" : node.InnerText.Trim();
  41. node = root.SelectSingleNode("ClearOnlineUserTime");
  42. config.ClearOnlineUserTime = null == node ? 5 : CB.Common.TypeConverter.StrToInt(node.InnerText.Trim());
  43. node = root.SelectSingleNode("UnLockTime");
  44. config.UnLockTime = null == node ? 120 : CB.Common.TypeConverter.StrToInt(node.InnerText.Trim());
  45. node = root.SelectSingleNode("ApiCallTimes");
  46. config.ApiCallTimes = null == node ? 60 : CB.Common.TypeConverter.StrToInt(node.InnerText.Trim());
  47. node = root.SelectSingleNode("ApiCallCycle");
  48. config.ApiCallCycle = null == node ? 1 : CB.Common.TypeConverter.StrToInt(node.InnerText.Trim());
  49. node = root.SelectSingleNode("DataCfgVersion");
  50. config.DataCfgVersion = null == node ? 0 : CB.Common.TypeConverter.StrToInt(node.InnerText.Trim());
  51. node = root.SelectSingleNode("ImgVersion");
  52. config.ImgVersion = null == node ? 0 : CB.Common.TypeConverter.StrToInt(node.InnerText.Trim());
  53. node = root.SelectSingleNode("ShowByBrowser");
  54. config.ShowByBrowser = null == node ? true : (node.InnerText.Trim() == "1" ? true : false);
  55. }
  56. _version = File.GetLastWriteTime(configPath).Ticks;
  57. _config = config;
  58. }
  59. public static TVConfigInfo GetConfig()
  60. {
  61. if (null == _config)
  62. {
  63. LoadConfig();
  64. return _config;
  65. }
  66. if (_version != File.GetLastWriteTime(configPath).Ticks)
  67. LoadConfig();
  68. return _config;
  69. }
  70. }
  71. }