コード例 #1
0
        static private async Task MainTask()
        {
            await Downloader.GetBooks();

            var files = Directory.EnumerateFiles("books", "*.txt", SearchOption.AllDirectories);

            files = files.Where(file => !Path.GetFileName(file).StartsWith("new_"));
            // Console.WriteLine(files.Count());

            ConsoleTime.Start("Part1");
            foreach (var file in files)
            {
                Converter.Koi7ifyFile(file);
            }
            ConsoleTime.End("Part1");

            ConsoleTime.Start("Part2");
            await Task.WhenAll(files.Select(file =>
                                            Task.Run(() => Converter.Koi7ifyFile(file))
                                            ));

            ConsoleTime.End("Part2");

            ConsoleTime.Start("Part3");
            await Downloader.GetEBook();

            Converter.Koi7ifyFile("book_from_web.txt");
            ConsoleTime.End("Part3");
        }
コード例 #2
0
ファイル: Downloader.cs プロジェクト: Cortan122/cp20200529
        static public async Task GetEBook()
        {
            if (File.Exists("book_from_web.txt"))
            {
                return;
            }
            ConsoleTime.Start("GetEBook");
            await Download("https://www.gutenberg.org/files/1342/1342-0.txt", "book_from_web.txt");

            ConsoleTime.End("GetEBook");
        }
コード例 #3
0
ファイル: Downloader.cs プロジェクト: Cortan122/cp20200529
        static public async Task GetBooks()
        {
            if (Directory.Exists("books"))
            {
                return;
            }
            ConsoleTime.Start("GetBooks");
            await Download("https://getfile.dokpub.com/yandex/get/https://yadi.sk/d/fh3lefTcQ_hLLA", "books.zip");

            ZipFile.ExtractToDirectory("books.zip", "books");
            ConsoleTime.End("GetBooks");
        }
コード例 #4
0
        public static void Koi7ifyFile(string path)
        {
            var name = Path.GetFileName(path);

            ConsoleTime.Start("file " + name);

            var str1 = File.ReadAllText(path);
            var str2 = Koi7ify(str1);

            var newFilename = Path.Combine(Path.GetDirectoryName(path), "new_" + name);

            File.WriteAllText(newFilename, str2);

            Console.WriteLine($"{name}: {str1.Length} -> {str2.Length}");
            ConsoleTime.End("file " + name);
        }