コード例 #1
0
        public static void Main(string[] args)
        {
            while (true)
            {
                BTree     bTree     = new BTree();
                PrintTree printTree = new PrintTree();
                string    node1;
                string    node2;
                string[]  input;

                printTree.Print(bTree.Root, "");

                Console.WriteLine("****************************************************************");

                Console.WriteLine("Please enter the names of the nodes you'd like to find the parent of (type quit to quit): ");

                input = Console.ReadLine().Trim().Split(' ');

                if (input.Contains("quit"))
                {
                    break;
                }

                if (input.Length > 1)
                {
                    node1 = input[0];
                    node2 = input[1];
                }
                else
                {
                    node1 = input.First();
                    node2 = Console.ReadLine();
                }

                bool success = new BTreeNodeService(new Node {
                    Name = node1
                }, new Node {
                    Name = node2
                })
                               .SetSelectedAndParentNodes(bTree.Root);

                if (success)
                {
                    printTree.Print(bTree.Root, "");
                }
                else
                {
                    Console.WriteLine("Parent not found, make sure to enter the correct node names");
                }

                Console.WriteLine("****************************************************************");
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            //get path of directory from which the app is launched
            string workDir  = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\";
            string filePath = workDir + @"test.torrent";

            //initialize parser instance
            BEncodeParser ben = new BEncodeParser();
            //parse torrent file and get TorrentObject
            TorrentObject torrent = ben.BuildTorrent(filePath);

            //get all files and put them to separate list
            List <TorrentObject.FileStruct> listFiles = torrent.Info.Files;

            //print all file names from torrent in sorted (alpha-numeric) order
            Console.WriteLine("===Torrent consists of next files:");
            foreach (object o in torrent.Info.Files.OrderBy(x => x.FullPath))
            {
                //custom print method from 'PrintTree' class
                PrintTree.PrintTreeSimple(o, 1, 0);
            }
            Console.WriteLine();

            //get all files from folder "The Hunting Party".
            //  as files in different folders have different start index (first 2 symbols + one space) in its names,
            //  we get file name starting from 4 symbol:
            //      x.FileName.Substring(3)
            string[] list1 = listFiles.Where(x => x.FullPath.StartsWith("The Hunting Party")).Select(x => x.FileName.Substring(3)).ToArray();
            //get all files from folder "Compilation"
            string[] list2 = listFiles.Where(x => x.FullPath.StartsWith("Compilation")).Select(x => x.FileName.Substring(3)).ToArray();
            //get all files in folder "The Hunting Party" which are not included in folder "Compilation"
            string[] except = list1.Except(list2).ToArray();

            //print all selected files
            Console.WriteLine("===The Hunting Party unique files:");
            foreach (object o in except)
            {
                //custom print method from 'PrintTree' class
                PrintTree.PrintTreeSimple(o, 1, 0);
            }

            Console.WriteLine("\nAny key to exit...");
            Console.ReadKey();
        }