public CommandExecutor(ICommandExpressionParser parser = null) { _root = new CommandTreeNode(); _parser = parser ?? CommandExpressionParser.Instance; _output = NullCommandOutlet.Instance; _error = CommandErrorWriter.Instance; }
public CommandExecutorContext(ICommandExecutor executor, CommandLine commandLine, CommandTreeNode commandNode, object parameter) : base(executor, null, commandNode, parameter) { if(commandLine == null) throw new ArgumentNullException("commandLine"); _commandLine = commandLine; }
public CommandTreeNode(ICommand command, CommandTreeNode parent = null) : base(command.Name, parent) { if(command == null) throw new ArgumentNullException("command"); _command = command; _children = new CommandTreeNodeCollection(this); }
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); }
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); }
public CommandTreeNode(ICommand command, CommandTreeNode parent = null) : base(command.Name, parent) { if (command == null) { throw new ArgumentNullException("command"); } _command = command; _children = new CommandTreeNodeCollection(this); }
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; }
public void Load(CommandTreeNode node) { if(node == null || _isLoaded) return; lock(_syncRoot) { if(_isLoaded) return; _isLoaded = this.OnLoad(node); } }
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); } }
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; }
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; }
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; }
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); }
public void Load(CommandTreeNode node) { if (node == null || _isLoaded) { return; } lock (_syncRoot) { if (_isLoaded) { return; } _isLoaded = this.OnLoad(node); } }
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; }
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); }
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); }
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); } }
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); } }
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; }
public TerminalCommandContext(TerminalCommandExecutor executor, CommandLine commandLine, CommandTreeNode commandNode, object parameter, IDictionary<string, object> items = null) : base(executor, commandLine, commandNode, parameter, items) { }
public CommandTreeNode(string name, CommandTreeNode parent) : base(name, parent) { _children = new CommandTreeNodeCollection(this); }
public TerminalCommandContext(TerminalCommandExecutor executor, CommandExpression expression, CommandTreeNode commandNode, object parameter, IDictionary<string, object> extendedProperties = null) : base(executor, expression, commandNode, parameter, extendedProperties) { }
protected CommandExecutorBase() { _root = new CommandTreeNode(); }
/// <summary> /// 执行加载命令的实际操作。 /// </summary> /// <param name="node">待加载的命令树节点。</param> /// <returns>如果加载成功则返回真(true),否则返回假(false)。</returns> protected abstract bool OnLoad(CommandTreeNode node);
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); }
public CommandTreeNode(string name, CommandTreeNode parent = null) : base(name, parent) { _children = new CommandTreeNodeCollection(this); }
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)); }
public CommandExecutorContext(ICommandExecutor executor, CommandLine commandLine, CommandTreeNode commandNode, object parameter) : base(executor, null, commandNode, parameter) { if (commandLine == null) { throw new ArgumentNullException("commandLine"); } _commandLine = commandLine; }
protected virtual CommandContext CreateCommandContext(CommandExpression expression, CommandTreeNode node, object parameter) { return new CommandContext(this, expression, node, parameter); }
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))); }
protected virtual CommandContext CreateCommandContext(CommandExpression expression, CommandTreeNode node, object parameter) { return(new CommandContext(this, expression, node, parameter)); }
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; }
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)); }
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); }