protected override string SetCacheLock() { if (_eum == null) { return(""); } foreach (var fieldInfo in _enum.GetFields()) { //判断名称是否相等 if (fieldInfo.Name != _enumName) { continue; } //反射出自定义属性 foreach (Attribute attr in fieldInfo.GetCustomAttributes(true)) { //类型转换找到一个Description,用Description作为成员名称 var dscript = attr as DisplayAttribute; if (dscript == null) { continue; } lock (LockObject) { if (!CacheList.ContainsKey(Key)) { CacheList.Add(Key, dscript.Name); } } return(dscript.Name); } } //如果没有检测到合适的注释,则用默认名称 return(_enumName); }
protected override object SetCacheLock() { lock (Sync) { return(CacheList.ContainsKey(Key) ? CacheList[Key] : null); } }
protected override IEnumerable <ICustomInterceptor> SetCacheLock() { lock (Sync) { return(CacheList.ContainsKey(Key) ? CacheList[Key] : null); } }
protected override ContextPhysicsMap SetCacheLock() { lock (LockObject) { if (!CacheList.ContainsKey(Key)) { CacheList.Add(Key, new ContextPhysicsMap(Key)); } } return(CacheList[Key]); }
protected override Func <IDependencyResolver, object[], object> SetCacheLock() { lock (Sync) { return(CacheList.ContainsKey(Key) ? CacheList[Key] : default(Func <IDependencyResolver, object[], object>)); } }
/// <summary> /// 删除缓存 /// </summary> private void RemoveLock() { lock (Sync) { if (CacheList.ContainsKey(Key)) { CacheList.Remove(Key); } } }
protected override IDictionary <Type, Dependency> SetCacheLock() { lock (Sync) { if (CacheList.ContainsKey(Key)) { return(CacheList[Key]); } return(CacheList[Key] = new ConcurrentDictionary <Type, Dependency>()); } }
protected override IEnumerable <PropertyInfo> SetCacheLock() { lock (Sync) { if (CacheList.ContainsKey(Key)) { return(CacheList[Key]); } return(CacheList[Key] = new List <PropertyInfo>(0)); } }
protected override IEnumerable <Tuple <IScopedResolver, Dependency> > SetCacheLock() { lock (Sync) { if (CacheList.ContainsKey(Key)) { return(CacheList[Key]); } return(CacheList[Key] = new List <Tuple <IScopedResolver, Dependency> >()); } }
/// <summary> /// 获取缓存 /// </summary> protected override IEnumerable <IResolverCallSite> SetCacheLock() { lock (Sync) { if (CacheList.ContainsKey(Key)) { return(CacheList[Key]); } return(CacheList[Key] = new List <IResolverCallSite>()); } }
/// <summary> /// 当缓存不存在时,上锁加入缓存 /// </summary> protected override Func <object[], object> SetCacheLock() { lock (LockObject) { if (CacheList.ContainsKey(Key)) { return(CacheList[Key]); } //缓存中没有找到,新建一个构造函数的委托 return(CacheList[Key] = ExpressionHelper.CreateInstance(_type, _parameterTypes)); } }
/// <inherit /> protected override object SetCacheLock() { lock (LockObject) { if (CacheList.ContainsKey(Key)) { return(CacheList[Key]); } //缓存中没有找到,新建一个构造函数的委托 return(CacheList[Key] = Activator.CreateInstance(_type, _parameterTypes)); } }
/// <inherit /> protected override Func <object[], object> SetCacheLock() { lock (LockObject) { if (CacheList.ContainsKey(Key)) { return(CacheList[Key]); } var method = _type.GetMethod(_methodName, BindingFlags.Static | BindingFlags.Public); //缓存中没有找到,新建一个构造函数的委托 return(CacheList[Key] = param => method.Invoke(null, param)); } }
protected override Func <object, object> SetCacheLock() { lock (LockObject) { if (CacheList.ContainsKey(Key)) { return(CacheList[Key]); } //缓存中没有找到,新建一个构造函数的委托 return(CacheList[Key] = ExpressionHelper.GetValue(Key)); } }
/// <inherit /> protected override TValue SetCacheLock() { if (_initCache == null) { return(default(TValue)); } lock (LockObject) { if (!CacheList.ContainsKey(Key)) { CacheList.Add(Key, _initCache()); } } return(CacheList[Key]); }
/// <summary> /// 当缓存不存在时,上锁加入缓存 /// </summary> protected override Type SetCacheLock() { lock (LockObject) { if (CacheList.ContainsKey(Key)) { return(CacheList[Key]); } //缓存中没有找到,新建一个构造函数的委托 var val = _isListProperty ? Dynamics.CreateClassType(_lstAddPropertys, _constructors, _baseType) : Dynamics.CreateClassType(_dicAddPropertys, _baseType); return(CacheList[Key] = val); } }
/// <summary> /// 删除缓存 /// </summary> private void RemoveLock() { lock (Sync) { if (CacheList.ContainsKey(Key)) { CacheList.Remove(Key); } else { throw new ArgumentException("尝移除不存在的配置失败。"); } } }
protected override string SetCacheLock() { lock (LockObject) { if (CacheList.ContainsKey(Key)) { return(CacheList[Key]); } DbInfo dbInfo = Key; CacheList.Add(Key, AbsDbProvider.CreateInstance(dbInfo.DataType, dbInfo.DataVer).CreateDbConnstring(dbInfo.UserID, dbInfo.PassWord, dbInfo.Server, dbInfo.Catalog, dbInfo.DataVer, dbInfo.ConnectTimeout, dbInfo.PoolMinSize, dbInfo.PoolMaxSize, dbInfo.Port)); } return(CacheList[Key]); }
/// <summary> /// 删除缓存 /// </summary> private void RemoveLock() { lock (Sync) { if (!CacheList.ContainsKey(Key)) { return; } if (Key.Item2.ImplementationInstance == null) { var disposable = CacheList[Key] as IDisposable; disposable?.Dispose(); } CacheList.Remove(Key); } }
protected override SortDelete SetCacheLock() { lock (LockObject) { if (CacheList.ContainsKey(Key)) { return(CacheList[Key]); } //缓存中没有找到,新建一个实例 var sortDelete = new SortDelete { Name = _name, FieldType = _field, Value = _value }; sortDelete.Init(_entityType); return(CacheList[Key] = sortDelete); } }
protected override string SetCacheLock() { lock (LockObject) { if (CacheList.ContainsKey(Key)) { return(CacheList[Key]); } DbInfo dbInfo = Key; if (dbInfo == null) { Log.LogManger.Log.Error("未设置数据库配置文件"); return(null); } CacheList.Add(Key, AbsDbProvider.CreateInstance(dbInfo.DataType, dbInfo.DataVer).CreateDbConnstring(dbInfo.Server, dbInfo.Port, dbInfo.UserID, dbInfo.PassWord, dbInfo.Catalog, dbInfo.DataVer, dbInfo.Additional, dbInfo.ConnectTimeout, dbInfo.PoolMinSize, dbInfo.PoolMaxSize)); } return(CacheList[Key]); }
protected override SetTypesInitializersPair SetCacheLock() { lock (LockObject) { if (CacheList.ContainsKey(Key)) { return(CacheList[Key]); } var dbContextParam = Expression.Parameter(typeof(DbContext), "_context"); var initDelegates = new List <Action <DbContext> >(); // 一个DbContext对象下的所有Set实体类型 var setTypeList = new Dictionary <Type, List <string> >(); // 取得所有Set属性 foreach (var entityMap in ContextMapCacheManger.Cache(Key).EntityMapList) { // 实体类型,Set的泛型类型 var entityType = entityMap.Value != null?entityMap.Key.PropertyType.GetGenericArguments()[0] : null; List <string> propertyName; // 查找这个Set类在当前DbContext中,出现过几次,并记录属性。 if (!setTypeList.TryGetValue(entityMap.Key.PropertyType, out propertyName)) { propertyName = new List <string>(); setTypeList[entityMap.Key.PropertyType] = propertyName; } propertyName.Add(entityMap.Key.Name); // 属性set方法 var setter = entityMap.Key.GetSetMethod(nonPublic: true); if (setter != null && setter.IsPublic) { // 上下文的Set方法(不同Set,提供不同的方法) MethodInfo setMethod = null; switch (entityMap.Key.PropertyType.Name) { case "TableSet`1": setMethod = SetInitializer.TableSetMethod.MakeGenericMethod(entityType); break; case "TableSetCache`1": setMethod = SetInitializer.TableSetCacheMethod.MakeGenericMethod(entityType); break; case "ViewSet`1": setMethod = SetInitializer.ViewSetMethod.MakeGenericMethod(entityType); break; case "ViewSetCache`1": setMethod = SetInitializer.ViewSetCacheMethod.MakeGenericMethod(entityType); break; case "ProcSet`1": setMethod = SetInitializer.ProcSetMethod.MakeGenericMethod(entityType); break; case "SqlSet`1": setMethod = SetInitializer.SqlSetMethod.MakeGenericMethod(entityType); break; case "SqlSet": setMethod = SetInitializer.SqlSetNonGenericMethod; break; } // 取得实例化 //var dbContextInitializer = typeof(DbContext).GetField("_dbContextInitializer", BindingFlags.NonPublic | BindingFlags.Instance); //var newExpression = Expression.Call(Expression.MakeMemberAccess(dbContextParam, dbContextInitializer), setMethod, Expression.Constant(entityMap.Key)); var newExpression = Expression.Call(dbContextParam, setMethod, Expression.Constant(entityMap.Key)); // 赋值 var setExpression = Expression.Call(Expression.Convert(dbContextParam, Key), setter, newExpression); initDelegates.Add(Expression.Lambda <Action <DbContext> >(setExpression, dbContextParam).Compile()); } } // 实体化所有Set属性 Action <DbContext> initializer = context => { foreach (var initer in initDelegates) { initer(context); } }; var setInfo = new SetTypesInitializersPair(setTypeList, initializer); CacheList.Add(Key, setInfo); return(setInfo); } }