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); }
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))); }
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))); }
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); }
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)); }
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); }
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); }
/// <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); }
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); }
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))); }
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))); }
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); }
/// <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) { }