/// <summary>
 /// 设置策略类型
 /// </summary>
 public static void SetPolicyType(this ISqlPolicyManager mgr, string policyName, Type type)
 {
     if (!typeof(ISqlConfigPolicy).IsAssignableFrom(type))
     {
         throw new ArgumentException($"The type [{type.Name}] must implement {nameof(ISqlConfigPolicy)}", nameof(type));
     }
     mgr.PolicyTypes[policyName] = type;
 }
        /// <summary>
        /// 设置全局策略对象
        /// </summary>
        public static void SetGlobalPolicy(this ISqlPolicyManager mgr, ISqlConfigPolicy policy)
        {
            policy.CheckNull(nameof(policy));
            var policyName = EFHelper.Services.EFCoreExUtility.GetSqlConfigPolicyName(policy.GetType());

            if (string.IsNullOrEmpty(policyName))
            {
                throw new ArgumentException($"Could not find {nameof(SqlConfigPolicyAttribute)} in {policy.GetType().Name} type");
            }
            mgr.GlobalPolicies[policyName] = policy;
        }
        /// <summary>
        /// 设置用于sql执行时的策略执行器(例如:查询缓存(一级/二级的),查询缓存清理(NonQuery的执行之后对二级缓存的清理)等等)
        /// </summary>
        public static void SetExecutePolicyExecutor <T>(this ISqlPolicyManager mgr,
                                                        Func <T> getExecutorFunc, int priority = 0)
            where T : ISqlExecutePolicyExecutor
        {
            var policyName = EFHelper.Services.EFCoreExUtility.GetSqlConfigPolicyName(typeof(T));

            if (string.IsNullOrEmpty(policyName))
            {
                throw new ArgumentException($"Could not find {nameof(SqlConfigPolicyAttribute)} in {typeof(T).Name} type");
            }
            mgr.SetExecutor(policyName, getExecutorFunc as Func <ISqlExecutePolicyExecutor>, priority);
        }
        /// <summary>
        /// 设置策略类型
        /// </summary>
        public static void SetPolicyType(this ISqlPolicyManager mgr, Type type)
        {
            if (!typeof(ISqlConfigPolicy).IsAssignableFrom(type))
            {
                throw new ArgumentException($"The type [{type.Name}] must implement {nameof(ISqlConfigPolicy)}", nameof(type));
            }
            var policyName = EFHelper.Services.EFCoreExUtility.GetSqlConfigPolicyName(type);

            if (string.IsNullOrEmpty(policyName))
            {
                throw new ArgumentException($"Could not find {nameof(SqlConfigPolicyAttribute)} in type [{type.Name}]", nameof(type));
            }
            mgr.PolicyTypes[policyName] = type;
        }
        /// <summary>
        /// 设置sql日志记录策略执行器
        /// </summary>
        /// <param name="mgr"></param>
        /// <param name="doLog">Action中的参数一:TableName;参数二:SqlName;参数三:Sql;参数四:SqlParameters</param>
        /// <param name="isAddLogGlobalPolicyObj">是否添加全局的策略对象</param>
        /// <param name="isAsync">是否异步记录</param>
        public static void SetSqlConfigExecuteLogPolicyExecutor(this ISqlPolicyManager mgr, Action <string, string,
                                                                                                    string, IReadOnlyList <IDataParameter> > doLog, bool isAddLogGlobalPolicyObj = true,
                                                                bool isAsync = true)
        {
            var logExc = new SqlConfigExecuteLogPolicyExecutor(doLog);

            mgr.SetExecutePolicyExecutor(() => logExc);
            if (isAddLogGlobalPolicyObj)
            {
                var policy = new SqlConfigExecuteLogPolicy()
                {
                    IsAsync = isAsync,
                };
                mgr.SetGlobalPolicy(policy);
            }
        }
        public SqlConfigManagerBase(ISqlConfigExecutorCreator sqlConfigExecutorCreator, IEFQueryCache efcache,
                                    ISqlParamConverter sqlParamConverter, ISqlPolicyManager policyExecutorMgr,
                                    IObjectReflector objReflec, IEFCoreExtendUtility util)
        {
            sqlConfigExecutorCreator.CheckNull(nameof(sqlConfigExecutorCreator));
            efcache.CheckNull(nameof(efcache));
            sqlParamConverter.CheckNull(nameof(sqlParamConverter));
            policyExecutorMgr.CheckNull(nameof(policyExecutorMgr));
            objReflec.CheckNull(nameof(objReflec));
            util.CheckNull(nameof(util));

            _sqlParamConverter        = sqlParamConverter;
            _efcache                  = efcache;
            _sqlConfigExecutorCreator = sqlConfigExecutorCreator;
            _policyMgr                = policyExecutorMgr;
            _objReflec                = objReflec;
            _util = util;

            _config = new SqlConfig(OnModified);
            _init   = new InitAction(DoInit);

            //添加默认的策略
            AddDefaultPolicies();
        }
 public SqlConfigPolicyData2ObjectExecutor(ISqlPolicyManager policyMgr)
 {
     policyMgr.CheckNull(nameof(policyMgr));
     _policyMgr = policyMgr;
 }
Exemple #8
0
 public SqlConfigManager(ISqlConfigExecutorCreator sqlConfigExecutorCreator, IEFQueryCache efcache,
                         ISqlParamConverter sqlParamConverter, ISqlPolicyManager policyExecutorMgr,
                         IObjectReflector objReflec, IEFCoreExtendUtility util)
     : base(sqlConfigExecutorCreator, efcache, sqlParamConverter, policyExecutorMgr, objReflec, util)
 {
 }
 /// <summary>
 /// 设置策略类型
 /// </summary>
 public static void SetPolicyType <T>(this ISqlPolicyManager mgr, string policyName)
     where T : ISqlConfigPolicy
 {
     mgr.SetPolicyType(policyName, typeof(T));
 }
 /// <summary>
 /// 设置策略类型
 /// </summary>
 public static void SetPolicyType <T>(this ISqlPolicyManager mgr)
     where T : ISqlConfigPolicy
 {
     mgr.SetPolicyType(typeof(T));
 }
 /// <summary>
 /// 设置全局策略对象
 /// </summary>
 /// <param name="mgr"></param>
 /// <param name="policyName"></param>
 /// <param name="policy"></param>
 public static void SetGlobalPolicy(this ISqlPolicyManager mgr, string policyName, ISqlConfigPolicy policy)
 {
     policy.CheckNull(nameof(policy));
     policyName.CheckStringIsNullOrEmpty(nameof(policyName));
     mgr.GlobalPolicies[policyName] = policy;
 }
 /// <summary>
 /// sql执行时的策略执行器的调用
 /// </summary>
 /// <param name="mgr"></param>
 /// <param name="policies"></param>
 /// <param name="info"></param>
 public static void InvokeExecutePolicyExecutors <T>(this ISqlPolicyManager mgr,
                                                     IDictionary <string, ISqlConfigPolicy> policies, T info)
     where T : IPolicyExecutorInfo, ISqlExecutePolicyExecutorInfo
 {
     mgr.InvokeExecutors(policies, info, typeof(ISqlExecutePolicyExecutorInfo));
 }
 /// <summary>
 /// 设置用于sql执行时的策略执行器(例如:查询缓存(一级/二级的),查询缓存清理(NonQuery的执行之后对二级缓存的清理)等等)
 /// </summary>
 public static void SetExecutePolicyExecutor(this ISqlPolicyManager mgr, string policyName,
                                             Func <ISqlExecutePolicyExecutor> getExecutorFunc, int priority = 0)
 {
     mgr.SetExecutor(policyName, getExecutorFunc, priority);
 }