Ejemplo n.º 1
0
        private IEnumerable <BoosterPack> GetBoosterPacks(IDictionary <string, string> links, out IEnumerable <Error> errors)
        {
            var boosterPacks = new ConcurrentBag <BoosterPack>();
            var total        = links.Count;
            var current      = 0;
            var tempErrors   = new ConcurrentBag <Error>();

            Parallel.ForEach(links, ScraperConstants.ParallelOptions, kv =>
            {
                try
                {
                    var boosterPack = new BoosterPackParser(kv.Key, $"{ScraperConstants.YuGiPediaUrl}{ScraperConstants.MediaWikiParseIdUrl}{kv.Value}").Parse(HttpClient);
                    boosterPack.Url = $"{ScraperConstants.YuGiPediaUrl}?curid={kv.Value}";

                    #region OCG TCG
                    boosterPack.TcgExists = TcgBoosters.ContainsKey(boosterPack.Name);
                    boosterPack.OcgExists = OcgBoosters.ContainsKey(boosterPack.Name);
                    #endregion OCG TCG

                    boosterPacks.Add(boosterPack);
                }
                catch (Exception exception)
                {
                    tempErrors.Add(new Error()
                    {
                        Name           = kv.Key,
                        Exception      = $"{exception.Message}\t{exception.StackTrace}",
                        InnerException = exception.InnerException is null ? null : $"{exception.InnerException}\t{exception.InnerException.StackTrace}",
                        Url            = kv.Value,
                        Type           = "Booster Pack"
                    });