Ejemplo n.º 1
0
        /// <summary>
        /// Обработка книги с сайта.
        /// </summary>
        /// <param name="ur"> Ссылка. </param>
        static async Task FromWeb(string ur, FileWorker fw)
        {
            string response;

            // Получаю книгу.
            try
            {
                HttpClient client = new HttpClient();
                response = await client.GetStringAsync(ur);

                Console.WriteLine("Книга получена.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Хм, что-то пошло не так..\n" + ex.Message);
                return;
            }

            // Запускаю таймер.
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            // Перевод.
            Tuple <int, int> sums = Translit(fw.ActualName + "/", ".txt", "new_book_from_web", new string[] { response });

            Console.WriteLine($"Web file: {sums.Item1} -> {sums.Item2}");

            // Затраченное время.
            stopWatch.Stop();
            TimeSpan ts          = stopWatch.Elapsed;
            string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}",
                                                 ts.Hours, ts.Minutes, ts.Seconds,
                                                 ts.Milliseconds / 10);

            Console.WriteLine("Web time: " + elapsedTime);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Синхронный перевод.
        /// </summary>
        static void FirstMethod(FileWorker fw)
        {
            // Запуск общего таймера.
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            // Для всех файлов в директории.
            foreach (string path in Directory.GetFiles(fw.ActualName))
            {
                // Запуск таймера для конкретного файла.
                Stopwatch currentWatch = new Stopwatch();
                currentWatch.Start();

                // Перевод.
                Tuple <int, int> sums = Translit(fw.ActualName + "/", Path.GetFileName(path));

                // Подсчёт времени для конкретного файла.
                currentWatch.Stop();
                Console.WriteLine($"File {Path.GetFileName(path)}: {sums.Item1} -> {sums.Item2}");
                TimeSpan currentSpan = currentWatch.Elapsed;
                string   currentTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}",
                                                     currentSpan.Hours, currentSpan.Minutes, currentSpan.Seconds,
                                                     currentSpan.Milliseconds / 10);
                Console.WriteLine("Time: " + currentTime);
            }

            // Подсчёт общего времени.
            stopWatch.Stop();
            TimeSpan ts          = stopWatch.Elapsed;
            string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}",
                                                 ts.Hours, ts.Minutes, ts.Seconds,
                                                 ts.Milliseconds / 10);

            Console.WriteLine("First method time: " + elapsedTime);
        }