protected override void OnExecute(TerminalCommandContext context) { if (context.Arguments.Length < 1) { foreach (var node in context.Executor.Root.Children) { this.DisplayCommandNode(context, node, 0); } return; } foreach (var argument in context.Arguments) { if (argument == "?") { CommandHelper.DisplayCommandInfo(context.Terminal, this); continue; } CommandTreeNode node = context.Executor.Find(argument); if (node == null) { context.Terminal.WriteLine(TerminalColor.Red, ResourceUtility.GetString("CommandNotFound", argument)); continue; } if (node != null && node.Command != null) { context.Terminal.WriteLine(node.FullPath); CommandHelper.DisplayCommandInfo(context.Terminal, node.Command); } } }
private CommandTreeNode CreateLocalTracesCommands(IAppMainView mainView) { var command = new CommandTreeNode { ImageIndex = 11, SelectedImageIndex = 11, Text = "Local Traces", ToolTipText = "In-Memory Traces", }; command.Nodes.Add(new CommandTreeNode { ImageIndex = 2, SelectedImageIndex = 2, Text = "View Memory Traces", ToolTipText = "View In-Memory Traces", Command = new ViewMemoryTracesCommand(mainView, this, memoryRepository) }); command.Nodes.Add(new CommandTreeNode { ImageIndex = 3, SelectedImageIndex = 3, Text = "Clear Memory Traces", ToolTipText = "Clear In-Memory Traces", Command = new ClearMemoryTracesCommand(mainView, memoryRepository) }); return(command); }
public void Should_recall_first_command_with_a_specific_command_when_pressing_Tab() { //Arrange var input = new[] { ConsoleKey.T, ConsoleKey.W, ConsoleKey.O, ConsoleKey.Tab, ConsoleKey.Enter }; var consoleManager = new FakeConsoleManager(new FakeKeyInputEngine(input)); var console = new TestConsole(consoleManager); var cancellationToken = new CancellationToken(); var inputInstance = new InputInstance(console, Constants.Prompt, null, cancellationToken); var selection = new CommandTreeNode <string>(new[] { new CommandTreeNode <string>("First", "One"), new CommandTreeNode <string>("Second", "Two", new [] { new CommandTreeNode <string>("FirstSub", "SubOne"), new CommandTreeNode <string>("SecondSub", "SubTwo"), new CommandTreeNode <string>("LastSub", "SubX"), }), new CommandTreeNode <string>("Last", "x") }); //Act var r = inputInstance.ReadLine(selection, true); //Assert var match = selection.Subs.ToArray()[1]; Assert.That(r, Is.EqualTo(match.Key)); Assert.That(consoleManager.LineOutput.First(), Is.EqualTo(Constants.Prompt + match.Value)); }
void TreeSelectCommandTreeNode(CommandTreeNode node, PackageBody body, Command command, PropertyInfo property) { argumentHelp.SetHelp("", "", "", false, null, null); panelCommandProperties.SuspendLayout(); panelCommandProperties.Controls.Clear(); if (property == null) { panelCommandProperties.SuspendLayout(); try { if (command == null) { FormsHelper.CreateNodeEditor(node, body, panelCommandProperties, _tree.Body, (propertyProgramName, propertyName, propertyDescription, allowTemplates, editor) => argumentHelp.SetHelp(propertyProgramName, propertyName, propertyDescription, allowTemplates, editor, _tree.Body.GetResultInfos())); } else { FormsHelper.CreateNodeEditor(node, command, panelCommandProperties, _tree.Body, (propertyProgramName, propertyName, propertyDescription, allowTemplates, editor) => argumentHelp.SetHelp(propertyProgramName, propertyName, propertyDescription, allowTemplates, editor, _tree.Body.GetResultInfos())); } } finally { panelCommandProperties.ResumeLayout(); } } ResizePropertiesPanelItems(); panelCommandProperties.ResumeLayout(); }
public void LoadTree(PackageBody body) { CommandTreeNode node = Root; _packageBody = body; FillTreeNode(node, body.Command, null); }
private bool InsertCommandIntoPropertyNode(TreeNodeData currentNodeData, PropertyInfo property, Command newCommand) { if (IsEmptyProperty(currentNodeData, property)) { return(ReplaceCommandIntoProperty(currentNodeData, newCommand)); } if (IsEnumerableProperty(currentNodeData, property)) { CommandTreeNode node = currentNodeData.Node; if (currentNodeData.Property == null || currentNodeData.Property != property) { IEnumerable <CommandTreeNode> childs = currentNodeData.Node.Childs; node = childs.Where(c => c.Data.Property == property).FirstOrDefault(); } AppendCommandAfter(node, newCommand, null); return(true); } else { AppendNodeType appendType = AskUserToDo(); switch (appendType) { case AppendNodeType.Append: CommandTreeNode sequenceTreeNode = IntermediateWithSequence(currentNodeData); AppendCommandAfter(sequenceTreeNode, newCommand, null); return(true); case AppendNodeType.Replace: return(ReplaceCommandIntoProperty(currentNodeData, newCommand)); } } return(false); }
protected void SelectCommandTreeNodeHandler(CommandTreeNode node, PackageBody body, Command command, PropertyInfo property) { if (SelectCommandTreeNode != null) { SelectCommandTreeNode(node, body, command, property); } }
private T Enter <T>(CommandTreeNode <T> selection) { var response = GetResponse(selection, _inputBuffer); RememberCommandHistory(_inputBuffer); return(response); }
public void Should_recall_first_sub_command_when_matching_a_sub_part_with_similar_root_name_pressing_Tab() { //Arrange var input = new[] { ConsoleKey.T, ConsoleKey.W, ConsoleKey.O, ConsoleKey.Spacebar, ConsoleKey.F, ConsoleKey.Tab, ConsoleKey.Enter }; var consoleManager = new FakeConsoleManager(new FakeKeyInputEngine(input)); var console = new TestConsole(consoleManager); var cancellationToken = new CancellationToken(); var inputInstance = new InputInstance(console, Constants.Prompt, null, cancellationToken); var match = new CommandTreeNode <string>("FirstSub", "SubOne"); var selection = new CommandTreeNode <string>(new[] { new CommandTreeNode <string>("First", "One"), new CommandTreeNode <string>("Second", "Two", new [] { match, new CommandTreeNode <string>("SecondSub", "SubTwo"), new CommandTreeNode <string>("LastSub", "SubX"), }), new CommandTreeNode <string>("SecondOther", "TwoOther"), new CommandTreeNode <string>("Last", "x") }); //Act var r = inputInstance.ReadLine(selection, true); //Assert Assert.That(r, Is.EqualTo(match.Key)); Assert.That(consoleManager.LineOutput.First(), Is.EqualTo(Constants.Prompt + "Two " + match.Value)); }
public void Should_recall_command_in_several_layers_when_navigating_with_Tab() { //Arrange var input = new[] { ConsoleKey.T, ConsoleKey.Tab, ConsoleKey.Spacebar, ConsoleKey.O, ConsoleKey.Tab, ConsoleKey.Spacebar, ConsoleKey.S, ConsoleKey.Tab, ConsoleKey.Enter }; var consoleManager = new FakeConsoleManager(new FakeKeyInputEngine(input)); var console = new TestConsole(consoleManager); var cancellationToken = new CancellationToken(); var inputInstance = new InputInstance(console, Constants.Prompt, null, cancellationToken); var match = new CommandTreeNode <string>("SecondSub", "S"); var selection = new CommandTreeNode <string>(new[] { new CommandTreeNode <string>("First", "One"), new CommandTreeNode <string>("Second", "Two", new [] { new CommandTreeNode <string>("FirstA", "One", new [] { new CommandTreeNode <string>("FirstSub", "ThirdOne"), match, new CommandTreeNode <string>("LastSub", "ThirdX"), }), new CommandTreeNode <string>("SecondSub", "SubTwo"), new CommandTreeNode <string>("LastSub", "SubX"), }), new CommandTreeNode <string>("Last", "x") }); //Act var r = inputInstance.ReadLine(selection, true); //Assert Assert.That(r, Is.EqualTo(match.Key)); Assert.That(consoleManager.LineOutput.First(), Is.EqualTo(Constants.Prompt + "Two One " + match.Value)); }
private CommandTreeNode CreateLocalProfilingCommands(IAppMainView mainView) { var command = new CommandTreeNode { ImageIndex = 6, SelectedImageIndex = 6, Text = "Profiling", ToolTipText = "Local Profiling", }; command.Nodes.Add(new CommandTreeNode { ImageIndex = 7, SelectedImageIndex = 7, Text = "Start Profiling", ToolTipText = "Start the Local Profiling Server", Command = new StartProfilingCommand(mainView, traceServerService) }); command.Nodes.Add(new CommandTreeNode { ImageIndex = 8, SelectedImageIndex = 8, Text = "Stop Profiling", ToolTipText = "Stop the Local Profiling Server", Command = new StopProfilingCommand(mainView, traceServerService) }); return(command); }
private CommandTreeNode CreateRemoteTracesCommands(IAppMainView mainView) { var command = new CommandTreeNode { ImageIndex = 10, SelectedImageIndex = 10, Text = "Remote Traces", ToolTipText = "Saved Traces (Database or FileSystem)", }; command.Nodes.Add(new CommandTreeNode { ImageIndex = 4, SelectedImageIndex = 4, Text = "View Database Traces", ToolTipText = "Remote Database Traces", Command = new ViewDatabaseTracesCommand(mainView, this) }); command.Nodes.Add(new CommandTreeNode { ImageIndex = 5, SelectedImageIndex = 5, Text = "View File Traces", ToolTipText = "FileSystem Traces", Command = new ViewFileTracesCommand(mainView, this) }); return(command); }
public static void CreateNodeEditor(CommandTreeNode node, object editedObject, Control container, PackageBody body, PropertyHelpCallback helpCallback) { container.Controls.Clear(); FlowLayoutPanel flowPanel; if (container is FlowLayoutPanel) { flowPanel = (FlowLayoutPanel)container; } else { flowPanel = new FlowLayoutPanel(); container.Controls.Add(flowPanel); flowPanel.FlowDirection = FlowDirection.TopDown; flowPanel.Dock = DockStyle.Fill; } Type type = editedObject.GetType(); var properties = type.GetProperties(); foreach (var currentProperty in properties) { GinArgumentAttribute argumentAttr = (GinArgumentAttribute)currentProperty.GetCustomAttributes(typeof(GinArgumentAttribute), false).FirstOrDefault(); bool isArgument = argumentAttr != null; if (isArgument) { object value = currentProperty.GetValue(editedObject, null); Control control = null; control = argumentAttr.GetEditor(value, currentProperty.Name, body, new PropertyChangedDelegate( (propertyName, propertyValue) => { PropertyInfo changedProperty = type.GetProperty(propertyName); if (changedProperty != null) { changedProperty.SetValue(editedObject, propertyValue, null); if (editedObject is Command) { string name = ((Command)editedObject).GetHumanReadableName(); if (name != node.NodeName) { node.NodeName = name; } } } }), new PropertyActivatedDelegate(propertyName => { if (helpCallback != null) { helpCallback(propertyName, argumentAttr.Name, argumentAttr.Description, argumentAttr.AllowTemplates, control as ITemplatedEditor); } })); if (control != null) { control.Tag = currentProperty; flowPanel.Controls.Add(control); } } } }
public void Rebuild() { CommandTreeNode _root = Root.Childs.FirstOrDefault(); if (_root != null) { _root.Rebuild(true); } }
private T GetResponse <T>(CommandTreeNode <T> selection, InputBuffer inputBuffer) { if (_finished) { throw new InvalidOperationException("Cannot get response more than once from a single input manager."); } T response; if (selection != null) { if (_selection != null) { _console.Output(new WriteEventArgs(null)); var v = _selection as CommandTreeNode <T>; response = v == null ? default(T) : v.Key; } else { var items = selection.Subs.Where(x => string.Equals(x.Value, inputBuffer.ToString(), StringComparison.CurrentCultureIgnoreCase)).ToArray(); if (!items.Any()) { try { response = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromInvariantString(inputBuffer.ToString()); _console.Output(new WriteEventArgs(null, OutputLevel.Default)); } catch (FormatException exception) { throw new EntryException("No item match the entry.", exception); } catch (Exception exception) { throw new EntryException("No item match the entry.", exception); } } else { if (items.Count() > 1) { throw new EntryException("There are several matches to the entry."); } _console.Output(new WriteEventArgs(null, OutputLevel.Default)); response = items.Single().Key; } } } else { response = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromInvariantString(inputBuffer.ToString()); _console.Output(new WriteEventArgs(null)); } _finished = true; return(response); }
internal static CommandTreeNode NodeWithChildren(CommandTreeNode node, params CommandTreeNode[] children) { foreach (var child in children) { node.NextNodes.Add(child.TokenPrototype, new CommandTreeNode.Reference(child, false)); } return(node); }
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); }
protected override void LoadItems() { using (new LoadingModeResource(this)) { foreach (ObjectListCommand command in _objectList.Commands) { CommandTreeNode newNode = new CommandTreeNode(command.Name, command); TreeList.TvList.Nodes.Add(newNode); } } LoadDefaultCommands(); }
public static IMessageTopic FindTopic(this CommandTreeNode node) { if (node == null) { return(null); } if (node.Command is QueueCommand queueCommand) { return(queueCommand.Topic); } return(FindTopic(node.Parent)); }
public static IMessageQueue FindQueue(this CommandTreeNode node) { if (node == null) { return(null); } if (node.Command is QueueCommand queueCommand) { return(queueCommand.Queue); } return(FindQueue(node.Parent)); }
public static MessageQueuePoller FindPoller(CommandTreeNode node) { if (node == null) { return(null); } if (node.Command is QueuePollerCommand pollerCommand) { return(pollerCommand.Poller); } return(FindPoller(node.Parent)); }
internal static RSA FindRSA(CommandTreeNode node) { if (node == null) { return(null); } if (node.Command is RSACommand command) { return(command.RSA ??= RSA.Create()); } return(FindRSA(node.Parent)); }
private static IQueue FindQueue(CommandTreeNode node, string name = null) { if (node == null) { return(null); } if (node.Command is QueueCommand queueCommand) { return(name == null ? queueCommand.Queue : queueCommand.QueueProvider.GetQueue(name)); } return(FindQueue(node.Parent, name)); }
internal static ISecretor FindSecretor(CommandTreeNode node) { if (node == null) { return(null); } if (node.Command is SecretCommand command) { return(command.Secretor); } return(FindSecretor(node.Parent)); }
protected override void LoadItemProperties() { using (new LoadingModeResource(this)) { if (CurrentNode != null) { CommandTreeNode currentCommandNode = (CommandTreeNode)CurrentNode; _txtText.Text = currentCommandNode.Text; } else { _txtText.Text = String.Empty; } } }
public override void Rebuild(bool recursive) { TreeNodeData data = (TreeNodeData)_node.Tag; if (IsCommand(data)) { ClearAllNestedCommands(data.Command); foreach (TreeNode nestedNode in _node.Nodes) { data = (TreeNodeData)nestedNode.Tag; if (IsProperty(data)) { if (IsEnumerableProperty(data, data.Property)) { IEnumerable <CommandTreeNode> nestedCommandNodes = data.Node.Childs; Type _listType = data.Property.PropertyType; object commands = _listType.GetConstructor(new Type[0]).Invoke(null); MethodInfo addMethod = _listType.GetMethod("Add"); foreach (var nestedCommandNode in nestedCommandNodes) { addMethod.Invoke(commands, new object[] { nestedCommandNode.Data.Command }); if (recursive) { nestedCommandNode.Rebuild(recursive); } } data.Property.SetValue(data.Command, commands, null); } else { if (data.Node.HasChilds) { CommandTreeNode nestedCommandNode = data.Node.Childs.FirstOrDefault(); Command nestedCommand = nestedCommandNode.Data.Command; data.Property.SetValue(data.Command, nestedCommand, null); if (recursive) { nestedCommandNode.Rebuild(recursive); } } } } } } }
public CommandTreeNode GetApplicationRootCommand(IAppMainView mainView) { var rootNode = new CommandTreeNode { ImageIndex = 0, SelectedImageIndex = 0, Text = "Dashboard", ToolTipText = "Dashboard" }; rootNode.Nodes.Add(CreateInstrumentationCommands(mainView)); rootNode.Nodes.Add(CreateLocalTracesCommands(mainView)); rootNode.Nodes.Add(CreateRemoteTracesCommands(mainView)); rootNode.Nodes.Add(CreateLocalProfilingCommands(mainView)); return(rootNode); }
internal static IListener GetListener(CommandTreeNode node) { if (node == null) { return(null); } var command = node.Command as ListenerCommand; if (command != null) { return(command.Server); } return(GetListener(node.Parent)); }
internal static Zongsoft.Services.IServiceProvider GetServiceProvider(CommandTreeNode node) { if (node == null) { return(null); } var command = node.Command as ServicesCommand; if (command != null) { return(command.ServiceProvider); } return(GetServiceProvider(node.Parent)); }
private IChannel GetActiveChannel(CommandTreeNode node) { if (node == null) { return(null); } var command = node.Command as ServerCommand; if (command != null) { return(command.Channel); } return(GetActiveChannel(node.Parent)); }
protected override void LoadItems() { using (new MobileComponentEditorPage.LoadingModeResource(this)) { foreach (ObjectListCommand command in this._objectList.get_Commands()) { CommandTreeNode node = new CommandTreeNode(command.get_Name(), command); base.TreeList.TvList.Nodes.Add(node); } } this.LoadDefaultCommands(); }
protected override void OnClickAddButton(object source, EventArgs e) { if (!base.IsLoading()) { CommandTreeNode node = new CommandTreeNode(this.GetNewName()); base.TreeList.TvList.Nodes.Add(node); base.TreeList.TvList.SelectedNode = node; base.CurrentNode = node; node.Dirty = true; node.BeginEdit(); this.LoadItemProperties(); this.LoadDefaultCommands(); this.SetDirty(); } }
protected override void OnClickAddButton(Object source, EventArgs e) { if (IsLoading()) { return; } CommandTreeNode newNode = new CommandTreeNode(GetNewName()); TreeList.TvList.Nodes.Add(newNode); TreeList.TvList.SelectedNode = newNode; CurrentNode = newNode; newNode.Dirty = true; newNode.BeginEdit(); LoadItemProperties(); LoadDefaultCommands(); SetDirty(); }