Exemplo n.º 1
0
        protected override System.IAsyncResult BeginExecute(AsyncCodeActivityContext context, System.AsyncCallback callback, object state)
        {
            string connString     = null;
            string provName       = null;
            string sql            = string.Empty;
            int    commandTimeout = OverTime.Get(context);

            if (commandTimeout < 0)
            {
                throw new ArgumentException("TimeoutMS");
            }
            Dictionary <string, Tuple <object, ArgumentDirection> > parameters = null;

            try
            {
                sql        = SQLString.Get(context);
                DBConn     = DBConnection.Get(context);
                connString = ConnectionString.Get(context);
                provName   = ProviderName.Get(context);
                if (Parameters != null)
                {
                    parameters = new Dictionary <string, Tuple <object, ArgumentDirection> >();
                    foreach (var param in Parameters)
                    {
                        parameters.Add(param.Key, new Tuple <object, ArgumentDirection>(param.Value.Get(context), param.Value.Direction));
                    }
                }
            }
            catch (Exception ex)
            {
                HandleException(ex, ContinueOnError.Get(context));
            }

            // create the action for doing the actual work
            Func <DBExecuteCommandResult> action = () =>
            {
                DBExecuteCommandResult executeResult = new DBExecuteCommandResult();
                if (DBConn == null)
                {
                    DBConn = new DatabaseConnection().Initialize(connString, provName);
                }
                if (DBConn == null)
                {
                    return(executeResult);
                }
                executeResult = new DBExecuteCommandResult(DBConn.Execute(sql, parameters, commandTimeout, CommandType), parameters);
                return(executeResult);
            };

            context.UserState = action;

            return(action.BeginInvoke(callback, state));
        }