Ejemplo n.º 1
0
        //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);
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
 public static void Save()
 {
     WeikeConfig.Instance().Save(_instance, typeof(T).Name);
 }