/// <summary> /// 添加策略执行器 /// </summary> /// <typeparam name="T">类型要为:</typeparam> /// <param name="policyName">策略名称</param> /// <param name="getExecutorFunc">获取执行器对象的Func</param> /// <param name="priority">策略执行器的执行优先级(值越大越先执行)</param> public void SetExecutor <T>(string policyName, Func <T> getExecutorFunc, int priority = 0) { policyName.CheckStringIsNullOrEmpty(nameof(policyName)); getExecutorFunc.CheckNull(nameof(getExecutorFunc)); //if (getExecutorFunc is Func<ISqlInitPolicyExecutor>) //不使用is,因为类型T可能都继承了所有类型而造成都转换成功 if (typeof(T) == _tISqlInitPolicyExecutor) { _sqlInitPolicyExecutors[policyName] = Tuple.Create(priority, getExecutorFunc as Func <ISqlInitPolicyExecutor>); //执行器有改动,那么重新初始化 _sqlInitPolicyExecutorsOrderInit.Release(); } else if (typeof(T) == _tISqlPreExecutePolicyExecutor) { _sqlPreExecutePolicyExecutors[policyName] = Tuple.Create(priority, getExecutorFunc as Func <ISqlPreExecutePolicyExecutor>); //执行器有改动,那么重新初始化 _sqlPreExecutePolicyExecutorsOrderInit.Release(); } else if (typeof(T) == _tISqlExecutePolicyExecutor) { _sqlExecutePolicyExecutors[policyName] = Tuple.Create(priority, getExecutorFunc as Func <ISqlExecutePolicyExecutor>); //执行器有改动,那么重新初始化 _sqlExecutePolicyExecutorsOrderInit.Release(); } else { throw new ArgumentException($"Invalid type [{typeof(T).FullName}]", nameof(getExecutorFunc)); } }
/// <summary> /// 添加策略执行器 /// </summary> /// <typeparam name="T">类型要为:</typeparam> /// <param name="policyName">策略名称</param> /// <param name="getExecutorFunc">获取执行器对象的Func</param> /// <param name="priority">策略执行器的执行优先级(值越大越先执行)</param> public void SetExecutor <T>(string policyName, Func <T> getExecutorFunc, int priority = 0) { policyName.CheckStringIsNullOrEmpty(nameof(policyName)); getExecutorFunc.CheckNull(nameof(getExecutorFunc)); var executorType = typeof(T); if (executorType == _tILuaSqlInitPolicyExecutor) { _luasqlInitPolicyExecutors[policyName] = Tuple.Create(priority, getExecutorFunc as Func <ILuaSqlInitPolicyExecutor>); //执行器有改动,那么重新初始化 _luasqlInitPolicyExecutorsOrderInit.Release(); } else if (typeof(T) == _tILuaSqlPreExecutePolicyExecutor) { _luasqlPreExecutePolicyExecutors[policyName] = Tuple.Create(priority, getExecutorFunc as Func <ILuaSqlPreExecutePolicyExecutor>); //执行器有改动,那么重新初始化 _luasqlPreExecutePolicyExecutorsOrderInit.Release(); } else if (executorType == _tILuaSqlExecutePolicyExecutor) { _luasqlExecutePolicyExecutors[policyName] = Tuple.Create(priority, getExecutorFunc as Func <ILuaSqlExecutePolicyExecutor>); //执行器有改动,那么重新初始化 _luasqlExecutePolicyExecutorsOrderInit.Release(); } else { throw new ArgumentException($"Invalid type [{executorType.FullName}]", nameof(executorType)); } }
private void OnModified() { //配置有新的修改,那么重置初始化 _init.Release(); }