Exemplo n.º 1
0
        public void DisplayTree(DirectoryTreeMap root)
        {
            var right = new List <int>();

            // now, retrieve all descendants of the $root node

            var query    = "SELECT * FROM DirectoryTreeMap " + $"WHERE lft BETWEEN {root.Lft} AND {root.Rgt} ORDER BY [lft] ASC;";
            var children = _directoryTreeMapSet.SqlQuery(query).AsNoTracking().ToList();

            // display each row
            foreach (var child in children)
            {
                // only check stack if there is one
                if (right.Count > 0)
                {
                    // check if we should remove a node from the stack
                    while (right[right.Count - 1] < child.Rgt)
                    {
                        right.RemoveAt(right.Count - 1);
                    }
                }
                for (var i = 0; i < right.Count; i++)
                {
                    Console.Write("  ");
                }
                // display indented node title
                Console.WriteLine(child.Name + $" ({child.Lft}:{child.Rgt})");

                // add this node to the stack
                right.Add(child.Rgt);
                //Console.WriteLine("Right: " + child.Rgt);
            }
        }
Exemplo n.º 2
0
 public void DeleteNode(DirectoryTreeMap currentNode)
 {
     //only delete if node is leaf
     if ((currentNode.Rgt - currentNode.Lft + 1) / 2 == 1)
     {
         _context.Database.ExecuteSqlCommand("Exec [DeleteNode] @p0", currentNode.Id);
     }
 }
Exemplo n.º 3
0
        public void InitRoot()
        {
            var query  = "Select top 1 * from DirectoryTreeMap";
            var result = _directoryTreeMapSet.SqlQuery(query).FirstOrDefault();

            if (result == null)
            {
                var newNode = new DirectoryTreeMap
                {
                    Lft      = 1,
                    Rgt      = 2,
                    ParentId = 0
                };
                _directoryTreeMapSet.Add(newNode);
                _context.SaveChanges();
            }
        }
Exemplo n.º 4
0
 public void MoveToLeftSide(DirectoryTreeMap currentNode, DirectoryTreeMap parentNode)
 {
     _context.Database.ExecuteSqlCommand("Exec [MoveNode] @p0, @p1, @p2, @p3", currentNode.Id, parentNode.Id, currentNode.Lft, currentNode.Rgt);
 }