public CommandExecutorFailureEventArgs(CommandExecutorContext context, Exception exception, bool handled) : base(exception, handled)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            _context = context;
        }
        public CommandExecutorEventArgs(CommandExecutorContext context, object result)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            _context = context;
            _result  = result;
        }
예제 #3
0
        protected virtual object OnExecute(CommandExecutorContext context)
        {
            var queue      = new Queue <Tuple <CommandExpression, CommandTreeNode> >();
            var expression = context.Expression;

            while (expression != null)
            {
                //查找指定路径的命令节点
                var node = this.Find(expression.FullPath);

                //如果指定的路径在命令树中是不存在的则抛出异常
                if (node == null)
                {
                    throw new CommandNotFoundException(expression.FullPath);
                }

                //将命令表达式的选项集绑定到当前命令上
                if (node.Command != null)
                {
                    expression.Options.Bind(node.Command);
                }

                //将找到的命令表达式和对应的节点加入队列中
                queue.Enqueue(new Tuple <CommandExpression, CommandTreeNode>(expression, node));

                //设置下一个待搜索的命令表达式
                expression = expression.Next;
            }

            //如果队列为空则返回空
            if (queue.Count < 1)
            {
                return(null);
            }

            //初始化第一个输入参数
            var parameter = context.Parameter;

            while (queue.Count > 0)
            {
                var entry = queue.Dequeue();

                //执行队列中的命令
                parameter = this.ExecuteCommand(context, entry.Item1, entry.Item2, parameter);
            }

            //返回最后一个命令的执行结果
            return(parameter);
        }
예제 #4
0
        protected bool OnFailed(CommandExecutorContext context, Exception ex)
        {
            var args = new CommandExecutorFailureEventArgs(context, ex);

            //激发“Failed”事件
            this.OnFailed(args);

            //输出异常信息
            if (!args.ExceptionHandled && args.Exception != null)
            {
                this.Error.WriteLine(args.Exception);
            }

            return(args.ExceptionHandled);
        }
예제 #5
0
        protected virtual object ExecuteCommand(CommandExecutorContext context, CommandExpression expression, CommandTreeNode node, object parameter)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            if (node.Command == null)
            {
                return(null);
            }

            return(node.Command.Execute(this.CreateCommandContext(expression, node, parameter)));
        }
예제 #6
0
 public CommandExecutorExecutedEventArgs(CommandExecutorContext context, object result) : base(context, result)
 {
 }
 public CommandExecutorExecutingEventArgs(CommandExecutorContext context, bool cancel = false) : base(context, null)
 {
     _cancel = cancel;
 }