Example #1
0
        internal static bool TryWriteX(Type tAccessor, DataSet db, DbCommand cmd, out int rslt, System.Linq.Expressions.Expression <Func <DataSet, DbCommand, int> > handlerExpr)
        {
            System.Linq.Expressions.MethodCallExpression methodCallExpr = (System.Linq.Expressions.MethodCallExpression)handlerExpr.Body;
            string handlerMethodName = methodCallExpr.Method.Name;

            HandlerExecDesc handler;

            if (!s_map_CommandText_Exec_Method.TryGetValue(cmd.CommandText, out handler))
            {
                // not registered
                IComparable handlerCommandText = GetCommandTextImpl(tAccessor, handlerMethodName);
                //string handlerCommandText = gct(handlerMethodName);// RepositoryDML_CommandText.RepositoryDML_GetCommandTextDML(handlerMethodName);

                string handlerCommandTextX = handlerCommandText as string;

                bool isOk;
                if (handlerCommandTextX == null)
                {
                    isOk = handlerCommandText.CompareTo(cmd) == 0;
                }
                else
                {
                    isOk = string.Equals(cmd.CommandText, handlerCommandTextX, StringComparison.Ordinal);
                }

                if (isOk)
                {
                    var parameter_db          = Expression.Parameter(typeof(DataSet), "db");
                    var parameter_cmd         = Expression.Parameter(typeof(DbCommand), "cmd");
                    MethodCallExpression call = Expression.Call(methodCallExpr.Method, parameter_db, parameter_cmd);                                              // methodCallExpr.Arguments
                    Expression <Func <DataSet, DbCommand, int> > lambda = Expression.Lambda <Func <DataSet, DbCommand, int> >(call, parameter_db, parameter_cmd); // visitor.ExtractedParameters

                    Func <DataSet, DbCommand, int> handlerMethod = lambda.Compile();
                    handler = new HandlerExecDesc(handlerMethodName, handlerMethod);
                    s_map_CommandText_Exec_Method.Add(cmd.CommandText, handler);
                }
                else
                {
                    handler = null;
                }
            }
            else
            {
                // registered
            }

            if (handler != null && handler.MethodName == handlerMethodName)
            {
                rslt = handler.HandlerMethod(db, cmd);
                return(true);
            }

            rslt = 0;
            return(false);
        }
Example #2
0
        internal static Func <DataSet, DbCommand, int> TryWrite(CommandExecutionHandler handlerRegistry, DbCommand cmd)
        {
            HandlerExecDesc handler;

            if (!s_map_CommandText_Exec_Method.TryGetValue(cmd.CommandText, out handler))
            {
                // not yet cached
                IComparable handlerCommandText = handlerRegistry.RetrieveCommandText();// GetCommandTextImpl(tAccessor, handlerMethodName);

                string handlerCommandTextX = handlerCommandText as string;

                bool isOk;
                if (handlerCommandTextX == null)
                {
                    isOk = handlerCommandText.CompareTo(cmd) == 0;
                }
                else
                {
                    isOk = string.Equals(cmd.CommandText, handlerCommandTextX, StringComparison.Ordinal);
                }


                if (isOk)
                {
                    Func <DataSet, DbCommand, int> handlerMethod = handlerRegistry.DoCompileExecMethod();
                    handler = new HandlerExecDesc(handlerRegistry.RetrieveHandlerMethodName(), handlerMethod);
                    s_map_CommandText_Exec_Method.Add(cmd.CommandText, handler);
                }
                else
                {
                    handler = null;
                }
            }
            else
            {
                // registered
            }

            if (handler != null && handler.MethodName == handlerRegistry.RetrieveHandlerMethodName())
            {
                return(handler.HandlerMethod);
            }


            return(null);
        }