//static ConfigInfo() //{ WebCache.WebCacheClear += new WebCacheClearEventHandler(Clear); } public static T Instance() { if (_instance == null) { _instance = new T(); WeikeConfig.Instance().Node(_instance, typeof(T).Name); } return(_instance); }
public void Node(IConfigInfo _instance, string nodeName) { nodeName = "Weike/" + nodeName; WeikeConfig config = WeikeConfig.Instance(); XmlNode configSection = config.GetConfigSection(nodeName); if (configSection != null) { IEnumerator enumerator = configSection.ChildNodes.GetEnumerator(); while (enumerator.MoveNext()) { XmlNode node_current = enumerator.Current as XmlNode; if (node_current.NodeType == XmlNodeType.Comment) continue; Type t = _instance.GetType(); System.Reflection.PropertyInfo p = t.GetProperty(node_current.Attributes["key"].Value); if (p != null) p.SetValue(_instance, Convert.ChangeType(node_current.Attributes["value"].Value, p.PropertyType), null); } } }
public static WeikeConfig Instance() { WeikeConfig _instance = HttpRuntime.Cache.Get(key) as WeikeConfig; if (_instance == null) { string str2; if (HttpContext.Current != null) { str2 = HttpContext.Current.Server.MapPath("~/Weike.Config"); } else { str2 = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Weike.Config"); } _instance = new WeikeConfig(str2); CacheDependency dep = new CacheDependency(str2); HttpRuntime.Cache.Add(key, _instance, dep, DateTime.Now.AddYears(1), TimeSpan.Zero, CacheItemPriority.High, null); } return _instance; }
public void Save(IConfigInfo _instance, string nodeName) { nodeName = "Weike/" + nodeName; if (this.xmlDoc != null) { string str2; if (HttpContext.Current != null) { str2 = HttpContext.Current.Server.MapPath("~/Weike.Config"); } else { str2 = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Weike.Config"); } WeikeConfig config = WeikeConfig.Instance(); XmlNode configSection = config.GetConfigSection(nodeName); if (configSection != null) { IEnumerator enumerator = configSection.ChildNodes.GetEnumerator(); while (enumerator.MoveNext()) { XmlNode node_current = enumerator.Current as XmlNode; if (node_current.NodeType == XmlNodeType.Comment) continue; Type t = _instance.GetType(); System.Reflection.PropertyInfo p = t.GetProperty(node_current.Attributes["key"].Value); if (p != null) node_current.Attributes["value"].Value = p.GetValue(_instance, null).ToString(); } } this.xmlDoc.Save(str2); HttpRuntime.Cache.Remove(key); } }
public static void Save() { WeikeConfig.Instance().Save(_instance, typeof(T).Name); }