protected virtual object Execute(TContext context) { if (context == null) { throw new ArgumentNullException("context"); } //创建事件参数对象 var executingArgs = new CommandExecutorExecutingEventArgs(context); //激发“Executing”事件 this.OnExecuting(executingArgs); if (executingArgs.Cancel) { return(executingArgs.Result); } //执行命令 this.OnExecute(context); //创建事件参数对象 var executedArgs = new CommandExecutorExecutedEventArgs(context); //激发“Executed”事件 this.OnExecuted(executedArgs); //返回最终的执行结果 return(context.Result); }
protected virtual void OnExecuted(CommandExecutorExecutedEventArgs args) { var executed = this.Executed; if (executed != null) { executed(this, args); } }
protected virtual void OnExecuted(CommandExecutorExecutedEventArgs args) { this.Executed?.Invoke(this, args); }
public object Execute(string commandText, object parameter = null) { if (string.IsNullOrWhiteSpace(commandText)) { throw new ArgumentNullException(nameof(commandText)); } CommandExecutorContext context = null; try { //创建命令执行器上下文对象 context = this.CreateExecutorContext(commandText, parameter); if (context == null) { throw new InvalidOperationException("Create executor context failed."); } } catch (Exception ex) { //激发“Error”事件 if (!this.OnFailed(context, ex)) { throw; } return(null); } //创建事件参数对象 var executingArgs = new CommandExecutorExecutingEventArgs(context); //激发“Executing”事件 this.OnExecuting(executingArgs); if (executingArgs.Cancel) { return(executingArgs.Result); } object result = null; try { //调用执行请求 result = this.OnExecute(context); } catch (Exception ex) { //激发“Error”事件 if (!this.OnFailed(context, ex)) { throw; } } //创建事件参数对象 var executedArgs = new CommandExecutorExecutedEventArgs(context, result); //激发“Executed”事件 this.OnExecuted(executedArgs); //返回最终的执行结果 return(executedArgs.Result); }
public object Execute(string commandText, object parameter = null) { if (string.IsNullOrWhiteSpace(commandText)) { throw new ArgumentNullException(nameof(commandText)); } CommandExecutorContext context = null; try { //创建命令执行器上下文对象 context = this.CreateExecutorContext(commandText, parameter); if (context == null) { throw new InvalidOperationException("Create executor context failed."); } } catch (Exception ex) { //激发“Error”事件 if (!this.OnFailed(context, ex)) { throw; } return(null); } //创建事件参数对象 var executingArgs = new CommandExecutorExecutingEventArgs(context); //激发“Executing”事件 this.OnExecuting(executingArgs); if (executingArgs.Cancel) { return(executingArgs.Result); } var complateInvoked = false; IEnumerable <CommandCompletionContext> completes = null; try { //调用执行请求 context.Result = this.OnExecute(context, out completes); } catch (Exception ex) { complateInvoked = true; //执行命令完成通知 this.OnCompletes(completes, ex); //激发“Error”事件 if (!this.OnFailed(context, ex)) { throw; } } //执行命令完成通知 if (!complateInvoked) { this.OnCompletes(completes, null); } //创建事件参数对象 var executedArgs = new CommandExecutorExecutedEventArgs(context); //激发“Executed”事件 this.OnExecuted(executedArgs); //返回最终的执行结果 return(executedArgs.Result); }
protected override void OnExecuted(CommandExecutorExecutedEventArgs args) { var commandNode = args.CommandNode; //更新当前命令节点,只有当前命令树节点不是叶子节点并且为空命令节点 if(commandNode != null && commandNode.Children.Count > 0 && commandNode.Command == null) this.Current = commandNode; base.OnExecuted(args); }
public object Execute(string commandText, object parameter = null) { if(string.IsNullOrWhiteSpace(commandText)) throw new ArgumentNullException(nameof(commandText)); //创建命令执行器上下文对象 var context = this.CreateExecutorContext(commandText, parameter); if(context == null) throw new InvalidOperationException("The context of this command executor is null."); //创建事件参数对象 var executingArgs = new CommandExecutorExecutingEventArgs(context); //激发“Executing”事件 this.OnExecuting(executingArgs); if(executingArgs.Cancel) return executingArgs.Result; object result = null; try { //调用执行请求 result = this.OnExecute(context); } catch(Exception ex) { //激发“Error”事件 if(!this.OnFailed(context, ex)) throw; } //创建事件参数对象 var executedArgs = new CommandExecutorExecutedEventArgs(context, result); //激发“Executed”事件 this.OnExecuted(executedArgs); //返回最终的执行结果 return executedArgs.Result; }