public void Insert(T node) { if (this.Node.CompareTo(node) > 0) { if (this.LeftTree == null) { this.LeftTree = new BinaryTree <T>(node); } else { this.LeftTree.Insert(node); } } else { if (this.RightTree == null) { this.RightTree = new BinaryTree <T>(node); } else { this.RightTree.Insert(node); } } NodeAdd?.Invoke(this, new BinaryTreeEventArgs <T>("Node add") { Data = node }); }
public void CanBuildExpressionTree() { var input = new List <Token>() { new Token { Type = TokenType.Number, Value = 5 }, new Token { Type = TokenType.Add, Value = null }, new Token { Type = TokenType.Number, Value = 7 }, }; var expectedOutput = new NodeAdd { Left = new NodeNumber { Value = 5 }, Right = new NodeNumber { Value = 7 } }; var root = ExpressionTreeBuilder.Build(input) as NodeAdd; Assert.NotNull(root); var left = root.Left as NodeNumber; Assert.NotNull(left); Assert.Equal(5, left.Value); var right = root.Right as NodeNumber; Assert.NotNull(right); Assert.Equal(7, right.Value); }
private void NodeAddMessageHandler(Server server, Client client, Session session, NodeAdd message) { Console.WriteLine(message.Name); if (session.Node == null || string.IsNullOrWhiteSpace(message.ParentSelector)) { session.Node = new Node(message.Type, message.Name); if (message.Properties != null) { foreach (var p in message.Properties) { session.Node.AddPropertyAsChild(p.Name, p.Data); } } return; } Node foundNode = session.Node.GetNode(message.ParentSelector); Node newNode = foundNode.AddChild(new Node(message.Type, message.Name)); if (message.Properties != null) { message.Properties.ForEach(p => { newNode.AddPropertyAsChild(p.Name, p.Data); }); } // Forward the update message to all clients. server.SendBroadcastWithExcept(message, client); }
public override void OnNodeEnable() { node = target as NodeAdd; }