using System; using System.Collections.Generic; using System.IO; using System.Xml; namespace CB.TVUCenter.Config { public class TVConfigs { private static string configPath = AppDomain.CurrentDomain.BaseDirectory + "Config\\TV.config"; private static long _version = 0; private static TVConfigInfo _config = null; private TVConfigs() { } static TVConfigs() { LoadConfig(); } public static void LoadConfig() { if (!File.Exists(configPath)) return; var config = new TVConfigInfo(); XmlDocument doc = new XmlDocument(); doc.Load(configPath); var root = doc.SelectSingleNode("TVConfig"); if (null != root) { var node = root.SelectSingleNode("Debug"); config.Debug = null == node ? false : (node.InnerText.Trim() == "1" ? true : false); node = root.SelectSingleNode("ExEncryptKey"); config.ExEncryptKey = null == node ? "5pyA5aW955qE55S16KeG6LWw5Yq/5Zu+5Zyo5b2p5ZCn572R" : node.InnerText.Trim(); node = root.SelectSingleNode("TrendChartEncryptKey"); config.TrendChartEncryptKey = null == node ? "5pyA5aW955qE55S16KeG6LWw5Yq/5Zu+5Zyo5b2p5ZCn572R" : node.InnerText.Trim(); node = root.SelectSingleNode("InitImg"); config.InitImg = null == node ? "" : node.InnerText.Trim(); node = root.SelectSingleNode("InitVerticalImg"); config.InitVerticalImg = null == node ? "" : node.InnerText.Trim(); node = root.SelectSingleNode("BackgroundImg"); config.BackgroundImg = null == node ? "" : node.InnerText.Trim(); node = root.SelectSingleNode("BackgroundVerticalImg"); config.BackgroundVerticalImg = null == node ? "" : node.InnerText.Trim(); node = root.SelectSingleNode("ClearOnlineUserTime"); config.ClearOnlineUserTime = null == node ? 5 : CB.Common.TypeConverter.StrToInt(node.InnerText.Trim()); node = root.SelectSingleNode("UnLockTime"); config.UnLockTime = null == node ? 120 : CB.Common.TypeConverter.StrToInt(node.InnerText.Trim()); node = root.SelectSingleNode("ApiCallTimes"); config.ApiCallTimes = null == node ? 60 : CB.Common.TypeConverter.StrToInt(node.InnerText.Trim()); node = root.SelectSingleNode("ApiCallCycle"); config.ApiCallCycle = null == node ? 1 : CB.Common.TypeConverter.StrToInt(node.InnerText.Trim()); node = root.SelectSingleNode("DataCfgVersion"); config.DataCfgVersion = null == node ? 0 : CB.Common.TypeConverter.StrToInt(node.InnerText.Trim()); node = root.SelectSingleNode("ImgVersion"); config.ImgVersion = null == node ? 0 : CB.Common.TypeConverter.StrToInt(node.InnerText.Trim()); node = root.SelectSingleNode("ShowByBrowser"); config.ShowByBrowser = null == node ? true : (node.InnerText.Trim() == "1" ? true : false); } _version = File.GetLastWriteTime(configPath).Ticks; _config = config; } public static TVConfigInfo GetConfig() { if (null == _config) { LoadConfig(); return _config; } if (_version != File.GetLastWriteTime(configPath).Ticks) LoadConfig(); return _config; } } }