Example #1
0
        /// <summary>
        /// 从XML文件中读取字符串,转换成字典,并缓存起来
        /// </summary>
        /// <returns></returns>
        protected virtual IDictionary <string, IList <SettingForCaching> > GetAllGlobalSettingsCached()
        {
            var xmlCacheDependency = CommonHelper.MapPath(c_XmlCacheDependency);
            var cacheKey           = new ScdCacheKey(ScdCacheCategory.ConfigFile, xmlCacheDependency.Replace("/", "_"));
            Dictionary <string, IList <SettingForCaching> > dictionary
                = _cacheManager.Get <Dictionary <string, IList <SettingForCaching> > >(cacheKey);

            if (dictionary == null)
            {
                string      fileName = Utilities.MapPath(c_XmlCacheDependency);
                XmlDocument doc      = new XmlDocument();
                doc.Load(fileName);

                XmlNodeList nodes = doc.DocumentElement.SelectNodes("i");
                dictionary = new Dictionary <string, IList <SettingForCaching> >();
                foreach (XmlNode node in nodes)
                {
                    SettingForCaching settingForCaching = new SettingForCaching();
                    settingForCaching.LoadByXmlNode(node);
                    var resourceName = settingForCaching.Name;
                    if (!dictionary.ContainsKey(resourceName))
                    {
                        //first setting
                        dictionary.Add(resourceName, new List <SettingForCaching>()
                        {
                            settingForCaching
                        });
                    }
                    else
                    {
                        //already added
                        //most probably it's the setting with the same name but for some certain store (storeId > 0)
                        dictionary[resourceName].Add(settingForCaching);
                    }
                }

                //压入缓存
                _cacheManager.AddCache(cacheKey, dictionary, xmlCacheDependency);
            }
            return(dictionary);
        }