예제 #1
0
        /// <summary>
        /// 用于初始化的策略执行器,就是在程序运行期间只执行一次,除非sql的配置数据发生了改变(例如:替换表名 / 合并分部sql等的执行器)
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        protected void DoSqlInitPolicyExecutors(IDictionary <string, ISqlConfigPolicy> policies,
                                                IPolicyExecutorInfo info)
        {
            var pinfo = (ISqlInitPolicyExecutorInfo)info;
            ISqlConfigPolicy policy = null;

            if (policies?.Count > 0)
            {
                foreach (var pair in _sqlInitPolicyExecutorsOrder)
                {
                    info.PolicyName = pair.Key;
                    //全局的策略对象
                    _globalPolicies.TryGetValue(pair.Key, out policy);
                    info.GlobalPolicy = policy;

                    //获取通过方法形参传递过来的策略对象
                    policies.TryGetValue(pair.Key, out policy);
                    info.ParameterPolicy = policy;

                    pair.Value.Item2.Invoke().Execute(pinfo);
                }
            }
            else
            {
                info.ParameterPolicy = null;
                foreach (var pair in _sqlInitPolicyExecutorsOrder)
                {
                    info.PolicyName = pair.Key;
                    //全局的策略对象
                    _globalPolicies.TryGetValue(pair.Key, out policy);
                    info.GlobalPolicy = policy;
                    pair.Value.Item2.Invoke().Execute(pinfo);
                }
            }
        }
예제 #2
0
 /// <summary>
 /// 执行相关的策略执行器
 /// </summary>
 public void InvokeExecutors(IDictionary <string, ISqlConfigPolicy> policies,
                             IPolicyExecutorInfo info, Type executorInfoBaseType)
 {
     if (executorInfoBaseType == _tISqlInitPolicyExecutorInfo)
     {
         //在策略执行之前进行相应的初始化操作(优先级排序)
         _sqlInitPolicyExecutorsOrderInit.Invoke(-1);
         DoSqlInitPolicyExecutors(policies, info);
     }
     else if (executorInfoBaseType == _tISqlPreExecutePolicyExecutorInfo)
     {
         _sqlPreExecutePolicyExecutorsOrderInit.Invoke(-1);
         DoSqlPreExecutePolicyExecutors(policies, info);
     }
     else if (executorInfoBaseType == _tISqlExecutePolicyExecutorInfo)
     {
         _sqlExecutePolicyExecutorsOrderInit.Invoke(-1);
         DoSqlExecutePolicyExecutors(policies, info);
     }
     else
     {
         throw new ArgumentException($"Invalid type [{info.GetType().FullName}]", nameof(info));
     }
 }