//===================================================================//
        //                          Constructors                             //
        //===================================================================//
        /// <summary>
        /// Create a new SplitTree.
        /// </summary>
        /// <param name="maxValue">the maximum value of a node in the tree</param>
        /// <param name="minValue">the minimum value of a node in the tree</param>
        /// <param name="points">the grid points from which to construct the tree</param>
        public SplitTree(float maxValue, float minValue, List<GridPoint> points)
            : base(maxValue, minValue)
        {
            // reverse th points list
            points.Reverse();

            // create a list to store all the blobs in
            List<BlobOfNodes> blobList = new List<BlobOfNodes>();

            // Turn each point into a tree node.
            foreach (GridPoint point in points)
            {
                // Turn the next point into a node.
                TreeNode newNode = new TreeNode(point);

                // Make a list of all the blobs to which the node is adjacent.
                List<BlobOfNodes> adjacentBlobs = new List<BlobOfNodes>();
                // Check each blob in the list.
                foreach (BlobOfNodes blob in blobList) {
                    // If it is adjacent...
                    if (blob.IsAdjacentTo(newNode)) {
                        // ...add it to the list of adjacent blobs.
                        adjacentBlobs.Add(blob); } }

                // If the node is not adjacent to any blobs,
                // create a new blob for it.
                if (adjacentBlobs.Count == 0) {
                    BlobOfNodes newBlob = new BlobOfNodes(newNode);
                    blobList.Add(newBlob);
                    this.childless.Add(newNode); }

                // If the node is adjacent to exactly one blob,
                // add it to that blob.
                else if (adjacentBlobs.Count == 1) {
                    adjacentBlobs[0].GetMostRecentlyAddedNode().AddParent(newNode);
                    newNode.AddChild(adjacentBlobs[0].GetMostRecentlyAddedNode());
                    adjacentBlobs[0].Add(newNode); }

                // If the node is adjacent to more than one blob,
                // merge the blobs.
                else {
                    foreach (BlobOfNodes blob in adjacentBlobs) {
                        blob.GetMostRecentlyAddedNode().AddParent(newNode);
                        newNode.AddChild(blob.GetMostRecentlyAddedNode());
                        blobList.Remove(blob); }
                    this.merging.Add(newNode);
                    blobList.Add(new BlobOfNodes(newNode, adjacentBlobs)); }
            } // end of adding all the gridpoints

            // At this point, there will be exactly one blob. Its most recently
            // added node is the bottom of the split tree.
            this.parentless.Add(blobList[0].GetMostRecentlyAddedNode());
        }
Beispiel #2
0
 public static void Main()
 {
     TreeNode<int> node = new TreeNode<int>(2);
     TreeNode<int> node1 = new TreeNode<int>(4);
     node1.HasParent = true;
     node.AddChild(node1);
     Tree<int> tr = new Tree<int>(2);
 }
    void Start()
    {
        _mainView = this.GetComponent<UIPanel>().ui;

        _folderURL1 = UIPackage.GetItemURL("TreeView", "folder_closed");
        _folderURL2 = UIPackage.GetItemURL("TreeView", "folder_opened");
        _fileURL = UIPackage.GetItemURL("TreeView", "file");

        _treeView = new TreeView(_mainView.GetChild("tree").asList);
        _treeView.onClickNode.Add(__clickNode);
        _treeView.treeNodeRender = RenderTreeNode;

        TreeNode topNode = new TreeNode(true);
        topNode.data = "I'm a top node";
        _treeView.root.AddChild(topNode);
        for (int i = 0; i < 5; i++)
        {
            TreeNode node = new TreeNode(false);
            node.data = "Hello " + i;
            topNode.AddChild(node);
        }

        TreeNode aFolderNode = new TreeNode(true);
        aFolderNode.data = "A folder node";
        topNode.AddChild(aFolderNode);
        for (int i = 0; i < 5; i++)
        {
            TreeNode node = new TreeNode(false);
            node.data = "Good " + i;
            aFolderNode.AddChild(node);
        }

        for (int i = 0; i < 3; i++)
        {
            TreeNode node = new TreeNode(false);
            node.data = "World " + i;
            topNode.AddChild(node);
        }

        TreeNode anotherTopNode = new TreeNode(false);
        anotherTopNode.data = new string[] { "I'm a top node too", UIPackage.GetItemURL("TreeView", "heart") };
        _treeView.root.AddChild(anotherTopNode);
    }
        /// <summary>
        /// Creates <see cref="Common.UI.MenuItems.MenuSeparatorItem"/> instance that representing separator and adds it to
        /// <see cref="Common.TreeNode`1"/> instance.
        /// </summary>
        /// <param name="owner"><see cref="Common.TreeNode`1"/> instance.</param>
        public static TreeNode<CustomMenuItem> Create(TreeNode<CustomMenuItem> owner)
        {
            DebugEx.VerboseFormat("MenuSeparatorItem.Create(owner = {0})", owner);

            MenuSeparatorItem        item = new MenuSeparatorItem();
            TreeNode<CustomMenuItem> node = owner.AddChild(item);

            item.mNode = node;

            return node;
        }
        public static TreeNode<string> GetSet1()
        {
            TreeNode<string> root = new TreeNode<string>("root");
            {
                TreeNode<string> node0 = root.AddChild("node0");
                TreeNode<string> node1 = root.AddChild("node1");
                TreeNode<string> node2 = root.AddChild("node2");
                {
                    TreeNode<string> node20 = node2.AddChild(null);
                    TreeNode<string> node21 = node2.AddChild("node21");
                    {
                        TreeNode<string> node210 = node21.AddChild("node210");
                        TreeNode<string> node211 = node21.AddChild("node211");
                    }
                }
                TreeNode<string> node3 = root.AddChild("node3");
                {
                    TreeNode<string> node30 = node3.AddChild("node30");
                }
            }

            return root;
        }
        public static void BuildTree(TreeNode<Device> dev, IEnumerable<Device> list)
        {
            var devices = list as IList<Device> ?? list.ToList();

            var childrens =
                devices.Where(
                    d => d.Name.Level == dev.Value.Name.Level + 1
                         && d.Name.Path.Contains(dev.Value.Name.Path));

            foreach (var child in childrens)
            {
                BuildTree(dev.AddChild(child), devices);
            }
        }
        public void setUp()
        {
            admin        = new User(0, "admin", "123456", true, true);
            admin.State  = state.signedIn;
            basket_admin = admin.Basket;
            user         = new User(1, null, null, false, false);
            basket_user  = user.Basket;
            manager      = new User(2, "manager", "1234", false, true);

            store = new Store(-1, "store");

            Owner   storeOwner   = new Owner(store, admin);
            Manager storeManager = new Manager(store, manager, new List <int>());


            admin.Roles.Add(store.Id, storeOwner);
            manager.Roles.Add(store.Id, storeManager);


            store.Roles = new TreeNode <Role>(storeOwner);
            TreeNode <Role> ownerNode   = new TreeNode <Role>(storeOwner);
            TreeNode <Role> managerNode = ownerNode.AddChild(storeManager);

            store.RolesDictionary.Add(admin.Id, ownerNode);
            store.Roles.AddChild(storeManager);
            store.RolesDictionary.Add(manager.Id, managerNode);


            p1   = new Product(0, "first", null, "", 5000);
            p2   = new Product(1, "second", null, "", 5000);
            p3   = new Product(2, "third", null, "", 5000);
            p4   = new Product(3, "fourth", null, "", 5000);
            pis1 = new ProductInStore(10000000, store, p1);
            pis2 = new ProductInStore(10000000, store, p2);
            pis3 = new ProductInStore(10000000, store, p3);
            pis4 = new ProductInStore(10000000, store, p4);
            store.Products.Add(p1.Id, pis1);
            store.Products.Add(p2.Id, pis2);
            store.Products.Add(p3.Id, pis3);
            store.Products.Add(p4.Id, pis4);
            sys = new TradingSystem(null, null);
            sys.StoreCounter   = 1;
            sys.ProductCounter = 4;
            sys.UserCounter    = 2;
            sys.Stores.Add(store.Id, store);
            sys.Users.Add(admin.Id, admin);
            sys.Users.Add(user.Id, user);
            sys.Users.Add(manager.Id, manager);
        }
Beispiel #8
0
        public void TestThatTreeNode_CanBeEnumerated()
        {
            // Arrange
            var list = new List <string> {
                "ONE", "TWO", "THREE"
            };

            // Act
            var sut = new TreeNode <string>("-root-");

            sut.AddChild("ONE");
            sut.AddChild("TWO");
            sut.AddChild("THREE");

            // Assert
            var counter = 0;

            foreach (var node in sut.Children)
            {
                var expected = list[counter];
                Assert.Equal(expected, node.Data);
                counter++;
            }
        }
Beispiel #9
0
        public void AddChild_ShouldRaiseArgumentNullException_ForNullChildNodeArgument()
        {
            // Arrange.
            var childNode = (TestTreeNode)null;
            var target    = new TreeNode <Int32, TestTreeNode>();

            // Act.
            var action = new Action(() =>
            {
                target.AddChild(childNode);
            });

            // Assert.
            action.Should().Throw <ArgumentNullException>($"because {nameof(childNode)} is null");
        }
        static void AddChildren(IList <StakeholderContact> contacts, TreeNode <Stakeholder> node)
        {
            //var nodeAncestors = node.GetAncestors().ToArray();
            var children = contacts
                           .Where(c => c.RoleGiver == node.Value)
                           // avoid infinite recursion
                           //.Where(c => !nodeAncestors.Any(a => a.Value == c.Stakeholder || a.Value.Id == c.StakeholderId))
                           .ToList();

            foreach (var child in children)
            {
                var childNode = node.AddChild(child.RoleBearer);
                AddChildren(contacts, childNode);
            }
        }
Beispiel #11
0
        public static TreeNode <int> GetSet1()
        {
            TreeNode <int> root = new TreeNode <int>(100);

            {
                TreeNode <int> node0 = root.AddChild(0);
                TreeNode <int> node1 = root.AddChild(1);
                TreeNode <int> node2 = root.AddChild(2);
                {
                    TreeNode <int> node20 = node2.AddChild(20);
                    TreeNode <int> node21 = node2.AddChild(21);
                    {
                        TreeNode <int> node210 = node21.AddChild(210);
                        TreeNode <int> node211 = node21.AddChild(211);
                    }
                }
                TreeNode <int> node3 = root.AddChild(3);
                {
                    TreeNode <int> node30 = node3.AddChild(30);
                }
            }

            return(root);
        }
Beispiel #12
0
    private MySceneManager()
    {
        Debug.Log("MySceneManager AWAKE");
        _treeRoot = new TreeNode <string>("OP_00");
        // example
        TreeNode <string> child   = _treeRoot.AddChild("A0_ZhuYe");
        TreeNode <string> child01 = child.AddChild("301_ShiWai");
        TreeNode <string> child02 = child.AddChild("k6_1_ShiWai");
        TreeNode <string> child03 = child.AddChild("K5-JIA");
        TreeNode <string> child04 = child.AddChild("313-k7_ShiWai");

        child.AddChild("3D_ZhuChengXu");
        child.AddChild("ZongZhan_GongKuangChaKan");

        child.AddChild("大区域街景");

        TreeNode <string> child1 = child.AddChild("A6_GongKuangChaKan");
        TreeNode <string> child2 = child.AddChild("A2_场景巡游");
        TreeNode <string> child3 = child.AddChild("A2_SheBeiDingWEI");
        TreeNode <string> child4 = child.AddChild("A1_JiaoChengYanShi");
        TreeNode <string> child5 = child.AddChild("A4_RenWuBianJi");                                //   A5_MoNiYanLian_new
        TreeNode <string> child6 = child.AddChild("A3_RenYuanDingWei");

        child1.AddChild("301_GongKuangChaKan");
        child1.AddChild("301_ShiWai");

        child2.AddChild("301_GongKuangChaKan");
        child2.AddChild("301_ShiWai");

        TreeNode <string> child41  = child4.AddChild("教学演示列表页");
        TreeNode <string> child411 = child41.AddChild("培训教学");

        child5.AddChild("模拟演练-K6");

        _node = _treeRoot;
    }
Beispiel #13
0
        public void TestThatTreeNodeFind_ReturnsWhatYouSearchedFor()
        {
            // Arrange
            var test0 = new Test {
                Id = 0, Value = "Zero"
            };
            var test1 = new Test {
                Id = 1, Value = "One"
            };
            var test2 = new Test {
                Id = 2, Value = "Two"
            };

            // Act
            var node = new TreeNode <Test>(test0);

            node.AddChild(test1);
            node.AddChild(test2);

            // Assert
            var found = node.FindTreeNode(x => x.Data.Id == 2);

            Assert.Equal(test2.Id, found.Data.Id);
        }
Beispiel #14
0
    private void CreateTree(TreeNode <Transform> root)
    {
        var childCount = root.Data.childCount;

        if (childCount == 0)
        {
            return;
        }
        for (int i = 0; i < childCount; i++)
        {
            var ChildNode = new TreeNode <Transform>(root.Data.GetChild(i), root);
            root.AddChild(ChildNode.Data);
            CreateTree(root.FindInChildren(root.Data.GetChild(i)));
        }
    }
Beispiel #15
0
    private void TreePath(TreeNode <int> tn)
    {
        currentDepth++;
        if (currentDepth < depth)
        {
            for (int i = 0; i < maxChildren; i++)
            {
                currentNode++;

                var t = tn.AddChild(currentNode);
                TreePath(t);
                currentDepth--;
            }
        }
    }
Beispiel #16
0
        private static void DeserializeCommandsRecursively(TreeNode<Command> commandRoot, TreeNode<YamlObject> yamlCommandNode)
        {
            var command = YamlCommandIO.Deserialize(yamlCommandNode);
            if (command == null)
                return;

            var addedCommandNode = commandRoot.AddChild(command);

            foreach (var yamlChildCommand in yamlCommandNode)
            {
                // Don't call Deserialize for non-command properties. In Yaml tree Command properties don't have any value, just property name.
                if (yamlChildCommand.value.value == "" || yamlChildCommand.value.value == string.Empty)
                    DeserializeCommandsRecursively(addedCommandNode, yamlChildCommand);
            }
        }
Beispiel #17
0
        private void AddNode(TreeNode <CircleNode> parent, string question, DecisionTree.Model.Node child)
        {
            TreeNode <CircleNode> parentDraw = new TreeNode <CircleNode>(new CircleNode(question + ". " + child.ToString()));

            parent.AddChild(parentDraw);

            if (child is DecisionTree.Model.Decision)
            {
                DecisionTree.Model.Decision dChild = (DecisionTree.Model.Decision)child;
                for (int i = 0; i < dChild.Children.Length; i++)
                {
                    AddNode(parentDraw, dChild.Questions[i], dChild.Children[i]);
                }
            }
        }
        public static TreeNode <string> GetSet1()
        {
            TreeNode <string> root = new TreeNode <string>("root");

            {
                TreeNode <string> node0 = root.AddChild("node0");
                TreeNode <string> node1 = root.AddChild("node1");
                TreeNode <string> node2 = root.AddChild("node2");
                {
                    TreeNode <string> node20 = node2.AddChild(null);
                    TreeNode <string> node21 = node2.AddChild("node21");
                    {
                        TreeNode <string> node210 = node21.AddChild("node210");
                        TreeNode <string> node211 = node21.AddChild("node211");
                    }
                }
                TreeNode <string> node3 = root.AddChild("node3");
                {
                    TreeNode <string> node30 = node3.AddChild("node30");
                }
            }

            return(root);
        }
Beispiel #19
0
    // this is a classic BFS search algorithm, we expand the game tree
    // performing actions and we look for the goalState using as a goalTest
    // the function equalRelations.
    // desiredAccuracy => when are we satisfied by the value returning by the evaluation function
    // cutOff => after how many levels do we stop looking
    public static TreeNode <WorldState> breadthFirstSearch(WorldState initialState,
                                                           WorldState goalState, double desiredAccuracy = 1, double cutoff = Mathf.Infinity)
    {
        // TODO: remove this
        Utils.bfsExploredNodes = 0;

        TreeNode <WorldState> node = new TreeNode <WorldState>(initialState);
        double nodeAccuracy        = equalRelations(goalState, node.Data);

        if (nodeAccuracy == desiredAccuracy)
        {
            return(node);
        }

        Queue <TreeNode <WorldState> > frontier = new Queue <TreeNode <WorldState> >(node);
        HashSet <WorldState>           explored = new HashSet <WorldState>();

        while (node.Level < cutoff)
        {
            if (frontier.Count == 0)
            {
                return(null);
            }
            node = frontier.Dequeue();
            explored.Add(node.Data);
            foreach (Action a in node.Data.getPossibleActions())
            {
                TreeNode <WorldState> child = node.AddChild(node.Data.applyAction(a), new HashSet <Action>()
                {
                    a
                });
                if (explored.Contains(child.Data) == false && frontier.Contains(child) == false)
                {
                    // TODO: remove this
                    Utils.bfsExploredNodes++;

                    double childAccuracy = equalRelations(goalState, child.Data);
                    if (childAccuracy == desiredAccuracy)
                    {
                        return(child);
                    }
                    frontier.Enqueue(child);
                }
            }
        }

        return(null);
    }
Beispiel #20
0
        public void AddChildTestWithNodes()
        {
            var baseNode         = new TreeNode <string>("root");
            var intermediateNode = new TreeNode <string>("intermediate");
            var leafNode         = new TreeNode <string>("leaf");

            Assert.AreEqual(baseNode.AddChild(intermediateNode), true);
            Assert.AreEqual(intermediateNode.AddChild(leafNode), true);

            Assert.AreEqual(3, baseNode.Height);
            Assert.AreEqual(3, baseNode.Count);
            Assert.AreEqual(2, intermediateNode.Height);
            Assert.AreEqual(2, intermediateNode.Count);
            Assert.AreEqual(1, leafNode.Height);
            Assert.AreEqual(1, leafNode.Count);
        }
Beispiel #21
0
        private void AddNodeLib(TreeNode <CircleNode> parent, string child)
        {
            TreeNode <CircleNode> parentDraw = new TreeNode <CircleNode>(new CircleNode(child));

            parent.AddChild(parentDraw);

            if (!IsLeaf(child))
            {
                string parentName = string.Concat(Regex.Matches(child, "[A-Z]").OfType <Match>().Select(match => match.Value));

                foreach (string childChild in children[parentName])
                {
                    AddNodeLib(parentDraw, childChild);
                }
            }
        }
Beispiel #22
0
    //克隆
    public TreeNode Clone()
    {
        TreeNode cloneNode = new TreeNode(title, assetObject);

        cloneNode.SetSubTitle(subTitle, subTitleGuiStyle != null ? subTitleGuiStyle.normal.textColor : Color.green);
        cloneNode.SetParent(parent);
        for (int i = 0; i < children.Count; i++)
        {
            if (children[i] != null)
            {
                cloneNode.AddChild(children[i].Clone());
            }
        }

        return(cloneNode);
    }
Beispiel #23
0
        private void BuildPathsTree(Piece piece, IPathValidator <Key> validator, TreeNode <Key> currentPosition, int currentDepth)
        {
            if (!validator.IsValid(currentPosition, currentDepth))
            {
                return;
            }

            var moves = piece.GetPossibleMoves();

            foreach (var move in moves)
            {
                piece.MoveTo(move);
                var destinationChildTreeNode = currentPosition.AddChild(move.Item);
                BuildPathsTree(piece, validator, destinationChildTreeNode, currentDepth + 1);
            }
        }
Beispiel #24
0
        private TreeNode <ContentTreeNode> BuildTreeNode(TreeNode <ContentTreeNode> node)
        {
            if (node.Data.CurrentState == ContentTreeNode.State.Expanded)
            {
                foreach (var child in node.Data.WrappedElement.FindElements(By.XPath("./div/div")))
                {
                    node.AddChild(new ContentTreeNode(child));
                }

                for (var i = 0; i < node.Children.Count; i++)
                {
                    node.Children[i] = BuildTreeNode(node.Children[i]);
                }
            }

            return(node);
        }
        private void TraverseNode(int currentDepth, int maxDepth,
                                  TreeNode <LayerTreeNode> prevLayerTreeNode,
                                  TreeNode <MapTreeItem> mapTreeNode,
                                  bool isOnlyChild)
        {
            bool isLastLayer = currentDepth == maxDepth;

            TreeNode <LayerTreeNode> newNode;

            // If an only child then we avoid new nodes
            // as we would only add a redudant branch in that case
            // (ie. a branch containing only one branch).
            if (isLastLayer || !isOnlyChild)
            {
                LayerTreeNode newLayerNode = new LayerTreeNode();
                newLayerNode.mParent = prevLayerTreeNode.mItem;
                newNode = prevLayerTreeNode.AddChild(newLayerNode);
            }
            else
            {
                newNode = prevLayerTreeNode;
            }

            if (isLastLayer)
            {
                newNode.mItem.mObject = GameObject.Instantiate(MapTreeTwigPrefab);
                mapTreeNode.mItem.mChildLayerTreeNode = newNode.mItem;
            }
            else
            {
                if (!isOnlyChild)
                {
                    newNode.mItem.mObject = GameObject.Instantiate(MapTreeBranchPrefab);
                }

                int numChildren = mapTreeNode.GetNumChildren();
                for (int i = 0; i < numChildren; i++)
                {
                    TraverseNode(currentDepth + 1, maxDepth, newNode, mapTreeNode.GetChild(i), numChildren == 1);
                }
            }

            newNode.mItem.mObject.transform.SetParent(newNode.mItem.mParent.mObject.transform, false);

            return;
        }
Beispiel #26
0
        public void GetChildrenShouldReturnAddedNodesInOrder()
        {
            TreeNode parent = new TreeNode("parent");

            TreeNode[] expectedKids = new TreeNode[] { new TreeNode("1"), new TreeNode("2") };
            foreach (TreeNode child in expectedKids)
            {
                parent.AddChild(child);
            }
            IList <TreeNode> children = parent.GetChildren();

            Assert.Equal(expectedKids.Length, children.Count);
            for (int i = 0; i < expectedKids.Length; i++)
            {
                Assert.Equal(expectedKids[i], children[i]);
            }
        }
    void Start()
    {
        _mainView = this.GetComponent <UIPanel>().ui;

        _folderURL1 = UIPackage.GetItemURL("TreeView", "folder_closed");
        _folderURL2 = UIPackage.GetItemURL("TreeView", "folder_opened");
        _fileURL    = UIPackage.GetItemURL("TreeView", "file");

        _treeView = new TreeView(_mainView.GetChild("tree").asList);
        _treeView.onClickNode.Add(__clickNode);
        _treeView.treeNodeRender = RenderTreeNode;

        TreeNode topNode = new TreeNode(true);

        topNode.data = "I'm a top node";
        _treeView.root.AddChild(topNode);
        for (int i = 0; i < 5; i++)
        {
            TreeNode node = new TreeNode(false);
            node.data = "Hello " + i;
            topNode.AddChild(node);
        }

        TreeNode aFolderNode = new TreeNode(true);

        aFolderNode.data = "A folder node";
        topNode.AddChild(aFolderNode);
        for (int i = 0; i < 5; i++)
        {
            TreeNode node = new TreeNode(false);
            node.data = "Good " + i;
            aFolderNode.AddChild(node);
        }

        for (int i = 0; i < 3; i++)
        {
            TreeNode node = new TreeNode(false);
            node.data = "World " + i;
            topNode.AddChild(node);
        }

        TreeNode anotherTopNode = new TreeNode(false);

        anotherTopNode.data = new string[] { "I'm a top node too", UIPackage.GetItemURL("TreeView", "heart") };
        _treeView.root.AddChild(anotherTopNode);
    }
Beispiel #28
0
        public void RootTest()
        {
            var tree = new TreeNode <string>("F");

            tree
            .AddChild("B")
            .AddChild("A").Parent
            .AddChild("D")
            .AddChild("C").Parent
            .AddChild("E").Parent.Parent.Parent
            .AddChild("G")
            .AddChild("I")
            .AddChild("H");

            Assert.Equal(tree, TreeUtils.Root(tree, n => n.Parent));
            Assert.Equal(tree, TreeUtils.Root(tree.Children[0].Children[0], n => n.Parent));
        }
Beispiel #29
0
        static TreeNode <int> recursiveModTree(int value, TreeNode <int> node)
        {
            List <int> divisorList = Factor(value);

            if (divisorList.Count() > 2)
            {
                foreach (int divisor in divisorList)
                {
                    if (value != divisor)
                    {
                        recursiveModTree(divisor, node.AddChild(divisor));
                    }
                }
                return(node);
            }
            return(node);
        }
Beispiel #30
0
    private TreeNode AddNode(TreeNode parent, ref int currentIndex)
    {
        int      children     = tokens[currentIndex++];
        int      metadaTokens = tokens[currentIndex++];
        TreeNode node         = new TreeNode();

        for (int i = 0; i < children; i++)
        {
            var childNode = AddNode(node, ref currentIndex);
            node.AddChild(childNode);
        }
        for (int i = 0; i < metadaTokens; i++)
        {
            node.Metadata.Add(tokens[currentIndex++]);
        }
        return(node);
    }
Beispiel #31
0
        public void AddChildrenMidexTest()
        {
            var baseNode          = new TreeNode <string>("root");
            var intermediateNode  = new TreeNode <string>("intermediate");
            var intermediateNode2 = new TreeNode <string>("intermediate2");

            baseNode.AddChild("leaf");
            baseNode.AddChild(intermediateNode);
            intermediateNode.AddChild(intermediateNode2);
            intermediateNode2.AddChild("leaf2");

            Assert.AreEqual(4, baseNode.Height);
            Assert.AreEqual(5, baseNode.Count);
            Assert.AreEqual(3, intermediateNode.Height);
            Assert.AreEqual(3, intermediateNode.Count);
            Assert.AreEqual(2, intermediateNode2.Height);
            Assert.AreEqual(2, intermediateNode2.Count);
        }
Beispiel #32
0
    // Use this for initialization
    void Start()
    {
        TreeNode <string> root  = new TreeNode <string>("root");
        TreeNode <string> node0 = root.AddChild("node0");
        TreeNode <string> node1 = root.AddChild("node1");
        TreeNode <string> node2 = root.AddChild("node2");

        TreeNode <string> node21 = node2.AddChild("node21");

        node21.IsRoot;

        foreach (TreeNode <string> node in root)
        {
            string indent = CreateIndent(node.Level);
            output += indent + (node.Data + "\n" ?? "null\n");
        }
        Debug.Log(output);
    }
Beispiel #33
0
        private void ExistNode(TreeNode treeNode, T data, TreeNode nodeParent)
        {
            if (treeNode.parent == root)
            {
                treeNode.parent = nodeParent;
                nodeParent.AddChild(treeNode);

                if (treeNode.childrens != null)
                {
                    foreach (var n in treeNode.childrens)
                    {
                        n.level = treeNode.level + 1;
                    }
                }

                root.DeleteChild(data);
            }
        }
Beispiel #34
0
    private void ContinueMulticapturingMove(TreeNode <Move> treeNode, int depth, int alpha, int beta)
    {
        GameObject pawn           = GetPawnFromTreeNode(treeNode);
        var        capturingMoves = GetPawnCapturingMoves(pawn);
        TileIndex  pawnTileIndex  = pawn.GetComponent <IPawnProperties>().GetTileIndex();

        foreach (var moveIndex in capturingMoves)
        {
            var move         = new Move(pawnTileIndex, moveIndex);
            var moveTreeNode = treeNode.AddChild(move);
            AddMovesToTreeNode(moveTreeNode, depth - 1, alpha, beta);
            SetAlphaAndBeta(IsMoveByMaximizingPlayer(treeNode), moveTreeNode.Value.Score, ref alpha, ref beta);
            if (beta <= alpha)
            {
                return;
            }
        }
    }
Beispiel #35
0
        private static TreeNode InsertParent(
            TreeNode parent,
            NamedNode actualParent,
            string name = null,
            Func <ProxyNode, bool> existingNodeFinder = null)
        {
            name ??= actualParent.Name;

            ProxyNode folderProxy = null;

            if (existingNodeFinder != null)
            {
                foreach (var existingChild in parent.Children.OfType <ProxyNode>())
                {
                    if (existingNodeFinder(existingChild))
                    {
                        folderProxy = existingChild;
                        break;
                    }
                }

                if (folderProxy == null)
                {
                    folderProxy = new ProxyNode {
                        Name = name
                    };
                    parent.AddChild(folderProxy);
                }
            }

            if (folderProxy == null)
            {
                folderProxy = parent.GetOrCreateNodeWithName <ProxyNode>(name);
            }

            folderProxy.Original = actualParent;
            if (folderProxy.Highlights.Count == 0)
            {
                folderProxy.Highlights.Add(name);
            }

            folderProxy.IsExpanded = true;
            return(folderProxy);
        }
Beispiel #36
0
        public bool AddParent(T child, T parent)
        {
            var      tempNode   = FindNode(child);
            TreeNode nodeParent = FindNode(parent);

            if (nodeParent == null)
            {
                return(false);
            }
            if (tempNode != null)
            {
                ExistNode(tempNode, child, nodeParent);
                return(true);
            }
            TreeNode nodeLeaf = new TreeNode(child, nodeParent);

            nodeParent.AddChild(nodeLeaf);
            return(true);
        }
        public void MakeTree(string namafile, TreeNode<string> T)
        {
        //membentuk pohon status dari file dan direktori dari direktori tertentu
            if (Directory.Exists(namafile))
            {
                string[] listdirektori = {};
                try{
                    listdirektori = Directory.GetDirectories(namafile);
                } catch (Exception e){

                }
                if (listdirektori.Length > 0)
                {
                    foreach (var directori in listdirektori)
                    {
                        string dirr = directori;
                        TreeNode<string> nodee = T.AddChild(dirr,"folder");
                        countTotal++;
                        MakeTree(dirr, nodee);

                    }
                }
                string[] listfile={};
                try
                {
                    listfile = Directory.GetFiles(namafile);
                }
                catch (Exception e)
                {

                }
                if (listfile.Length > 0)
                {
                    foreach (var directori in listfile)
                    {
                        countTotal++;
                        string filee = directori;
                        TreeNode<string> nodef = T.AddChild(filee,"file");

                    }
                }
            }
        }
  } //Main()

  public static void FillTree(TreeNode InputNode) 
  {
    //Fill the tree with all the types in the BCL assembly in inheritence hierarchy.
    Type [] types = typeof(object).Module.Assembly.GetExportedTypes();
    InputNode.AddChild(new TreeNode(typeof(object).FullName));

    //Go through the types and for each base type add any new derived types.
    //Since Find returns a reference to a node within InputNode, the original
    //node is modified when n is modified.
    //AddChild checks for existence and only adds if new.
    foreach (Type t in types) 
    {
      if (t.BaseType != null && t.BaseType.FullName != null)
      {
        TreeNode n = InputNode.Find(t.BaseType.FullName);
        if (n != null) 
        {
          n.AddChild(new TreeNode(t));
        } //if
      } //if
    } //foreach

  } //FillTree()
        public async Task<TreeNode<NavigationNode>> FromXml(
            XDocument xml,
            NavigationTreeBuilderService service
            )
        { 
            if(xml.Root.Name != "NavNode") { throw new ArgumentException("Expected NavNode"); }

            TreeNode<NavigationNode> treeRoot;
            var builderName = GetNodeBuilderName(xml.Root);
            if (string.IsNullOrEmpty(builderName))
            {
                NavigationNode rootNav = BuildNavNode(xml.Root, service);
                treeRoot = new TreeNode<NavigationNode>(rootNav);
               
            }
            else
            {
                var otherBuilderRoot = await service.GetTree(builderName).ConfigureAwait(false);
                if(otherBuilderRoot.Value.ChildContainerOnly)
                {
                    NavigationNode rootNav = BuildNavNode(xml.Root, service);
                    treeRoot = new TreeNode<NavigationNode>(rootNav);
                    foreach(var firstChild in otherBuilderRoot.Children)
                    {
                        treeRoot.AddChild(firstChild);
                    }

                }
                else
                {
                    treeRoot = otherBuilderRoot;
                }
            }

            var childrenNode = xml.Root.Elements(XName.Get("Children"));
            if (childrenNode != null)
            {
                foreach (XElement childNode in childrenNode.Elements(XName.Get("NavNode")))
                {
                    var childBuilder = GetNodeBuilderName(childNode);
                    if (string.IsNullOrEmpty(childBuilder))
                    {
                        await AddChildNode(treeRoot, childNode, service).ConfigureAwait(false);
                    }
                    else
                    {
                        var child = await service.GetTree(childBuilder).ConfigureAwait(false);
                        if (child.Value.ChildContainerOnly)
                        {
                            foreach (var subChild in child.Children)
                            {
                                treeRoot.AddChild(subChild);
                            }
                        }
                        else
                        {
                            treeRoot.AddChild(child);
                        }

                    }
                }
            }



            //foreach (XElement childrenNode in xml.Root.Elements(XName.Get("Children")))
            //{
            //    foreach (XElement childNode in childrenNode.Elements(XName.Get("NavNode")))
            //    {
            //        var childBuilder = GetNodeBuilderName(childNode);
            //        if(string.IsNullOrEmpty(childBuilder))
            //        {
            //            await AddChildNode(treeRoot, childNode, service).ConfigureAwait(false);
            //        }
            //        else
            //        {
            //            var child = await service.GetTree(childBuilder).ConfigureAwait(false);
            //            if(child.Value.ChildContainerOnly)
            //            {
            //                foreach(var subChild in child.Children)
            //                {
            //                    treeRoot.AddChild(subChild);
            //                }
            //            }
            //            else
            //            {
            //                treeRoot.AddChild(child);
            //            }

            //        }


            //    }

            //}

            return treeRoot;
        }
        private TreeNode<ProductFilterGroupNode> BuildTreeNode(IEnumerable<IProductFilterGroup> groups, IEnumerable<Tuple<IEnumerable<Guid>, int>> tuples, params Guid[] collectionKeys)
        {
            var root = new TreeNode<ProductFilterGroupNode>(new ProductFilterGroupNode { Keys = collectionKeys, Item = null });
            foreach (var g in groups)
            {
                root.AddChild(CreateNodeData(g, tuples, collectionKeys));
            }

            return root;
        }
Beispiel #41
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Common.UI.MenuItems.MenuItem"/> class with given token ID and with
        /// assigning to specified <see cref="Common.TreeNode`1"/> instance.
        /// </summary>
        /// <param name="owner"><see cref="Common.TreeNode`1"/> instance.</param>
        /// <param name="tokenId">Token ID for translation.</param>
        /// <param name="onClick">Click event handler.</param>
        /// <param name="enabled">Is this menu item enabled or not.</param>
        /// <param name="shortcutHandler">Shortcut handler.</param>
        /// <param name="shortcut">Shortcut.</param>
        /// <param name="radioGroup">Menu radio group.</param>
        public static TreeNode<CustomMenuItem> Create(
													    TreeNode<CustomMenuItem>     owner
													  , R.sections.MenuItems.strings tokenId
													  , UnityAction                  onClick         = null
													  , bool                         enabled         = true
												      , IShortcutHandler             shortcutHandler = null
													  , string                       shortcut        = null
													  , MenuRadioGroup               radioGroup      = null
													 )
        {
            MenuItem item = new MenuItem(
                                           tokenId                            // Token ID
                                         , null                               // Token arguments
                                         , null                               // Text
                                         , enabled                            // Enabled
                                         , onClick                            // Click event handler
                                         , shortcutHandler    			      // Shortcut handler
                                     	 , KeyboardInput.FromString(shortcut) // Shortcut
                                 		 , radioGroup                         // Menu radio group
                                        );

            TreeNode<CustomMenuItem> node = owner.AddChild(item);

            item.mNode = node;

            return node;
        }
        void IterateProjectTree(PBXGroupBase parentGroup, TreeNode<Tuple<string, IPBXElement>> parentNode)
        {
            if (parentGroup.Children.Count == 0)
                return;

            foreach (var childElementId in parentGroup.Children) {
                var childElement = GetElementById (childElementId);
                var childNode = parentNode.AddChild (new Tuple<string, IPBXElement> (childElementId, childElement));

                if (childElement.GetType ().BaseType == typeof(PBXGroupBase))
                    IterateProjectTree ((PBXGroupBase)childElement, childNode);
            }
        }
        private void loadChildren(TreeNode<SitemapItem> root)
        {
            List<SitemapItem> items =
                _articleDbContext.SitemapItems.Where(i => i.ParentCode == root.Data.Code)
                    .OrderBy(i => i.SortOrder)
                    .ThenBy(i => i.Code).ToList();

            foreach (SitemapItem sitemapItem in items)
            {
                var child = new SitemapItem(sitemapItem);

                loadChildren(root.AddChild(child));
            }
        }
Beispiel #44
0
        //===================================================================//
        //                             Actions                               //
        //===================================================================//
        /// <summary>
        /// Clones all of the nodes in the tree and duplicates their connections.
        /// </summary>
        /// <param name="parentlessParam">the list in which to store the parentless nodes of the new tree</param>
        /// <param name="mergingParam">the list in which to store the merging nodes of the new tree</param>
        /// <param name="childlessParam">the list in which to store the childless nodes of the new tree</param>
        private void Clone(List<TreeNode> parentlessParam, List<TreeNode> mergingParam, List<TreeNode> childlessParam)
        {
            // Copy the tree root and place it in the new tree's list.
            TreeNode newTreeRoot = new TreeNode(this.GetChildless()[0]);
            childlessParam.Add(newTreeRoot);

            // Create the current "level" of nodes in the original tree.
            List<TreeNode> currentLevel = new List<TreeNode>();
            currentLevel.Add(this.GetChildless()[0]);
            // Create the current "level" of nodes in the clone tree.
            List<TreeNode> currentCloneLevel = new List<TreeNode>();
            currentCloneLevel.Add(newTreeRoot);

            // Loop through the levels of the original tree.
            while (currentLevel.Count > 0) {

                // Construct the next level of the original and clone trees.
                List<TreeNode> nextLevel = new List<TreeNode>();
                List<TreeNode> nextCloneLevel = new List<TreeNode>();

                // Put all of the children of the nodes in the current level of
                // the original tree into the next level.
                for (int id = 0; id < currentLevel.Count; id++) {
                    foreach (TreeNode parent in currentLevel[id].GetParents()) {
                        // Copy each parent and set its relations.
                        TreeNode newNode = new TreeNode(parent);
                        newNode.AddChild(currentCloneLevel[id]);
                        currentCloneLevel[id].AddParent(newNode);

                        nextLevel.Add(parent);
                        nextCloneLevel.Add(newNode);

                        if (this.merging.Contains(parent)) {
                            mergingParam.Add(newNode); }
                        if (this.parentless.Contains(parent)) {
                            parentlessParam.Add(newNode); }
                    }
                }
                currentLevel = nextLevel;
                currentCloneLevel = nextCloneLevel;
            }
        }
#pragma warning restore 1998

        private TreeNode<NavigationNode> BuildTree()
        {
            
            NavigationNode home = new NavigationNode();
            home.Key = "Home";
            home.ParentKey = "RootNode";
            home.Controller = "Home";
            home.Action = "Index";
            home.Text = "Home";
            home.Url = home.ResolveUrl();
            home.IsRootNode = true;
            TreeNode<NavigationNode> treeRoot = new TreeNode<NavigationNode>(home);

            NavigationNode about = new NavigationNode();
            about.Key = "About";
            about.ParentKey = "RootNode";
            about.Controller = "Home";
            about.Action = "About";
            about.Text = "About";
            about.Url = about.ResolveUrl();
            treeRoot.AddChild(about);

            NavigationNode contact = new NavigationNode();
            contact.Key = "Contact";
            contact.ParentKey = "RootNode";
            contact.Controller = "Home";
            contact.Action = "Contact";
            contact.Text = "Contact";
            contact.Url = contact.ResolveUrl();
            treeRoot.AddChild(contact);


            NavigationNode siteAdmin = new NavigationNode();
            siteAdmin.Key = "SiteAdmin";
            siteAdmin.ParentKey = "RootNode";
            siteAdmin.Controller = "SiteAdmin";
            siteAdmin.Action = "Index";
            siteAdmin.Text = "Administration";
            siteAdmin.ViewRoles = "Admins,Content Administrators";
            siteAdmin.Url = siteAdmin.ResolveUrl();
            TreeNode<NavigationNode> adminRoot = treeRoot.AddChild(siteAdmin);

            NavigationNode siteSettings = new NavigationNode();
            siteSettings.Key = "BasicSettings";
            siteSettings.ParentKey = "SiteAdmin";
            siteSettings.Controller = "SiteAdmin";
            siteSettings.Action = "SiteInfo";
            siteSettings.Text = "Site Settings";
            siteSettings.ViewRoles = "Admins,Content Administrators";
            siteSettings.ComponentVisibility = NamedNavigationFilters.Breadcrumbs + "," + NamedNavigationFilters.ChildTree; 
            siteSettings.PreservedRouteParameters = "siteGuid";
            siteSettings.Url = siteSettings.ResolveUrl();
            TreeNode<NavigationNode> siteT = adminRoot.AddChild(siteSettings);

            NavigationNode hosts = new NavigationNode();
            hosts.Key = "SiteHostMappings";
            hosts.ParentKey = "BasicSettings";
            hosts.Controller = "SiteAdmin";
            hosts.Action = "SiteHostMappings";
            hosts.Text = "Domain Mappings";
            hosts.ViewRoles = "Admins,Content Administrators";
            hosts.ComponentVisibility = NamedNavigationFilters.Breadcrumbs;
            hosts.PreservedRouteParameters = "siteGuid";
            hosts.Url = hosts.ResolveUrl();
            TreeNode<NavigationNode> hostsT = siteT.AddChild(hosts);

            NavigationNode siteList = new NavigationNode();
            siteList.Key = "SiteList";
            siteList.ParentKey = "SiteAdmin";
            siteList.Controller = "SiteAdmin";
            siteList.Action = "SiteList";
            siteList.Text = "SiteList";
            siteList.ViewRoles = "ServerAdmins";
            siteList.ComponentVisibility = NamedNavigationFilters.Breadcrumbs + "," + NamedNavigationFilters.ChildTree;
            siteList.Url = siteList.ResolveUrl();
            TreeNode<NavigationNode> siteListT = adminRoot.AddChild(siteList);

            NavigationNode newSite = new NavigationNode();
            newSite.Key = "NewSite";
            newSite.ParentKey = "SiteList";
            newSite.Controller = "SiteAdmin";
            newSite.Action = "NewSite";
            newSite.Text = "NewSite";
            newSite.ViewRoles = "ServerAdmins";
            newSite.ComponentVisibility = NamedNavigationFilters.Breadcrumbs + "," + NamedNavigationFilters.ChildTree;
            newSite.Url = newSite.ResolveUrl();
            TreeNode<NavigationNode> newSiteT = siteListT.AddChild(newSite);


            NavigationNode userAdmin = new NavigationNode();
            userAdmin.Key = "UserAdmin";
            userAdmin.ParentKey = "SiteAdmin";
            userAdmin.Controller = "UserAdmin";
            userAdmin.Action = "Index";
            userAdmin.Text = "UserManagement";
            userAdmin.ViewRoles = "ServerAdmins";
            userAdmin.ComponentVisibility = NamedNavigationFilters.Breadcrumbs + "," + NamedNavigationFilters.ChildTree;
            userAdmin.Url = userAdmin.ResolveUrl();
            TreeNode<NavigationNode> userAdminT = adminRoot.AddChild(userAdmin);

            NavigationNode newUser = new NavigationNode();
            newUser.Key = "UserEdit";
            newUser.ParentKey = "UserAdmin";
            newUser.Controller = "UserAdmin";
            newUser.Action = "UserEdit";
            newUser.Text = "NewUser";
            newUser.ViewRoles = "Admins";
            newUser.ComponentVisibility = NamedNavigationFilters.Breadcrumbs + "," + NamedNavigationFilters.ChildTree;
            newUser.Url = newUser.ResolveUrl();
            TreeNode<NavigationNode> newUserT = userAdminT.AddChild(newUser);

            NavigationNode userSearch = new NavigationNode();
            userSearch.Key = "UserSearch";
            userSearch.ParentKey = "UserAdmin";
            userSearch.Controller = "UserAdmin";
            userSearch.Action = "Search";
            userSearch.Text = "User Search";
            userSearch.ViewRoles = "Admins";
            userSearch.ComponentVisibility = NamedNavigationFilters.Breadcrumbs;
            userSearch.Url = userSearch.ResolveUrl();
            TreeNode<NavigationNode> userSearchT = userAdminT.AddChild(userSearch);

            NavigationNode ipSearch = new NavigationNode();
            ipSearch.Key = "IpSearch";
            ipSearch.ParentKey = "UserAdmin";
            ipSearch.Controller = "UserAdmin";
            ipSearch.Action = "IpSearch";
            ipSearch.Text = "IpSearch";
            ipSearch.ViewRoles = "Admins";
            ipSearch.ComponentVisibility = NamedNavigationFilters.Breadcrumbs;
            ipSearch.Url = ipSearch.ResolveUrl();
            TreeNode<NavigationNode> ipSearchT = userAdminT.AddChild(ipSearch);


            NavigationNode roleAdmin = new NavigationNode();
            roleAdmin.Key = "RoleAdmin";
            roleAdmin.ParentKey = "SiteAdmin";
            roleAdmin.Controller = "RoleAdmin";
            roleAdmin.Action = "Index";
            roleAdmin.Text = "RoleManagement";
            roleAdmin.ViewRoles = "Admins";
            roleAdmin.ComponentVisibility = NamedNavigationFilters.Breadcrumbs + "," + NamedNavigationFilters.ChildTree;
            roleAdmin.Url = roleAdmin.ResolveUrl();
            TreeNode<NavigationNode> roleAdminT = adminRoot.AddChild(roleAdmin);

            // TODO: this one should not be in main or child menus
            // we can't have just one url since it depends on roleId
            // but we do want it to appear ar the active breadcrumb
            NavigationNode roleMembers = new NavigationNode();
            roleMembers.Key = "RoleMembers";
            roleMembers.ParentKey = "RoleAdmin";
            roleMembers.Controller = "RoleAdmin";
            roleMembers.Action = "RoleMembers";
            roleMembers.Text = "RoleMembers";
            roleMembers.ViewRoles = "Admins";
            roleMembers.ComponentVisibility = NamedNavigationFilters.Breadcrumbs;
            roleMembers.Url = roleMembers.ResolveUrl();
            roleMembers.PreservedRouteParameters = "roleId,pageNumber,pageSize";
            TreeNode<NavigationNode> roleMembersT = roleAdminT.AddChild(roleMembers);

            NavigationNode roleEdit = new NavigationNode();
            roleEdit.Key = "RoleEdit";
            roleEdit.ParentKey = "RoleAdmin";
            roleEdit.Controller = "RoleAdmin";
            roleEdit.Action = "RoleEdit";
            roleEdit.Text = "NewRole";
            roleEdit.ViewRoles = "Admins";
            roleEdit.ComponentVisibility = NamedNavigationFilters.Breadcrumbs + "," + NamedNavigationFilters.ChildTree;
            roleEdit.Url = roleEdit.ResolveUrl();
            roleEdit.PreservedRouteParameters = "roleIde";
            TreeNode<NavigationNode> roleEditT = roleAdminT.AddChild(roleEdit);


            NavigationNode coreData = new NavigationNode();
            coreData.Key = "CoreData";
            coreData.ParentKey = "SiteAdmin";
            coreData.Controller = "CoreData";
            coreData.Action = "Index";
            coreData.Text = "CoreData";
            coreData.ViewRoles = "ServerAdmins";
            coreData.ComponentVisibility = NamedNavigationFilters.Breadcrumbs + "," + NamedNavigationFilters.ChildTree;
            coreData.Url = coreData.ResolveUrl();
            TreeNode<NavigationNode> coreDataT = adminRoot.AddChild(coreData);

            NavigationNode currencyList = new NavigationNode();
            currencyList.Key = "CurrencyList";
            currencyList.ParentKey = "SiteAdmin";
            currencyList.Controller = "CoreData";
            currencyList.Action = "CurrencyList";
            currencyList.Text = "CurrencyAdministration";
            currencyList.ViewRoles = "ServerAdmins";
            currencyList.ComponentVisibility = NamedNavigationFilters.Breadcrumbs + "," + NamedNavigationFilters.ChildTree;
            currencyList.Url = currencyList.ResolveUrl();
            TreeNode<NavigationNode> currencyListT = coreDataT.AddChild(currencyList);

            //TODO: again I think we just want to be a breadcrumb here
            NavigationNode currencyEdit = new NavigationNode();
            currencyEdit.Key = "CurrencyEdit";
            currencyEdit.ParentKey = "CurrencyList";
            currencyEdit.Controller = "CoreData";
            currencyEdit.Action = "CurrencyEdit";
            currencyEdit.Text = "NewCurrency";
            currencyEdit.ViewRoles = "ServerAdmins";
            currencyEdit.ComponentVisibility = NamedNavigationFilters.Breadcrumbs;
            currencyEdit.Url = currencyEdit.ResolveUrl();
            currencyEdit.PreservedRouteParameters = "currencyGuid";
            TreeNode<NavigationNode> currencyEditT = currencyListT.AddChild(currencyEdit);


            NavigationNode countryList = new NavigationNode();
            countryList.Key = "CountryListPage";
            countryList.ParentKey = "SiteAdmin";
            countryList.Controller = "CoreData";
            countryList.Action = "CountryListPage";
            countryList.Text = "CountryStateAdministration";
            countryList.ViewRoles = "ServerAdmins";
            countryList.ComponentVisibility = NamedNavigationFilters.Breadcrumbs + "," + NamedNavigationFilters.ChildTree;
            countryList.Url = countryList.ResolveUrl();
            TreeNode<NavigationNode> countryListT = coreDataT.AddChild(countryList);

            NavigationNode countryEdit = new NavigationNode();
            countryEdit.Key = "CountryEdit";
            countryEdit.ParentKey = "CountryListPage";
            countryEdit.Controller = "CoreData";
            countryEdit.Action = "CountryEdit";
            countryEdit.Text = "NewCountry";
            countryEdit.ViewRoles = "ServerAdmins";
            countryEdit.ComponentVisibility = NamedNavigationFilters.Breadcrumbs + "," + NamedNavigationFilters.ChildTree;
            countryEdit.Url = countryEdit.ResolveUrl();
            countryEdit.PreservedRouteParameters = "guid";
            TreeNode<NavigationNode> countryEditT = countryListT.AddChild(countryEdit);

            NavigationNode stateList = new NavigationNode();
            stateList.Key = "StateListPage";
            stateList.ParentKey = "CountryListPage";
            stateList.Controller = "CoreData";
            stateList.Action = "StateListPage";
            stateList.Text = "States";
            stateList.ViewRoles = "ServerAdmins";
            stateList.ComponentVisibility = NamedNavigationFilters.Breadcrumbs;
            stateList.Url = stateList.ResolveUrl();
            stateList.PreservedRouteParameters = "countryGuid";
            TreeNode<NavigationNode> stateListT = countryListT.AddChild(stateList);

            NavigationNode stateEdit = new NavigationNode();
            stateEdit.Key = "StateEdit";
            stateEdit.ParentKey = "StateListPage";
            stateEdit.Controller = "CoreData";
            stateEdit.Action = "StateEdit";
            stateEdit.Text = "New State";
            stateEdit.ViewRoles = "ServerAdmins";
            stateEdit.ComponentVisibility = NamedNavigationFilters.Breadcrumbs;
            stateEdit.Url = stateEdit.ResolveUrl();
            stateEdit.PreservedRouteParameters = "countryGuid";
            TreeNode<NavigationNode> stateEditT = stateListT.AddChild(stateEdit);



            //string serialized = JsonConvert.SerializeObject(treeRoot,Formatting.Indented);


            return treeRoot;
        }
        private void AddChildNode(TreeNode<NavigationNode> node, XElement xmlNode)
        {
            NavigationNode navNode = BuildNavNode(xmlNode);
            TreeNode<NavigationNode> navNodeT = node.AddChild(navNode);

            foreach (XElement childrenNode in xmlNode.Elements(XName.Get("Children")))
            {
                foreach (XElement childNode in childrenNode.Elements(XName.Get("NavNode")))
                {
                    AddChildNode(navNodeT, childNode); //recursion   
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Common.UI.MenuItems.MenuItem"/> class with given text and with
        /// assigning to specified <see cref="Common.TreeNode`1"/> instance.
        /// </summary>
        /// <param name="owner"><see cref="Common.TreeNode`1"/> instance.</param>
        /// <param name="text">Menu item text.</param>
        /// <param name="onClick">Click event handler.</param>
        /// <param name="enabled">Is this menu item enabled or not.</param>
        /// <param name="shortcutHandler">Shortcut handler.</param>
        /// <param name="shortcut">Shortcut.</param>
        /// <param name="radioGroup">Menu radio group.</param>
        public static TreeNode<CustomMenuItem> Create(
                                                        TreeNode<CustomMenuItem> owner
                                                      , string 		             text
                                                      , UnityAction              onClick         = null
                                                      , bool                     enabled         = true
                                                      , IShortcutHandler         shortcutHandler = null
                                                      , string                   shortcut        = null
                                                      , MenuRadioGroup           radioGroup      = null
                                                     )
        {
            DebugEx.VerboseFormat("MenuItem.Create(owner = {0}, text = {1}, onClick = {2}, enabled = {3}, shortcutHandler = {4}, shortcut = {5}, radioGroup = {6})"
                                  , owner
                                  , text
                                  , onClick
                                  , enabled
                                  , shortcutHandler
                                  , shortcut
                                  , radioGroup);

            MenuItem item = new MenuItem(
                                           R.sections.MenuItems.strings.Count // Token ID
                                         , null                               // Token arguments
                                         , text                               // Text
                                         , enabled                            // Enabled
                                         , onClick                            // Click event handler
                                         , shortcutHandler                    // Shortcut handler
                                         , KeyboardInput.FromString(shortcut) // Shortcut
                                         , radioGroup                         // Menu radio group
                                        );

            TreeNode<CustomMenuItem> node = owner.AddChild(item);

            item.mNode = node;

            return node;
        }
        /// <summary>
        /// Constructur returns a skeleton in standrad ISO/IEC FCD 19774 specification
        /// http://h-anim.org/Specifications/H-Anim200x/ISO_IEC_FCD_19774/
        /// </summary>
        /// <returns></returns>
        public static TreeNode<Bone> GetHAminSkeleton()
        {
            TreeNode<Bone> root = new TreeNode<Bone>(new Bone(Joint.PELVIS,
            HAminStandard.pelvisPos, Quaternion.Identity));
            #region bone structure
            {
                #region upper body
                #region spine and head
                TreeNode<Bone> spine0 = root.AddChild(new Bone(Joint.SPINE0,
                    HAminStandard.spine0Pos,
                    HAminStandard.spine0Rot));
                {
                    TreeNode<Bone> spine1 = spine0.AddChild(new Bone(Joint.SPINE1,
                        HAminStandard.spine1Pos,
                        HAminStandard.spine1Rot));
                    {
                        TreeNode<Bone> spine3 = spine1.AddChild(new Bone(Joint.SPINE3,
                            HAminStandard.spine3Pos,
                            HAminStandard.spine3Rot));
                    {
                        TreeNode<Bone> neck = spine3.AddChild(new Bone(Joint.NECK,
                            HAminStandard.neckPos,
                            HAminStandard.neckRot));
                        {
                            TreeNode<Bone> head = neck.AddChild(new Bone(Joint.HEAD,
                                HAminStandard.headPos,
                                HAminStandard.headRot));
                            {
                                head.AddChild(new Bone(Joint.HEADTOP, HAminStandard.headTopPos, QuaternionHelper2.Zero));
                            }
                        }
                #endregion
                        #region arm left
                        TreeNode<Bone> clavicleLeft = spine3.AddChild(new Bone(Joint.CLAVICLE_L,
                            HAminStandard.spine3Pos,
                            HAminStandard.clavicleLeftRot));
                        {
                            TreeNode<Bone> shoulderLeft = clavicleLeft.AddChild(new Bone(Joint.SHOULDER_L,
                                HAminStandard.shoulderLeftPos,
                                HAminStandard.shoulderLeftRot));
                            {
                                TreeNode<Bone> elbowLeft = shoulderLeft.AddChild(new Bone(Joint.ELBOW_L,
                                    HAminStandard.elbowLeftPos,
                                    HAminStandard.elbowLeftRot));
                                {
                                    TreeNode<Bone> wristLeft = elbowLeft.AddChild(new Bone(Joint.WRIST_L,
                                        HAminStandard.wristLeftPos,
                                        HAminStandard.wristLeftRot));
                                    {
                                        TreeNode<Bone> handLeft = wristLeft.AddChild(new Bone(Joint.HAND_L,
                                            HAminStandard.handLeftPos,
                                            HAminStandard.handLeftRot));
                                        {
                                            handLeft.AddChild(new Bone(Joint.INDEX_L,
                                            HAminStandard.indexLeftPos,
                                            QuaternionHelper2.Zero));
                                        }
                                        TreeNode<Bone> trapezoidLeft = wristLeft.AddChild(new Bone(Joint.TRAP_L,
                                                HAminStandard.wristLeftPos,
                                                HAminStandard.trapezoidLeftRot));
                                        {
                                            trapezoidLeft.AddChild(new Bone(Joint.THUMB_L,
                                            HAminStandard.thumbLeftPos,
                                            QuaternionHelper2.Zero));
                                        }
                                    }
                                }
                            }
                        }
                        #endregion
                        #region arm right
                        TreeNode<Bone> clavicleRight =
                            spine3.AddChild(new Bone(Joint.CLAVICLE_R,
                            HAminStandard.spine3Pos,
                            HAminStandard.clavicleRightRot));
                        {
                            TreeNode<Bone> shoulderRight =
                                clavicleRight.AddChild(new Bone(Joint.SHOULDER_R,
                                HAminStandard.shoulderRightPos,
                                HAminStandard.shoulderRightRot));
                            {
                                TreeNode<Bone> elbowRight =
                                    shoulderRight.AddChild(new Bone(Joint.ELBOW_R,
                                    HAminStandard.elbowRightPos,
                                    HAminStandard.elbowRightRot));
                                {
                                    TreeNode<Bone> wristRight =
                                        elbowRight.AddChild(new Bone(Joint.WRIST_R,
                                        HAminStandard.wristRightPos,
                                        HAminStandard.wristRightRot));
                                    {
                                        TreeNode<Bone> handRight =
                                            wristRight.AddChild(new Bone(Joint.HAND_R,
                                            HAminStandard.handRightPos,
                                            HAminStandard.handRightRot));
                                        {
                                            handRight.AddChild(new Bone(Joint.INDEX_R,
                                            HAminStandard.indexRightPos,
                                            QuaternionHelper2.Zero));
                                        TreeNode<Bone> trapezoidRight =
                                            wristRight.AddChild(new Bone(Joint.TRAP_R,
                                            HAminStandard.wristRightPos,
                                            HAminStandard.trapezoidRightRot));
                                        {
                                            trapezoidRight.AddChild(new Bone(Joint.THUMB_R,
                                            HAminStandard.thumbRightPos,
                                            QuaternionHelper2.Zero));
                                        }
                                        }
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                }
                }
                #endregion
                #region legs left
                TreeNode<Bone> hipLeft =
                    root.AddChild(new Bone(Joint.HIP_L,
                        HAminStandard.hipLeftPos,
                        HAminStandard.hipLeftRot));
                {

                    TreeNode<Bone> kneeLeft =
                        hipLeft.AddChild(new Bone(Joint.KNEE_L,
                            HAminStandard.kneeLeftPos,
                            HAminStandard.kneeLeftRot));
                    {
                        TreeNode<Bone> ankleLeft =
                            kneeLeft.AddChild(new Bone(Joint.ANKLE_L,
                                HAminStandard.ankleLeftPos,
                                HAminStandard.ankleLeftRot));
                        {
                            TreeNode<Bone> footBaseLeft =
                                ankleLeft.AddChild(new Bone(Joint.FOOTBASE_L,
                                    HAminStandard.footBaseLeftPos,
                                    HAminStandard.footBaseLeftRot));
                            {
                                footBaseLeft.AddChild(
                                    new Bone(Joint.TOE_L,
                                        HAminStandard.toeLeftPos,
                                        QuaternionHelper2.Zero)
                                    );
                            }
                        }
                    }
                }
                #endregion
                #region legs right
                TreeNode<Bone> hipRight =
                    root.AddChild(new Bone(Joint.HIP_R,
                        HAminStandard.hipRightPos,
                        HAminStandard.hipRightRot));
                {
                    TreeNode<Bone> kneeRight =
                        hipRight.AddChild(new Bone(Joint.KNEE_R,
                            HAminStandard.kneeRightPos,
                            HAminStandard.kneeRightRot));
                    {
                        TreeNode<Bone> ankleRight =
                            kneeRight.AddChild(new Bone(Joint.ANKLE_R,
                                HAminStandard.ankleRightPos,
                                HAminStandard.ankleRightRot));
                        {
                            TreeNode<Bone> footBaseRight =
                                ankleRight.AddChild(new Bone(Joint.FOOTBASE_R,
                                    HAminStandard.footBaseRightPos,
                                    HAminStandard.footBaseRightRot));
                            {
                                footBaseRight.AddChild(
                                    new Bone(Joint.TOE_R,
                                        HAminStandard.toeRightPos,
                                        QuaternionHelper2.Zero));
                            }
                        }
                    }
                }
                #endregion
            }
                #endregion
            return root;
        }
 private void AddChildren(TreeNode<Comment> parentNode)
 {
     foreach(Comment child in parentNode.Data.Replies.Comments)
     {
         TreeNode<Comment> childNode = parentNode.AddChild(child);
         AddChildren(childNode);
     }
 }
        private async Task AddChildNode(
            TreeNode<NavigationNode> node, 
            XElement xmlNode,
            NavigationTreeBuilderService service
            )
        {
            NavigationNode navNode = BuildNavNode(xmlNode, service);
            TreeNode<NavigationNode> navNodeT = node.AddChild(navNode);

            foreach (XElement childrenNode in xmlNode.Elements(XName.Get("Children")))
            {
                foreach (XElement childNode in childrenNode.Elements(XName.Get("NavNode")))
                {
                    var childBuilder = GetNodeBuilderName(childNode);
                    if (string.IsNullOrEmpty(childBuilder))
                    {
                        await AddChildNode(navNodeT, childNode, service).ConfigureAwait(false); //recursion
                    }
                    else
                    {
                        var child = await service.GetTree(childBuilder).ConfigureAwait(false);
                        if (child.Value.ChildContainerOnly)
                        {
                            foreach (var subChild in child.Children)
                            {
                                navNodeT.AddChild(subChild);
                            }
                        }
                        else
                        {
                            navNodeT.AddChild(child);
                        }

                        
                    }

                       
                }
            }

            

        }