private static void RefreshSingleModelPriceRealization( SteamItemsModel item, MarketSellStrategy sellStrategy = null) { var task = Task.Run( () => { if (item == null) { return; } try { item.CleanItemPrices(); var averagePriceDays = SettingsProvider.GetInstance().AveragePriceDays; var price = UiGlobalVariables.SteamManager.GetCurrentPrice( item.ItemModel.Asset.Appid, item.ItemModel.Description.MarketHashName); Logger.Log.Debug($"Current price for {item.ItemName} is - {price}"); item.CurrentPrice = price; price = UiGlobalVariables.SteamManager.GetAveragePrice( item.ItemModel.Asset.Appid, item.ItemModel.Description.MarketHashName, averagePriceDays); Logger.Log.Debug( $"Average price for {averagePriceDays} days for {item.ItemName} is - {price}"); item.AveragePrice = price; if (sellStrategy != null) { ((MarketSellModel)item).ProcessSellPrice(sellStrategy); } } catch (Exception ex) { ErrorNotify.CriticalMessageBox("Error on item price update", ex); } }); PriceLoadSubTasks.Add(task); }
private static void ProcessPriceLoadingTaskRealization( IEnumerable <SteamItemsModel> itemsList, MarketSellStrategy sellStrategy = null) { if (priceLoadingTask?.IsCompleted == false) { ErrorNotify.InfoMessageBox("Price loading is already in progress"); return; } cancellationTokenSource = new CancellationTokenSource(); priceLoadingTask = Task.Run( () => { try { Logger.Log.Debug("Starting price loading task"); var items = itemsList.ToList(); items.ForEach(i => i.CleanItemPrices()); var averagePriceDays = SettingsProvider.GetInstance().AveragePriceDays; var priceLoadingSemaphore = new Semaphore( SettingsProvider.GetInstance().PriceLoadingThreads, SettingsProvider.GetInstance().PriceLoadingThreads); foreach (var item in items) { priceLoadingSemaphore.WaitOne(); Logger.Log.Debug($"Processing price for {item.ItemName}"); var task = Task.Run( () => { var price = UiGlobalVariables.SteamManager.GetCurrentPriceWithCache( item.ItemModel.Asset.Appid, item.ItemModel.Description.MarketHashName); Logger.Log.Debug($"Current price for {item.ItemName} is - {price}"); item.CurrentPrice = price; if (sellStrategy != null) { ((MarketSellModel)item).ProcessSellPrice(sellStrategy); } priceLoadingSemaphore.Release(); }, cancellationTokenSource.Token); PriceLoadSubTasks.Add(task); priceLoadingSemaphore.WaitOne(); task = Task.Run( () => { var price = UiGlobalVariables.SteamManager.GetAveragePriceWithCache( item.ItemModel.Asset.Appid, item.ItemModel.Description.MarketHashName, averagePriceDays); Logger.Log.Debug( $"Average price for {averagePriceDays} days for {item.ItemName} is - {price}"); item.AveragePrice = price; if (sellStrategy != null) { ((MarketSellModel)item).ProcessSellPrice(sellStrategy); } priceLoadingSemaphore.Release(); }, cancellationTokenSource.Token); PriceLoadSubTasks.Add(task); if (cancellationTokenSource.Token.IsCancellationRequested) { WaitForPriceLoadingSubTasksEnd(); Logger.Log.Debug("Market sell price loading was force stopped"); return; } } WaitForPriceLoadingSubTasksEnd(); Logger.Log.Debug("Market sell price loading task is finished"); } catch (Exception ex) { ErrorNotify.CriticalMessageBox("Error on items price update", ex); } }, cancellationTokenSource.Token); }
public static void StartPriceLoading(IEnumerable <MarketSellModel> itemsList, MarketSellStrategy sellStrategy) => ProcessPriceLoadingTaskRealization(itemsList, sellStrategy);
public static void RefreshSingleModelPrice(MarketSellModel items, MarketSellStrategy sellStrategy) => RefreshSingleModelPriceRealization(items, sellStrategy);
protected bool Equals(MarketSellStrategy other) { return(this.SaleType == other.SaleType && this.ChangeValue.Equals(other.ChangeValue)); }