/// <summary> /// 组件BuildCache /// </summary> /// <returns></returns> private static ICache BuildCache(CacheConfigProvider provider) { try { if (provider == null || string.IsNullOrEmpty(provider.Type) || provider.IsEnabled == false) { if (NDComponentConfig.Instance.IsThrowConfigException) { throw new ArgumentNullException("Invalid_Config_CacheProvider"); } return(new NullCache()); } string assemblyName = provider.Type.Split(',')[0]; string typeName = provider.Type.Split(',')[1]; Type type = Type.GetType(typeName + "," + assemblyName); return((ICache)Activator.CreateInstance(type)); } catch (Exception ex) { if (NDComponentConfig.Instance.IsThrowConfigException) { throw new ArgumentNullException("Invalid_Config_CacheProvider"); } return(new NullCache()); } }
//组建缓存 #region BuildCacheProvider private CacheConfigProvider BuildCacheProvider(XElement root) { CacheConfigProvider cacheProvider = null; XElement elm = root.Element("cacheprovider"); if (elm != null) { cacheProvider = new CacheConfigProvider(); cacheProvider.CacheDBName = elm.Attribute("dbname").Value; cacheProvider.CacheTableName = elm.Attribute("tablename").Value; cacheProvider.IsLogging = string.IsNullOrEmpty(elm.Attribute("islogging").NotNull("").Value) ? false : Convert.ToBoolean(elm.Attribute("islogging").NotNull("").Value); cacheProvider.Name = elm.Attribute("name").Value.NotEmpty(""); cacheProvider.Type = elm.Attribute("type").Value.NotEmpty(""); cacheProvider.IsEnabled = Convert.ToBoolean(elm.Attribute("isenabled").Value.NotEmpty("false")); foreach (var elmItem in elm.Elements("cacheitem")) { cacheProvider.CacheItem.Add(new CacheItem() { IsEnabled = Convert.ToBoolean(elmItem.Attribute("isenabled").Value.NotEmpty("false")), ConnStr = elmItem.Attribute("connstr").Value.NotEmpty(""), WeightValue = Convert.ToInt32(elmItem.Attribute("weightvalue").Value.NotEmpty("1")) }); } cacheProvider.Cache = BuildCache(cacheProvider); } return(cacheProvider); }