/// <summary> /// Adds the commands. /// </summary> /// <param name="name">The name.</param> /// <param name="commands">The commands.</param> private void AddCommands(String name, Command[] commands) { foreach (Command command in commands) { AddToView(name, command); } }
/// <summary> /// Initializes a new instance of the <see cref="CommandBuilder"/> class. /// </summary> /// <param name="rawCommand">The raw command.</param> /// <param name="command">The command.</param> /// <param name="ptypes">The ptypes.</param> public CommandBuilder(String rawCommand, Command command, Dictionary<String, PType> ptypes, Session session) { RawCommand = rawCommand; Command = command; PTypes = ptypes; Session = session; }
public void CreationOneLevelCommandTest() { var node = new CommandNode(); var command = new Command() {Name = "show"}; node.Add(command); Assert.IsTrue(node.Parent == null); Assert.IsNull(node.Command); Assert.IsTrue(node.Nodes.ContainsKey("show")); Assert.IsTrue(node.Nodes["show"].Command == command); // Assert.IsTrue(node.Nodes.First().Value.First().Command == "show"); }
public void CreationThreeLevelCommandTest2() { var node = new CommandNode(); var command1 = new Command { Name = "show config" }; var command2 = new Command { Name = "show" }; node.Add(command1); node.Add(command2); Assert.IsTrue(node.Parent == null); Assert.IsNull(node.Command); Assert.IsTrue(node.Nodes.ContainsKey("show")); Assert.IsTrue(node.Nodes["show"].Command == command2); Assert.IsTrue(node.Nodes["show"].Nodes.ContainsKey("config")); Assert.IsTrue(node.Nodes["show"].Nodes["config"].Command == command1); }
/// <summary> /// Adds to view. /// </summary> /// <param name="name">The name.</param> /// <param name="command">The command.</param> private void AddToView(String name, Command command) { if (!Views.ContainsKey(name)) { Views.Add(name, new CommandNode()); } Views[name].Add(command); }
/// <summary> /// Initializes a new instance of the <see cref="CommandNode"/> class. /// </summary> /// <param name="name">The name.</param> /// <param name="command">The command.</param> /// <param name="parent">The parent.</param> public CommandNode(string name, Command command, CommandNode parent) { Name = name; Command = command; Parent = parent; }
/// <summary> /// Creates the node. /// </summary> /// <param name="node">The node.</param> /// <param name="command">The command.</param> /// <param name="line">The line.</param> private void CreateNode(CommandNode node, Command command, String line) { string[] splitted = line.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); if (splitted.Length > 0) { String key = splitted[0]; Command reference = splitted.Length == 1 ? command : null; CommandNode created = new CommandNode(key, reference, node); if (!node.Nodes.ContainsKey(key)) { node.Nodes.Add(key, created); } if (splitted.Length != 1) // it'sn't last node { CreateNode(node.Nodes[key], command, line.Replace(key, String.Empty).Trim()); } else // this is last node { // We have to set command value, because this node can be create before we // had command. node.Nodes[key].Command = reference; } } }
/// <summary> /// Adds the specified command. /// </summary> /// <param name="command">The command.</param> /// <param name="line">The line.</param> public void Add(Command command, String line) { CreateNode(this, command, line); }
/// <summary> /// Adds the specified command. /// </summary> /// <param name="command">The command.</param> public void Add(Command command) { CreateNode(this, command, command.Name); }
public void SearchThreeLevelCommandTest2() { var node = new CommandNode(); var command1 = new Command { Name = "show config" }; var command2 = new Command { Name = "show" }; node.Add(command1); node.Add(command2); List<CommandNode> cn1 = node.Search("show"); Assert.IsNotNull(cn1); Assert.IsTrue(cn1.Count == 1); Assert.IsTrue(cn1.First().Name == "show"); Assert.IsNotNull(cn1.First().Command); List<CommandNode> cn2 = node.Search("test"); Assert.IsNotNull(cn2); Assert.IsTrue(cn2.Count == 0); List<CommandNode> cn3 = node.Search("sh"); Assert.IsNotNull(cn3); Assert.IsTrue(cn3.First().Name == "show"); Assert.IsNotNull(cn3.Count == 1); List<CommandNode> cn4 = node.Search("show c"); Assert.IsNotNull(cn4); Assert.IsTrue(cn4.First().Name == "config"); Assert.IsNotNull(cn3.Count == 1); }
public void SearchDeeperTest4() { var node = new CommandNode(); var command1 = new Command { Name = "show config" }; var command2 = new Command { Name = "show" }; var command3 = new Command { Name = "show test" }; node.Add(command1); node.Add(command2); node.Add(command3); string line = "show"; Assert.IsTrue(node.SearchDeeper(ref line).FullName == "show"); Assert.IsTrue(String.IsNullOrEmpty(line)); }
public void GetLinearNodesTest() { var node = new CommandNode(); var command1 = new Command { Name = "show config" }; var command2 = new Command { Name = "show" }; var command3 = new Command { Name = "show test" }; var command4 = new Command { Name = "linear" }; node.Add(command1); node.Add(command2); node.Add(command3); node.Add(command4); int count = 0; foreach (var n in node.LinearNodes) { count++; } Assert.IsTrue(count == 4); }
public void GetFullNameTest() { var node = new CommandNode(); var command1 = new Command { Name = "show config" }; var command2 = new Command { Name = "show" }; var command3 = new Command { Name = "show test" }; node.Add(command1); node.Add(command2); node.Add(command3); Assert.IsTrue(node.Nodes["show"].FullName == "show"); Assert.IsTrue(node.Nodes["show"].Nodes["config"].FullName == "show config"); Assert.IsTrue(node.Nodes["show"].Nodes["test"].FullName == "show test"); }