Exemple #1
0
        public void PriceSearchResult()
        {
            var searchResult = _searchResult;

            if (searchResult == null || !searchResult.Any())
            {
                return;
            }

            searchResult = searchResult
                           .DistinctBy(c => c.NameEN)
                           .Where(c => c.CardPrice == null || !c.CardPrice.IsPriceUpToDate())
                           .OrderBy(c => !c.CardPrice.CheapestPrice.HasValue)
                           .ThenByDescending(c => c.CardPrice.CheapestPrice)
                           .ToList();

            _notificationCenter.FireNotification(
                LogLevel.Info,
                string.Format("Starting price lookup for {0} cards", searchResult.Count()));

            Task.Factory.StartNew(() =>
            {
                var count     = searchResult.Count();
                var index     = 0;
                var stopwatch = Stopwatch.StartNew();
                foreach (var card in searchResult)
                {
                    ++index;
                    card.UpdatePriceData(false, false, " (card " + index + " of " + count + ")", false);

                    if (index % 30 == 0)
                    {
                        StaticPriceDatabase.Write();

                        ////var seconds = 30;
                        ////_notificationCenter.FireNotification(
                        ////	LogLevel.Debug,
                        ////	string.Format("Waiting {0} seconds to avoid being locked out by MKM", seconds));

                        ////// Wait a bit between requests
                        ////Thread.Sleep(seconds * 1000);
                    }
                }

                StaticPriceDatabase.Write();

                stopwatch.Stop();

                _notificationCenter.FireNotification(
                    LogLevel.Info,
                    string.Format("Price lookup for {0} cards took {1}", searchResult.Count(), stopwatch.Elapsed));
            });
        }
Exemple #2
0
        public void PriceBinder()
        {
            Task.Factory.StartNew(() =>
            {
                var stopwatch = Stopwatch.StartNew();

                _notificationCenter.FireNotification(LogLevel.Info, "Starting price current binder...");

                var cards = _cards.DistinctBy(c => c.CardId).ToList();

                var request = new CardPriceRequest(_notificationCenter);
                request.PerformRequest(cards);
                StaticPriceDatabase.Write();
                CalculateTotals();

                stopwatch.Stop();
                _notificationCenter.FireNotification(LogLevel.Info, string.Format("Done price current binder ({0}).", stopwatch.Elapsed));
            });
        }