public virtual ICache GetCacher(string name)
        {
            ICache cache = cacheDic.TryGetValue(name);

            if (cache == null)
            {
                SettingNode node = cacheNodes.TryGetValue(name);

                if (node == null)
                {
                    cache = CacheUtil.GetDefaultCache();
                }
                else
                {
                    cache = CacheUtil.TryCreateCache(node, "type");
                    List <SettingNode> settingNodes = new List <SettingNode>()
                    {
                        node
                    };
                    settingNodes.Add(ToolSection.Instance.TryGetNode("cache/specifiableFactory"));
                    settingNodes.Add(ToolSection.Instance.TryGetNode("cache"));

                    CacheUtil.InitCache(cache, CacheUtil.GetCacheSettingNode(settingNodes, cache));
                }
                if (cache is AbstractCache)
                {
                    ((AbstractCache)cache).CacheName = name;
                }

                cacheDic[name] = cache;
            }
            return(cache);
        }
예제 #2
0
        public bool Contains(string path)
        {
            path = path.Replace("\\", "/");
            int f = path.IndexOf("/");

            if (f == -1)
            {
                string v;
                bool   hasAttr = Attributes.TryGetValue(path, out v);
                if (hasAttr)
                {
                    return(true);
                }
                return(Nodes.Any(o => o.Name == path));
            }

            string      name = path.Substring(0, f);
            SettingNode node = Nodes.FirstOrDefault(o => o.Name == name);

            if (node == null)
            {
                return(false);
            }
            return(node.Contains(path.Substring(f + 1)));
        }
예제 #3
0
        public string TryGetValue(string path)
        {
            path = path.Replace("\\", "/");
            int f = path.IndexOf("/");

            if (f == -1)
            {
                string v;
                if (Attributes.TryGetValue(path, out v))
                {
                    return(v);
                }
                return(null);
            }
            string name = path.Substring(0, f);

            SettingNode node = Nodes.FirstOrDefault(o => o.Name == name);

            if (node == null)
            {
                return(null);
            }

            return(node.TryGetValue(path.Substring(f + 1)));
        }
예제 #4
0
        protected override void DeserializeElement(System.Xml.XmlReader reader, bool serializeCollectionKey)
        {
            string    xml = reader.ReadOuterXml();
            XDocument doc = XDocument.Parse(xml);

            rootNode = SettingNode.ConvertFrom((XElement)doc.FirstNode, null);
        }
예제 #5
0
        public static IEnumerable <SettingNode> Combine(SettingNode node, IEnumerable <SettingNode> nodes)
        {
            List <SettingNode> items = new List <SettingNode>();

            items.Add(node);
            items.AddRange(nodes);
            return(items.Where(o => o != null));
        }
예제 #6
0
        public static SettingNode ConvertFrom(XElement element, SettingNode parent)
        {
            SettingNode node = new SettingNode();

            node.Name       = element.Name.LocalName;
            node.Parent     = parent;
            node.Attributes = element.Attributes().ToDictionary(o => o.Name.LocalName, o => o.Value);
            node.Nodes      = element.Elements().Select(o => ConvertFrom(o, node));
            return(node);
        }
예제 #7
0
 public static SettingNode TryGetNode(IEnumerable <SettingNode> settingNodes, string path)
 {
     foreach (SettingNode node in settingNodes)
     {
         SettingNode targetNode = node.TryGetNode(path);
         if (targetNode != null)
         {
             return(targetNode);
         }
     }
     return(null);
 }
예제 #8
0
 /// <summary>
 /// 尝试创建缓存实例
 /// </summary>
 /// <param name="node">允许为空</param>
 /// <param name="typePath"></param>
 /// <returns></returns>
 public static ICache TryCreateCache(SettingNode node, string typePath)
 {
     if (node != null)
     {
         string typeName = node.TryGetValue(typePath);
         if (!String.IsNullOrEmpty(typeName))
         {
             Type type = Type.GetType(typeName);
             return((ICache)FastActivator.Create(type));
         }
     }
     return(null);
 }
예제 #9
0
        internal static IList <SettingNode> GetSettingNodes(SettingNode settingNode)
        {
            List <SettingNode> settingNodes = new List <SettingNode>();

            if (settingNode != null && !settingNode.IsRoot)
            {
                settingNodes.Add(settingNode);
            }
            if (settingNode == null || !settingNode.IsRoot)
            {
                settingNodes.Add(ToolSection.Instance.RootNode);
            }
            return(settingNodes);
        }
예제 #10
0
        public SettingNode TryGetNode(string path)
        {
            path = path.Replace("\\", "/");
            int f = path.IndexOf("/");

            if (f == -1)
            {
                return(Nodes.FirstOrDefault(o => o.Name == path));
            }

            string      name = path.Substring(0, f);
            SettingNode node = Nodes.FirstOrDefault(o => o.Name == name);

            if (node == null)
            {
                return(null);
            }
            return(node.TryGetNode(path.Substring(f + 1)));
        }
예제 #11
0
        public IEnumerable <SettingNode> TryGetNodes(string path)
        {
            path = path.Replace("\\", "/");
            int f = path.IndexOf("/");

            if (f == -1)
            {
                return(Nodes.Where(o => o.Name == path));
            }

            string      name = path.Substring(0, f);
            SettingNode node = Nodes.FirstOrDefault(o => o.Name == name);

            if (node == null)
            {
                return(new List <SettingNode>());
            }
            return(node.TryGetNodes(path.Substring(f + 1)));
        }
예제 #12
0
        public static ICache GetDefaultCache(bool init = true)
        {
            SettingNode        cacheNode    = ToolSection.Instance.TryGetNode("cache");
            List <SettingNode> settingNodes = new List <SettingNode> {
                cacheNode
            };
            ICache cache = CacheUtil.TryCreateCache(cacheNode, "type");

            if (cache == null)
            {
                cache = new AspnetCache();
            }

            if (init)
            {
                CacheUtil.InitCache(cache, CacheUtil.GetCacheSettingNode(settingNodes, cache));
            }
            return(cache);
        }
예제 #13
0
        /// <summary>
        /// 获取缓存对象的设置项,可能返回空
        /// </summary>
        /// <param name="rootNode">允许为空</param>
        /// <param name="cache"></param>
        /// <returns></returns>
        public static IEnumerable <SettingNode> GetCacheSettingNode(IEnumerable <SettingNode> rootNodes, ICache cache)
        {
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }

            string name = cache.GetType().Name;

            name = name.Substring(0, 1).ToLower() + name.Substring(1);

            rootNodes = rootNodes.Where(o => o != null);
            List <SettingNode> settingNodes = new List <SettingNode>();

            foreach (SettingNode rootNode in rootNodes)
            {
                SettingNode targetNode = rootNode.TryGetNode(name);
                settingNodes.Add(targetNode);
                settingNodes.Add(rootNode);
            }
            return(settingNodes.Where(o => o != null));
        }
 public MissConfigurationException(SettingNode settingNode, string path)
     : this(new List <SettingNode>() { settingNode }, path)
 {
 }