Exemplo n.º 1
0
        public static async Task <List <Match> > ParseMatchesAsync(Dictionary <Season, List <string> > matchUrls)
        {
            var matches = new List <Match>();
            var urlList = from mu in matchUrls
                          from u in mu.Value
                          select u;

            var parser = new UriParser(urlList);

            var result = await parser.ParseAllAsync();

            foreach (var request in result)
            {
                var doc = new HtmlDocument();
                doc.LoadHtml(request.Value);

                try
                {
                    var season = matchUrls.Where(mu => mu.Value.Contains(request.Key)).Select(mu => mu.Key).First();
                    var match  = new Match(doc.DocumentNode)
                    {
                        Url    = request.Key,
                        Season = season
                    };
                    var success = match.ParseInfo();

                    if (success)
                    {
                        matches.Add(match);
                    }
                }
                catch (Exception x)
                {
                    ErrorHandling.Log($"Match { request.Key } could not be parsed. Exception: { x.Message }");
                }
            }

            return(matches);
        }