Esempio n. 1
0
        private void downloadIds()
        {
            var sets = _repo.SetsByCode.Values.OrderByDescending(_ => _.ReleaseDate).ToArray();

            using (var stream = _priceRepository.AppendPriceIdStream())
                using (var writer = new StreamWriter(stream))
                    foreach (var set in sets)
                    {
                        Parallel.ForEach(set.Cards, new ParallelOptions {
                            MaxDegreeOfParallelism = Parallelism
                        }, card =>
                        {
                            lock (_sync)
                            {
                                if (_aborted)
                                {
                                    return;
                                }

                                if (!_priceRepository.IsDefined(card) || _priceRepository.ContainsSid(card))
                                {
                                    return;
                                }
                            }

                            var sid = _client.DownloadSid(card);
                            if (sid == null)
                            {
                                return;
                            }

                            var serialized = JsonConvert.SerializeObject(sid, Formatting.None);

                            lock (_sync)
                            {
                                _priceRepository.AddSid(card, sid);
                                SidAdded?.Invoke();
                                writer.WriteLine(serialized);
                            }
                        });
                    }
        }
Esempio n. 2
0
        private void downloadIds()
        {
            var sets = _repo.SetsByCode.Values.OrderByDescending(_ => _.ReleaseDate).ToArray();

            using (var stream = _priceRepository.AppendPriceIdStream())
                using (var writer = new StreamWriter(stream))
                    foreach (var set in sets)
                    {
                        foreach (var card in set.Cards)
                        {
                            if (_aborted)
                            {
                                return;
                            }

                            if (!_priceRepository.IsDefined(card) || _priceRepository.ContainsSid(card))
                            {
                                continue;
                            }

                            var sid = _client.DownloadSid(set.MagicCardsInfoCode, card.MciNumber);

                            if (sid == null)
                            {
                                continue;
                            }

                            _priceRepository.AddSid(card, sid);

                            SidAdded?.Invoke();

                            var serialized = JsonConvert.SerializeObject(_priceRepository.GetPriceId(card), Formatting.None);
                            writer.WriteLine(serialized);
                        }
                    }
        }