Ejemplo n.º 1
0
 public string GetValue(string sectionName)
 {
     return(MemoryCacheHelper.Get <string>(String.Format(configCachingValueKey, sectionName, appSectionName), () =>
     {
         XPathNavigator navigator = GetSection(sectionName);
         return navigator == null ? null : navigator.Value;
         //return GetSection(sectionName).Value;
     },
                                           MemoryCacheHelper.FilePolicy(settingPath)));
 }
Ejemplo n.º 2
0
 public string CombineChildAttr(string selectionName, string childName, string attrName)
 {
     return(MemoryCacheHelper.Get <string>(String.Format(configCachingCombinAttr, selectionName, childName, attrName, appSectionName),
                                           () =>
     {
         XPathNavigator navigator = GetSection(selectionName);
         string attr = navigator.GetAttribute(attrName, string.Empty);
         XPathNodeIterator iterator = navigator.SelectChildren(childName, string.Empty);
         //iterator.Current.att
         while (iterator.MoveNext())
         {
             attr = String.Concat(attr, iterator.Current.GetAttribute(attrName, string.Empty));
         }
         return attr;
     },
                                           MemoryCacheHelper.FilePolicy(settingPath)));
 }
Ejemplo n.º 3
0
        public string GetChildAttr(string selectionName, string childName, string attrName)
        {
            string key = String.Format(KEY_GetChildrenAttr, selectionName, childName, attrName, appSectionName);

            return(MemoryCacheHelper.Get <string>(key.GetHashCode().ToString(),
                                                  () =>
            {
                XPathNavigator navigator = GetSection(selectionName);
                XPathNodeIterator iterator = navigator.SelectChildren(childName, string.Empty);
                if (iterator.MoveNext())
                {
                    return iterator.Current.GetAttribute(attrName, string.Empty);
                }
                return null;
            },
                                                  MemoryCacheHelper.FilePolicy(settingPath)));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 使用此方法必须把实现父节点ArrayOf<paramref name="T"/>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sectionName"></param>
        /// <returns></returns>
        public List <T> ToEntity <T>(string sectionName)
        {
            var navitagor = GetSection(sectionName);

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

            string key = String.Format("Caching_7F30C82D-14B9-41A5-9D04-EC42B88D4415_{0}_{1}", typeof(T), appSectionName);

            return(MemoryCacheHelper.Get <List <T> >(key, () =>
            {
                XmlSerializer serializer = new XmlSerializer(typeof(List <T>));
                XElement xElm = XElement.Parse(navitagor.OuterXml);
                using (var reader = xElm.CreateReader())
                {
                    return (List <T>)serializer.Deserialize(reader);
                }
            }, MemoryCacheHelper.FilePolicy(settingPath)));
        }