private async void AlertEventAsync(string uniqueName) { while (_isEventActive) { try { var cityPrices = await ApiController.GetCityItemPricesFromJsonAsync(uniqueName, null, null).ConfigureAwait(false); foreach (var marketResponse in cityPrices ?? new List <MarketResponse>()) { if (Locations.GetName(marketResponse.City) != Location.BlackMarket && marketResponse.SellPriceMinDate >= DateTime.UtcNow.AddMinutes(-5) && marketResponse.SellPriceMin <= (ulong)AlertModeMinSellPriceIsUndercutPrice && AlertModeMinSellPriceIsUndercutPrice > 0) { SoundController.PlayAlertSound(); StopEvent(); AlertController.Remove(uniqueName); _mainWindow.Dispatcher.Invoke(() => { var itemAlertWindow = new ItemAlertWindow(new AlertInfos(_item, marketResponse)); itemAlertWindow.Show(); }); break; } } await Task.Delay(25000); } catch (FileNotFoundException e) { Log.Error(nameof(AlertEventAsync), e); } catch (TooManyRequestsException e) { Log.Warn(nameof(AlertEventAsync), e); return; } } }
public static async Task <decimal> GetMarketStatAvgPriceFromJsonAsync(string uniqueName, Location location) { using (var wc = new WebClient()) { var apiString = $"https://www.albion-online-data.com/api/v1/stats/charts/" + $"{uniqueName}?date={DateTime.Now:MM-dd-yyyy}?locations={Locations.GetName(location)}"; try { var itemString = await wc.DownloadStringTaskAsync(apiString); var values = JsonConvert.DeserializeObject <List <MarketStatChartResponse> >(itemString); return(values.FirstOrDefault()?.Data.PricesAvg.FirstOrDefault() ?? 0); } catch { return(0); } } }