コード例 #1
0
 public async Task when_parameter_is_not_null_we_throw_exception()
 {
     await Assert.ThrowsAsync <ArgumentException>(() => _headerParser.GetMetaData(File.OpenRead(TestfilesHeadingTxt)));
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: SorrowAureus/MangaScraper
        private static async Task GetMetaData(IMetaDataParser parser)
        {
            var options = new ProgressBarOptions
            {
                ForegroundColor   = ConsoleColor.Yellow,
                BackgroundColor   = ConsoleColor.DarkYellow,
                ProgressCharacter = '─'
            };

            var        cts    = new CancellationTokenSource();
            var        mgr    = new MangaDownloader(null, new List <ISeriesParser>());
            PageGetter getter = Client2.GetDocumentAsync;
            var        doc    = await getter("https://www.mangaeden.com/en/en-manga/naruto/");

            //var doc = await getter("http://manganelo.com/manga/read_naruto_manga_online_free3");
            var metaData = parser.GetMetaData(doc);

            var service = new MetaDataService(new List <IMetaDataParser>()
            {
                parser
            });

            var wasCalled = false;

            IProgress <double> GetProgress(string context)
            {
                if (context == "Instances" && !wasCalled)
                {
                    wasCalled = true;
                    Console.WriteLine($"Handling {context}");
                    Console.WriteLine();
                    return(new ConsoleProgress(options, context));
                }

                if (context == "MetaData")
                {
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine($"Handling {context}");
                    Console.WriteLine();
                    return(new ConsoleProgress(options, context));
                }

                cts.Cancel();
                return(null);
            }

            service.ReportProgressFactory = GetProgress;
            var t = service.Start(parser.ProviderName, cts.Token);

            try
            {
                await t;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            var res2 = await service.GetMetaData();

            var test   = res2.Where(a => a.metaData.Genres.HasFlag(Genre.MartialArts)).ToList();
            var unused = Enum.GetValues(typeof(Genre)).Cast <Genre>().Where(e => e != Genre.None).ToDictionary(g => g, _ => false);

            foreach (var valueTuple in res2)
            {
                foreach (var genre in valueTuple.metaData.Genres.Split())
                {
                    if (unused.ContainsKey(genre))
                    {
                        unused[genre] = true;
                    }
                }
            }

            var areNotUsed = unused.Where(kvp => !kvp.Value).Select(kvp => kvp.Key).ToList();

            Console.Read();
        }