コード例 #1
0
 public CommandExecutor(ICommandExpressionParser parser = null)
 {
     _root   = new CommandTreeNode();
     _parser = parser ?? CommandExpressionParser.Instance;
     _output = NullCommandOutlet.Instance;
     _error  = CommandErrorWriter.Instance;
 }
コード例 #2
0
		public CommandExecutorContext(ICommandExecutor executor, CommandLine commandLine, CommandTreeNode commandNode, object parameter) : base(executor, null, commandNode, parameter)
		{
			if(commandLine == null)
				throw new ArgumentNullException("commandLine");

			_commandLine = commandLine;
		}
コード例 #3
0
		public CommandExecutor(ICommandExpressionParser parser = null)
		{
			_root = new CommandTreeNode();
			_parser = parser ?? CommandExpressionParser.Instance;
			_output = NullCommandOutlet.Instance;
			_error = CommandErrorWriter.Instance;
		}
コード例 #4
0
		public CommandTreeNode(ICommand command, CommandTreeNode parent = null) : base(command.Name, parent)
		{
			if(command == null)
				throw new ArgumentNullException("command");

			_command = command;
			_children = new CommandTreeNodeCollection(this);
		}
コード例 #5
0
ファイル: CommandExecutor.cs プロジェクト: Zongsoft/Framework
 public CommandExecutor(ICommandExpressionParser parser = null)
 {
     _root   = new CommandTreeNode();
     _parser = parser ?? CommandExpressionParser.Instance;
     _output = NullCommandOutlet.Instance;
     _error  = CommandErrorWriter.Instance;
     _states = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
 }
コード例 #6
0
		public CommandContext(ICommandExecutor executor, CommandLine commandLine, CommandTreeNode commandNode, object parameter, IDictionary<string, object> items = null) : base(executor, commandNode, parameter, items)
		{
			_commandLine = commandLine;

			if(commandLine == null)
				_options = new CommandOptionCollection(this.Command);
			else
				_options = new CommandOptionCollection(this.Command, (System.Collections.IDictionary)commandLine.Options);
		}
コード例 #7
0
        public CommandTreeNode(ICommand command, CommandTreeNode parent = null) : base(command.Name, parent)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            _command  = command;
            _children = new CommandTreeNodeCollection(this);
        }
コード例 #8
0
		protected CommandExecutorContextBase(ICommandExecutor executor, string commandText, CommandTreeNode commandNode, object parameter)
		{
			if(executor == null)
				throw new ArgumentNullException("executor");

			_executor = executor;
			_commandText = commandText;
			_commandNode = commandNode;
			_command = commandNode == null ? null : commandNode.Command;
			_parameter = parameter;
		}
コード例 #9
0
		public void Load(CommandTreeNode node)
		{
			if(node == null || _isLoaded)
				return;

			lock(_syncRoot)
			{
				if(_isLoaded)
					return;

				_isLoaded = this.OnLoad(node);
			}
		}
コード例 #10
0
        public CommandContext(ICommandExecutor executor, CommandLine commandLine, CommandTreeNode commandNode, object parameter, IDictionary <string, object> items = null) : base(executor, commandNode, parameter, items)
        {
            _commandLine = commandLine;

            if (commandLine == null)
            {
                _options = new CommandOptionCollection(this.Command);
            }
            else
            {
                _options = new CommandOptionCollection(this.Command, (System.Collections.IDictionary)commandLine.Options);
            }
        }
コード例 #11
0
        protected CommandExecutorContextBase(ICommandExecutor executor, string commandText, CommandTreeNode commandNode, object parameter)
        {
            if (executor == null)
            {
                throw new ArgumentNullException("executor");
            }

            _executor    = executor;
            _commandText = commandText;
            _commandNode = commandNode;
            _command     = commandNode == null ? null : commandNode.Command;
            _parameter   = parameter;
        }
コード例 #12
0
		protected CommandContextBase(ICommandExecutor executor, CommandTreeNode commandNode, object parameter, IDictionary<string, object> extendedProperties = null)
		{
			if(commandNode == null)
				throw new ArgumentNullException("commandNode");

			if(commandNode.Command == null)
				throw new ArgumentException(string.Format("The Command property of '{0}' command-node is null.", commandNode.FullPath));

			_commandNode = commandNode;
			_command = commandNode.Command;
			_parameter = parameter;
			_extendedProperties = extendedProperties;
			_executor = executor;
		}
コード例 #13
0
        protected CommandContext(CommandContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            _session     = context._session;
            _expression  = context._expression;
            _command     = context._command;
            _commandNode = context._commandNode;
            _parameter   = context._parameter;
            _states      = context._states;
        }
コード例 #14
0
		public CommandContext(ICommandExecutor executor, CommandExpression expression, CommandTreeNode commandNode, object parameter, IDictionary<string, object> extendedProperties = null)
		{
			if(commandNode == null)
				throw new ArgumentNullException("commandNode");

			if(commandNode.Command == null)
				throw new ArgumentException(string.Format("The Command property of '{0}' command-node is null.", commandNode.FullPath));

			_executor = executor;
			_commandNode = commandNode;
			_command = commandNode.Command;
			_parameter = parameter;
			_expression = expression;

			if(extendedProperties != null && extendedProperties.Count > 0)
				_extendedProperties = new Dictionary<string, object>(extendedProperties, StringComparer.OrdinalIgnoreCase);
		}
コード例 #15
0
        public void Load(CommandTreeNode node)
        {
            if (node == null || _isLoaded)
            {
                return;
            }

            lock (_syncRoot)
            {
                if (_isLoaded)
                {
                    return;
                }

                _isLoaded = this.OnLoad(node);
            }
        }
コード例 #16
0
        protected CommandContextBase(ICommandExecutor executor, CommandTreeNode commandNode, object parameter, IDictionary <string, object> extendedProperties = null)
        {
            if (commandNode == null)
            {
                throw new ArgumentNullException("commandNode");
            }

            if (commandNode.Command == null)
            {
                throw new ArgumentException(string.Format("The Command property of '{0}' command-node is null.", commandNode.FullPath));
            }

            _commandNode        = commandNode;
            _command            = commandNode.Command;
            _parameter          = parameter;
            _extendedProperties = extendedProperties;
            _executor           = executor;
        }
コード例 #17
0
        private CommandTreeNode FindUp(CommandTreeNode current, Predicate <CommandTreeNode> predicate)
        {
            if (current == null || predicate == null)
            {
                return(null);
            }

            while (current != null)
            {
                if (predicate(current))
                {
                    return(current);
                }

                current = current.Parent;
            }

            return(null);
        }
コード例 #18
0
        private CommandTreeNode FindDown(CommandTreeNode current, Predicate <CommandTreeNode> predicate)
        {
            if (current == null || predicate == null)
            {
                return(null);
            }

            if (predicate(current))
            {
                return(current);
            }

            foreach (var child in current._children)
            {
                if (this.FindDown(child, predicate) != null)
                {
                    return(child);
                }
            }

            return(null);
        }
コード例 #19
0
        public CommandContext(CommandExecutorContext session, CommandExpression expression, CommandTreeNode commandNode, object parameter, IDictionary <string, object> extendedProperties = null)
        {
            if (commandNode == null)
            {
                throw new ArgumentNullException(nameof(commandNode));
            }

            if (commandNode.Command == null)
            {
                throw new ArgumentException($"The Command property of '{commandNode.FullPath}' command-node is null.");
            }

            _session     = session;
            _commandNode = commandNode;
            _command     = commandNode.Command;
            _parameter   = parameter;
            _expression  = expression;

            if (extendedProperties != null && extendedProperties.Count > 0)
            {
                _states = new Dictionary <string, object>(extendedProperties, StringComparer.OrdinalIgnoreCase);
            }
        }
コード例 #20
0
        public CommandContext(ICommandExecutor executor, CommandExpression expression, CommandTreeNode commandNode, object parameter, IDictionary <string, object> extendedProperties = null)
        {
            if (commandNode == null)
            {
                throw new ArgumentNullException("commandNode");
            }

            if (commandNode.Command == null)
            {
                throw new ArgumentException(string.Format("The Command property of '{0}' command-node is null.", commandNode.FullPath));
            }

            _executor    = executor;
            _commandNode = commandNode;
            _command     = commandNode.Command;
            _parameter   = parameter;
            _expression  = expression;

            if (extendedProperties != null && extendedProperties.Count > 0)
            {
                _extendedProperties = new Dictionary <string, object>(extendedProperties, StringComparer.OrdinalIgnoreCase);
            }
        }
コード例 #21
0
        protected override bool OnLoad(CommandTreeNode node)
        {
            node.Children.Add(new FtpAborCommand());
            node.Children.Add(new FtpAlloCommand());
            node.Children.Add(new FtpAppeCommand());
            node.Children.Add(new FtpCdupCommand());
            node.Children.Add(new FtpCwdCommand());
            node.Children.Add(new FtpDeleCommand());
            node.Children.Add(new FtpFeatCommand());
            node.Children.Add(new FtpHelpCommand());
            node.Children.Add(new FtpListCommand());
            node.Children.Add(new FtpMdtmCommand());
            node.Children.Add(new FtpMfmtCommand());
            node.Children.Add(new FtpMkdCommand());
            node.Children.Add(new FtpMlsdCommand());
            node.Children.Add(new FtpMlstCommand());
            node.Children.Add(new FtpNoopCommand());
            node.Children.Add(new FtpOptsCommand());
            node.Children.Add(new FtpPassCommand());
            node.Children.Add(new FtpPasvCommand());
            node.Children.Add(new FtpPortCommand());
            node.Children.Add(new FtpPwdCommand());
            node.Children.Add(new FtpQuitCommand());
            node.Children.Add(new FtpRestCommand());
            node.Children.Add(new FtpRetrCommand());
            node.Children.Add(new FtpRmdCommand());
            node.Children.Add(new FtpRnfrCommand());
            node.Children.Add(new FtpRntoCommand());
            node.Children.Add(new FtpSizeCommand());
            node.Children.Add(new FtpStorCommand());
            node.Children.Add(new FtpSystCommand());
            node.Children.Add(new FtpTypeCommand());
            node.Children.Add(new FtpUserCommand());

			//返回加载成功
			return true;
        }
コード例 #22
0
		public TerminalCommandContext(TerminalCommandExecutor executor, CommandLine commandLine, CommandTreeNode commandNode, object parameter, IDictionary<string, object> items = null) : base(executor, commandLine, commandNode, parameter, items)
		{
		}
コード例 #23
0
 public CommandTreeNode(string name, CommandTreeNode parent) : base(name, parent)
 {
     _children = new CommandTreeNodeCollection(this);
 }
コード例 #24
0
		public TerminalCommandContext(TerminalCommandExecutor executor, CommandExpression expression, CommandTreeNode commandNode, object parameter, IDictionary<string, object> extendedProperties = null) : base(executor, expression, commandNode, parameter, extendedProperties)
		{
		}
コード例 #25
0
 protected CommandExecutorBase()
 {
     _root = new CommandTreeNode();
 }
コード例 #26
0
		/// <summary>
		/// 执行加载命令的实际操作。
		/// </summary>
		/// <param name="node">待加载的命令树节点。</param>
		/// <returns>如果加载成功则返回真(true),否则返回假(false)。</returns>
		protected abstract bool OnLoad(CommandTreeNode node);
コード例 #27
0
			protected override CommandContext CreateCommandContext(CommandExpression expression, CommandTreeNode node, object parameter)
			{
				var args = parameter as ReceivedEventArgs;

				if(args == null)
					throw new InvalidOperationException("Invalid execution parameter.");

				return new FtpCommandContext(
						this,
						expression,
						node.Command,
						(FtpServerChannel)args.Channel,
						(FtpStatement)args.ReceivedObject);
			}
コード例 #28
0
		public CommandTreeNode(string name, CommandTreeNode parent = null) : base(name, parent)
		{
			_children = new CommandTreeNodeCollection(this);
		}
コード例 #29
0
ファイル: CommandExecutor.cs プロジェクト: Zongsoft/Framework
 protected virtual CommandContext CreateCommandContext(CommandExecutorContext session, CommandExpression expression, CommandTreeNode node, object parameter)
 {
     return(node == null || node.Command == null ? null : new CommandContext(session, expression, node, parameter));
 }
コード例 #30
0
        public CommandExecutorContext(ICommandExecutor executor, CommandLine commandLine, CommandTreeNode commandNode, object parameter) : base(executor, null, commandNode, parameter)
        {
            if (commandLine == null)
            {
                throw new ArgumentNullException("commandLine");
            }

            _commandLine = commandLine;
        }
コード例 #31
0
		protected virtual CommandContext CreateCommandContext(CommandExpression expression, CommandTreeNode node, object parameter)
		{
			return new CommandContext(this, expression, node, parameter);
		}
コード例 #32
0
 /// <summary>
 /// 执行加载命令的实际操作。
 /// </summary>
 /// <param name="node">待加载的命令树节点。</param>
 /// <returns>如果加载成功则返回真(true),否则返回假(false)。</returns>
 protected abstract bool OnLoad(CommandTreeNode node);
コード例 #33
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)));
        }
コード例 #34
0
 protected virtual CommandContext CreateCommandContext(CommandExpression expression, CommandTreeNode node, object parameter)
 {
     return(new CommandContext(this, expression, node, parameter));
 }
コード例 #35
0
		private CommandTreeNode FindDown(CommandTreeNode current, Predicate<CommandTreeNode> predicate)
		{
			if(current == null || predicate == null)
				return null;

			if(predicate(current))
				return current;

			foreach(var child in current._children)
			{
				if(this.FindDown(child, predicate) != null)
					return child;
			}

			return null;
		}
コード例 #36
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));
		}
コード例 #37
0
		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);
		}