/// <summary> /// Initializes a new instance of the <see cref="RelayCommand{T}"/> class. /// </summary> /// <param name="onExecute">Handler for execute command.</param> /// <param name="onCanExecute">Handler to validate whether execution is possible.</param> public RelayCommand( CommandExecuteHandler <T?> onExecute, CommandCanExecuteHandler <T?>?onCanExecute = null) { this.canExecuteHandler = onCanExecute; this.executeHandler = onExecute ?? throw new ArgumentNullException(nameof(onExecute)); }
/// <summary> /// Unsubscribe method handler from given command name /// </summary> /// <param name="command"></param> /// <param name="methodHandler"></param> public void Unsubscribe(string command, CommandExecuteHandler methodHandler) { if (!ContainsCommand(command)) { return; } this[command].Remove(methodHandler); }
/// <summary> /// Unsubscribe given method handler from all command executed subscribtions /// </summary> /// <param name="methodHandler"></param> public void UnsubscribeGlobal(CommandExecuteHandler methodHandler) { List <CommandExecuteHandler> items = this[ALL_COMMAND_NAME_PREFIX]; if (items != null) { items.Remove(methodHandler); } }
/// <summary> /// Subscribe given method handler to the given command name /// </summary> /// <param name="command"></param> /// <param name="methodHandler"></param> public void Subscribe(string command, CommandExecuteHandler methodHandler) { if (ContainsCommand(command)) { List <CommandExecuteHandler> list = this[command]; list.Add(methodHandler); } else { List <CommandExecuteHandler> list = new List <CommandExecuteHandler>(); list.Add(methodHandler); _Subscriptions.Add(command, list); } }
public MockExecutor(CommandExecuteHandler <TCommand> handler) { this._handler = handler; }
/// <summary> /// Subscribe given method handler to the given command name /// </summary> /// <param name="command"></param> /// <param name="methodHandler"></param> public void Subscribe(NetCommand command, CommandExecuteHandler methodHandler) { Subscribe(command.Name, methodHandler); }
/// <summary> /// Subscribe given method handler to all command executions /// </summary> /// <param name="methodHandler"></param> public void SubscribeGlobal(CommandExecuteHandler methodHandler) { Subscribe(ALL_COMMAND_NAME_PREFIX, methodHandler); }
/// <summary> /// 模拟指定命令模型的执行方法。 /// </summary> /// <typeparam name="TCommand">命令模型的数据类型。</typeparam> /// <param name="mockHandler">模拟的执行器。</param> /// <returns>当前执行器工厂。</returns> public MockExecutorFactory Mock <TCommand>(CommandExecuteHandler <TCommand> mockHandler) where TCommand : ICommand { Executors[typeof(TCommand)] = new ExecutorMetadata <TCommand>(new MockExecutor <TCommand>(mockHandler)); return(this); }
private T Execute <T>(CommandType commandType, string strSql, CommandExecuteHandler <T> commandExecuteHandler, object objParameters = null) { DbParameter[] dbParameters = objParameters == null ? null : GetDbParameters(objParameters); DbConnection conn = GetDbConnection(); DbCommand cmd = null; try { if (conn.State != ConnectionState.Open) { conn.Open(); } cmd = conn.CreateCommand(); cmd.CommandType = commandType; cmd.CommandText = strSql; if (_commandTimeout != (int)CommandTimeoutValue.None) { cmd.CommandTimeout = _commandTimeout; } if (Transactional) { cmd.Transaction = _dbTransaction; } if (dbParameters != null) { cmd.Parameters.AddRange(dbParameters); } DbAccessorContext context = new DbAccessorContext(this, cmd); if (PreCommandExecute != null) { PreCommandExecute.Invoke(context); } T result = commandExecuteHandler(cmd); if (AfterCommandExecute != null) { AfterCommandExecute.Invoke(context); } return(result); } finally { if (cmd != null) { cmd.Dispose(); } if (!Transactional && !(typeof(T) == typeof(DbDataReader))) { conn.Dispose(); } } }
public Command(CommandExecuteHandler callback) { handler = callback; }