Ejemplo n.º 1
0
        public static string ToAsciiTree(this IFileSystem fileSystem)
        {
            void AddFolder(IFileSystem fileSystem, UPath path, AsciiTreeNode parentNode)
            {
                foreach (var directoryPath in fileSystem.EnumerateDirectories(path))
                {
                    var directoryNode = new AsciiTreeNode(directoryPath.GetName());
                    parentNode.Children.Add(directoryNode);

                    AddFolder(fileSystem, directoryPath, directoryNode);
                }

                foreach (var filePath in fileSystem.EnumerateFiles(path))
                {
                    parentNode.Children.Add(new AsciiTreeNode(filePath.GetName()));
                }
            }

            var rootNode = new AsciiTreeNode("<root>");

            AddFolder(fileSystem, UPath.Root, rootNode);

            var treeWriter = new AsciiTreeWriter();

            treeWriter.WriteNode(rootNode);
            return(treeWriter.ToString());
        }
Ejemplo n.º 2
0
        private void PrintNode(AsciiTreeNode node, string indent)
        {
            m_Writer.WriteLine(node.Name);

            // Loop through the children recursively, passing in the
            // indent, and the isLast parameter
            var numberOfChildren = node.Children.Count;

            for (var i = 0; i < numberOfChildren; i++)
            {
                var child  = node.Children[i];
                var isLast = (i == (numberOfChildren - 1));
                PrintChildNode(child, indent, isLast);
            }
        }
Ejemplo n.º 3
0
        private void PrintChildNode(AsciiTreeNode node, string indent, bool isLast)
        {
            // Print the provided pipes/spaces indent
            m_Writer.Write(indent);

            // Depending if this node is a last child, print the
            // corner or cross, and calculate the indent that will
            // be passed to its children
            if (isLast)
            {
                m_Writer.Write(s_Corner);
                indent += s_Space;
            }
            else
            {
                m_Writer.Write(s_Cross);
                indent += s_Vertical;
            }

            PrintNode(node, indent);
        }
Ejemplo n.º 4
0
 public void WriteNode(AsciiTreeNode topLevelNode)
 {
     PrintNode(topLevelNode, indent: "");
 }