/// <summary>
        /// Method to perform first task of training.
        /// Prints all files and subdirectories in specified directory.
        /// </summary>
        private void DirectoryTask()
        {
            this.Writer.WriteLine("\nTask 1: Directory Visualizer");
            this.Writer.Write("\n Enter directory path: ");
            string path = this.Reader.ReadLine();

            if (string.IsNullOrEmpty(path))
            {
                this.Writer.WriteLine(" Error: Path cannot be empty.");
                return;
            }

            try
            {
                DirectoryVisualizer directoryVisualizer = new DirectoryVisualizer()
                {
                    Writer = this.Writer
                };
                directoryVisualizer.DisplayFilesAndSubdirectories(path);
            }
            catch (ArgumentException e)
            {
                this.Writer.WriteLine(e.Message);
                this.Logger.LogMessage($"Class - ThirdTrainingRunner | Method - DirectoryTask | {e.Message}");
            }
        }
        public void RunTaskVisualiseDirectory()
        {
            Console.WriteLine("____________Task Directory Visualiser____________");
            DirectoryVisualizer directoryVisualiser = new DirectoryVisualizer(new ConsolePrinter());

            directoryVisualiser.VisualizeDirectory();
        }
        public void Main()
        {
            IPrinter printer = new ConsolePrinter();
            IReader  reader  = new ConsoleReader();

            try
            {
                printer.PrintLine("Enter first path to directory");
                var path1     = reader.ReadLine();
                var fileList1 = DirectoryVisualizer.GetFilesFromDirectory(path1);

                printer.PrintLine("Enter second path to directory");
                var path2     = reader.ReadLine();
                var fileList2 = DirectoryVisualizer.GetFilesFromDirectory(path2);

                var watch = new Stopwatch();
                watch.Start();
                var uniqueFiles = CompareFiles.GetUniqueFiles(fileList1 as List <string>, fileList2 as List <string>);
                var commonFiles = CompareFiles.GetCommonFiles(fileList1 as List <string>, fileList2 as List <string>);
                watch.Stop();

                printer.PrintLine("Enter 1 to print info on console or 2 to print info to file");
                string FileOrConsole = reader.ReadLine();
                switch (FileOrConsole)
                {
                case "1":
                {
                    Print(commonFiles.ToList(), uniqueFiles.ToList(), new ConsolePrinter());
                    break;
                }

                case "2":
                {
                    Print(commonFiles.ToList(), uniqueFiles.ToList(), new FilePrinter());
                    break;
                }

                default:
                {
                    printer.PrintLine("You entered wrong symbol");
                    break;
                }
                }

                printer.PrintLine("\nExecution task time = " + watch.ElapsedMilliseconds + " ms");
            }
            catch (Exception ex)
            {
                printer.PrintLine(ex.Message);
                return;
            }
        }
Пример #4
0
        static void Hometask3()
        {
            Console.WriteLine("Enter directory you want visualize:");
            string directory = Console.ReadLine();

            DirectoryVisualizer visualizer = new DirectoryVisualizer(directory, new ConsoleUI(), Logger);

            visualizer.Visualize();
            DelayAndClear();

            Console.WriteLine("Enter a file name you are looking for:");
            string filename = Console.ReadLine();

            FileSearcher fs = new FileSearcher(filename, Logger);

            Console.WriteLine($"File location: {fs.SearchFile()}");
            DelayAndClear();
        }
Пример #5
0
 public Task1(IPrinter printer, ILogger <Task1> logger, DirectoryVisualizer directoryVisualizer)
 {
     _printer = printer;
     _logger  = logger;
     this.directoryVisualizer = directoryVisualizer;
 }
Пример #6
0
        static void Main(string[] args)
        {
            IPrinter  consolePrinter = new ConsolePrinter();
            Logger    logger         = new Logger(new FilePrinter("log.txt"));
            Stopwatch watch          = new Stopwatch();

            consolePrinter.WriteLine("Enter number of lab: ");
            switch (consolePrinter.ReadLine())
            {
            case "1":
                watch.Start();

                try {
                    Person personTest = new Person(Console.ReadLine(), Console.ReadLine(), Convert.ToInt32(Console.ReadLine()));
                    Console.WriteLine(personTest.CompareByAge(Convert.ToInt32(Console.ReadLine())));

                    Lab1Lib.Rectangle rectangleTest = new Lab1Lib.Rectangle(0, 0, 10, 20);
                    Console.WriteLine($"Perimeter of rectangle with height: {rectangleTest.Height}  {rectangleTest.Perimeter()}");

                    Console.WriteLine(Enum.GetName(typeof(Month), Convert.ToInt32(Console.ReadLine())));



                    consolePrinter.WriteLine($"Max: {(long)LongRange.Max}, Min: {(long)LongRange.Min}");
                }
                catch (Exception e) {
                    consolePrinter.WriteLine(e.Message);
                    logger.WriteMsg(e.Message);
                }

                watch.Stop();
                consolePrinter.WriteLine("Time: " + watch.Elapsed);;
                break;

                break;

            case "2":
                try {
                    GenerateExeption.StackOverflow_ExseptionGenerete();
                    GenerateExeption.IndexOuOfRange_ExceptionGenerate(new int[] { 0, 1, 2, 3, 4 }, 5);
                    GenerateExeption.DoSomeMath(-3, 3);
                }
                catch (Exception e) {
                    consolePrinter.WriteLine(e.Message);
                    logger.WriteMsg(e.Message);
                }
                break;

            case "3":
                watch.Start();

                try {
                    DirectoryInfo dir = new DirectoryInfo(Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.Parent.FullName);

                    DirectoryVisualizer.PrintSubDir(dir, consolePrinter);
                    consolePrinter.WriteLine("-------");
                    DirectoryVisualizer.FindLocationOfFileByPartName("ogram", dir, consolePrinter);
                }
                catch (Exception e) {
                    consolePrinter.WriteLine(e.Message);
                    logger.WriteMsg(e.Message);
                }

                watch.Stop();
                consolePrinter.WriteLine("Time: " + watch.Elapsed);;
                break;

            case "4":
                List <Car> cars = new List <Car>()
                {
                    new Car("car1", "01", "black"),
                    new Car("car2", "02", "white"),
                    new Car("car3", "04", "black"),
                    new Car("car4", "03", "yellow")
                };
                watch.Restart();

                try {
                    Serializer.ToXML("Cars.xml", cars, typeof(List <Car>));
                    Serializer.ToBinary("Cars.dat", cars);
                    Serializer.ToJSON("Cars.json", cars);

                    foreach (Car cs in (List <Car>)Deserializer.FromBinary("Cars.dat"))
                    {
                        consolePrinter.WriteLine(cs.ToString());
                    }
                }
                catch (Exception e) {
                    consolePrinter.WriteLine(e.Message);
                    logger.WriteMsg(e.Message);
                }

                watch.Stop();
                consolePrinter.WriteLine("Time: " + watch.Elapsed);
                break;

            case "5":
                watch.Restart();

                try {
                    PrintInfo.PrintInfoAssembly(consolePrinter);
                }
                catch (Exception e) {
                    consolePrinter.WriteLine(e.Message);
                    logger.WriteMsg(e.Message);
                }

                watch.Stop();
                consolePrinter.WriteLine("Time: " + watch.Elapsed);
                break;

            case "7":
                watch.Restart();

                try {
                    Calculator.Calculate(consolePrinter.ReadLine().ToString(), consolePrinter);
                }
                catch (Exception e) {
                    consolePrinter.WriteLine(e.Message);
                    logger.WriteMsg(e.Message);
                }

                watch.Stop();
                consolePrinter.WriteLine("Time: " + watch.Elapsed);
                break;

            case "8":
                watch.Restart();

                try {
                    watch.Start();
                    consolePrinter.WriteLine(MatrixOperation.sumInThread(MatrixOperation.GenerateMatrix(1000, 1000), 10).ToString());
                    watch.Stop();
                }
                catch (Exception e) {
                    logger.WriteMsg(e.Message);
                    consolePrinter.WriteLine(e.Message);
                }

                watch.Stop();
                consolePrinter.WriteLine("Time: " + watch.Elapsed.ToString());
                break;

            default:
                consolePrinter.WriteLine("Invalid number");
                break;
            }
        }