public Rune(string id, string firstValue, string secondValue, string thirdValue) { RuneId = id; RuneJson staticData = RuneHelper.GetRune(id); RuneName = staticData.Name; Descriptions = new List <string>(); for (int i = 0; i < staticData.EndOfGameStatDescs.Count; i++) { Descriptions.Add(RuneHelper.FillInDescriptions(staticData.EndOfGameStatDescs[i], firstValue, secondValue, thirdValue)); } Value0 = int.TryParse(firstValue, out int parsedValue0) ? parsedValue0 : 0; Value1 = int.TryParse(secondValue, out int parsedValue1) ? parsedValue1 : 0; Value2 = int.TryParse(thirdValue, out int parsedValue2) ? parsedValue2 : 0; }
public async Task LoadRuneThumbnails(ReplayDetail replay) { _log.Information("Loading/downloading thumbnails for runes..."); if (replay == null) { throw new ArgumentNullException(nameof(replay)); } string dataVersion = await RequestManager.GetLatestDataDragonVersionAsync().ConfigureAwait(true); List <Rune> allRunes = new List <Rune>(); List <Task> allTasks = new List <Task>(); allRunes.AddRange(replay.AllPlayers.Select(x => x.KeystoneRune)); allRunes.AddRange(replay.AllPlayers.SelectMany(x => x.Runes)); allRunes.AddRange(replay.AllPlayers.SelectMany(x => x.StatsRunes)); _log.Information($"Processing {allRunes.Count} rune thumbnail requests"); foreach (Rune rune in allRunes) { RuneJson runeData = RuneHelper.GetRune(rune.RuneId); // If an item does not exist, set it to nothing! if (string.IsNullOrEmpty(runeData.Icon)) { Application.Current.Dispatcher.Invoke(delegate { rune.OverlayIcon = ResourceTools.GetObjectFromResource <Geometry>("ErrorPathIcon"); }); // move on to the next rune continue; } // Set default item image, to be replaced Application.Current.Dispatcher.Invoke((Action) delegate { rune.OverlayIcon = ResourceTools.GetObjectFromResource <Geometry>("DownloadPathIcon"); }); // make requests for images allTasks.Add(Task.Run(async() => { ResponseBase response = await RequestManager.MakeRequestAsync(new RuneRequest { DataDragonVersion = dataVersion, RuneKey = runeData.Key, TargetPath = runeData.Icon }).ConfigureAwait(true); if (response.IsFaulted) { _log.Warning($"Failed to load image for {(response.Request as RuneRequest).RuneKey}"); Application.Current.Dispatcher.Invoke(delegate { rune.OverlayIcon = ResourceTools.GetObjectFromResource <Geometry>("ErrorPathIcon"); }); } else { if (response.FromCache) // load image from file { Application.Current.Dispatcher.Invoke(delegate { rune.OverlayIcon = null; // hide overlay icons, if any rune.ImageSource = ResourceTools.GetImageSourceFromPath(response.ResponsePath); }); } else // load image straight from response if its not cachsed { Application.Current.Dispatcher.Invoke(delegate { rune.OverlayIcon = null; // hide overlay icons, if any rune.ImageSource = response.ResponseBytes.ToBitmapImage(); }); } } })); } await Task.WhenAll(allTasks).ConfigureAwait(true); }