示例#1
0
        private static async Task <Tuple <double?, double?> > GetRelistRowPrice(DataGridViewRow row)
        {
            try
            {
                var hashCell = relistGridView.Rows[row.Index]
                               .Cells[MarketRelistControl.ListingHiddenMarketHashNameCellIndex];
                if (hashCell?.Value == null)
                {
                    return(new Tuple <double?, double?>(-1, -1));
                }

                var priceCell = relistGridView.Rows[row.Index].Cells[MarketRelistControl.ListingPriceCellIndex];
                if (priceCell?.Value == null)
                {
                    return(new Tuple <double?, double?>(-1, -1));
                }

                var hashName = (string)hashCell.Value;
                var price    = (double)priceCell.Value;

                var item = MarketRelistControl.MyListings?[hashName + price]?.FirstOrDefault();
                if (item == null)
                {
                    return(new Tuple <double?, double?>(-1, -1));
                }

                double?currentPrice = null;
                if (isForced == false)
                {
                    var cachedCurrentPrice = CurrentPricesCache.Get(item.HashName);
                    if (cachedCurrentPrice != null)
                    {
                        currentPrice = cachedCurrentPrice.Price;
                    }
                }

                if (currentPrice == null)
                {
                    currentPrice = await CurrentSession.SteamManager.GetCurrentPrice(item.AppId, item.HashName);

                    if (currentPrice != null && currentPrice != 0)
                    {
                        CurrentPricesCache.Cache(item.HashName, currentPrice.Value);
                    }
                }

                double?averagePrice = null;
                if (isForced == false)
                {
                    var cachedCurrentPrice = AveragePricesCache.Get(item.HashName);
                    if (cachedCurrentPrice != null)
                    {
                        averagePrice = cachedCurrentPrice.Price;
                    }
                }

                if (averagePrice != null)
                {
                    return(new Tuple <double?, double?>(currentPrice, averagePrice));
                }

                averagePrice = CurrentSession.SteamManager.GetAveragePrice(
                    item.AppId,
                    item.HashName,
                    SavedSettings.Get().SettingsAveragePriceParseDays);

                if (averagePrice != null && averagePrice != 0)
                {
                    AveragePricesCache.Cache(item.HashName, averagePrice.Value);
                }

                return(new Tuple <double?, double?>(currentPrice, averagePrice));
            }
            catch (Exception ex)
            {
                Logger.Debug($"Error on parsing item price - {ex.Message}");
                return(new Tuple <double?, double?>(0, 0));
            }
        }
示例#2
0
        private static async Task <Tuple <double?, double?> > GetItemsToSaleRowPrice(DataGridViewRow row)
        {
            try
            {
                var itemsCell = ItemsToSaleGridUtils.GetGridHidenItemsListCell(itemsToSaleGrid, row.Index);
                if (itemsCell == null || itemsCell.Value == null)
                {
                    return(new Tuple <double?, double?>(-1, -1));
                }

                var item = ItemsToSaleGridUtils.GetRowItemsList(itemsToSaleGrid, row.Index).FirstOrDefault();
                if (item == null)
                {
                    return(new Tuple <double?, double?>(-1, -1));
                }

                double?currentPrice = null;
                if (isForced == false)
                {
                    var cachedCurrentPrice = CurrentPricesCache.Get(item.Description.MarketHashName);
                    if (cachedCurrentPrice != null)
                    {
                        currentPrice = cachedCurrentPrice.Price;
                    }
                }

                if (currentPrice == null)
                {
                    currentPrice = await CurrentSession.SteamManager.GetCurrentPrice(
                        item.Asset.Appid,
                        item.Description.MarketHashName);

                    if (currentPrice != null && currentPrice != 0)
                    {
                        CurrentPricesCache.Cache(item.Description.MarketHashName, currentPrice.Value);
                    }
                }

                double?averagePrice = null;
                if (isForced == false)
                {
                    var cachedCurrentPrice = AveragePricesCache.Get(item.Description.MarketHashName);
                    if (cachedCurrentPrice != null)
                    {
                        averagePrice = cachedCurrentPrice.Price;
                    }
                }

                if (averagePrice != null)
                {
                    return(new Tuple <double?, double?>(currentPrice, averagePrice));
                }

                averagePrice = CurrentSession.SteamManager.GetAveragePrice(
                    item.Asset.Appid,
                    item.Description.MarketHashName,
                    SavedSettings.Get().SettingsAveragePriceParseDays);

                if (averagePrice != null && averagePrice != 0)
                {
                    AveragePricesCache.Cache(item.Description.MarketHashName, averagePrice.Value);
                }

                return(new Tuple <double?, double?>(currentPrice, averagePrice));
            }
            catch (Exception ex)
            {
                Logger.Debug($"Error on parsing item price - {ex.Message}");
                return(new Tuple <double?, double?>(0, 0));
            }
        }