Ejemplo n.º 1
0
        private void AddAndSaveExchangeHistory(ExchangeHistory exchangeHistory, ExchangeHistory.ItemData itemData)
        {
            lock (LockObject)
            {
                exchangeHistory.Items.Add(itemData);

                exchangeHistory.LastFetchDateTimeUtc = DateTime.UtcNow;

                if (string.IsNullOrEmpty(exchangeHistory.Id))
                {
                    return;
                }

                if (Stopwatch.ElapsedMilliseconds >= SaveEveryMilliSeconds)
                {
                    Debug.WriteLine("Saved at " + DateTime.UtcNow + " UTC");

                    DocumentSession.SaveChanges();

                    Stopwatch.Restart();
                }
            }
        }
Ejemplo n.º 2
0
        private async Task FillAndEmptyFetchQueuesAsync(ExchangeHistory exchangeHistory)
        {
            PoeNinjaDataService.CurrencyType currencyType;
            PoeNinjaDataService.ItemType     itemType;
            IdCurrencyTypePair idCurrencyTypePair;
            IdItemTypePair     idItemTypePair;

            while (FetchCurrencyQueue.TryDequeue(out currencyType))
            {
                Debug.WriteLine("Thread: " + Thread.CurrentThread.ManagedThreadId + " fetched currency type: " + currencyType);

                var currencyJsonResponse = await PoeNinjaDataService.FetchCurrencyJsonResponseAsync(currencyType);

                foreach (var details in currencyJsonResponse.CurrencyDetails)
                {
                    FetchCurrencyHistoryQueue.Enqueue(new IdCurrencyTypePair {
                        Id = details.Id, Name = details.Name, CurrencyType = currencyType
                    });
                }

                Thread.Sleep(10);
            }

            while (FetchItemQueue.TryDequeue(out itemType))
            {
                Debug.WriteLine("Thread: " + Thread.CurrentThread.ManagedThreadId + " fetched item type: " + itemType);

                var itemJsonResponse = await PoeNinjaDataService.FetchItemJsonResponseAsync(itemType);

                foreach (var line in itemJsonResponse.Lines)
                {
                    FetchItemHistoryQueue.Enqueue(new IdItemTypePair {
                        Id = line.Id, Name = line.Name, ItemType = itemType
                    });
                }

                Thread.Sleep(10);
            }

            while (FetchCurrencyHistoryQueue.TryDequeue(out idCurrencyTypePair))
            {
                Debug.WriteLine("Thread: " + Thread.CurrentThread.ManagedThreadId + " fetched currency id: " + idCurrencyTypePair.Id);

                var currencyHistoryJsonResponse = await PoeNinjaDataService.FetchCurrencyHistoryJsonResponseAsync(idCurrencyTypePair.CurrencyType, idCurrencyTypePair.Id);

                // can be null for certain currency items like Chaos Orb
                if (currencyHistoryJsonResponse != null)
                {
                    var item = new ExchangeHistory.ItemData
                    {
                        Type       = idCurrencyTypePair.CurrencyType.Name(),
                        Name       = idCurrencyTypePair.Name,
                        PoeNinjaId = idCurrencyTypePair.Id,
                    };

                    item.ChaosValuePerDay.AddRange(currencyHistoryJsonResponse.ReceiveCurrencyGraphData.Select(o => o.Value));

                    AddAndSaveExchangeHistory(exchangeHistory, item);
                }

                Thread.Sleep(10);
            }

            while (FetchItemHistoryQueue.TryDequeue(out idItemTypePair))
            {
                Debug.WriteLine("Thread: " + Thread.CurrentThread.ManagedThreadId + " fetched item id: " + idItemTypePair.Id);

                var itemHistoryJsonResponse = await PoeNinjaDataService.FetchItemHistoryJsonResponseAsync(idItemTypePair.ItemType, idItemTypePair.Id);

                // can be null for certain currency items like Chaos Orb
                if (itemHistoryJsonResponse != null)
                {
                    var item = new ExchangeHistory.ItemData
                    {
                        Type       = idItemTypePair.ItemType.Name(),
                        Name       = idItemTypePair.Name,
                        PoeNinjaId = idItemTypePair.Id,
                    };

                    item.ChaosValuePerDay.AddRange(itemHistoryJsonResponse.Select(o => o.Value));

                    AddAndSaveExchangeHistory(exchangeHistory, item);
                }

                Thread.Sleep(10);
            }
        }