Пример #1
0
        public async Task LoadItemThumbnails(ReplayDetail replay)
        {
            _log.Information("Loading/downloading thumbnails for items...");
            if (replay == null)
            {
                throw new ArgumentNullException(nameof(replay));
            }

            var dataVersion = await RequestManager.GetLatestDataDragonVersionAsync().ConfigureAwait(true);

            var allItems  = new List <Item>();
            var itemTasks = new List <Task>();

            allItems.AddRange(replay.BluePlayers.SelectMany(x => x.Items));
            allItems.AddRange(replay.RedPlayers.SelectMany(x => x.Items));

            _log.Information($"Processing {allItems.Count} item thumbnail requests");
            foreach (var item in allItems)
            {
                // If an item does not exist, set it to nothing!
                if (item.ItemId == "0")
                {
                    Application.Current.Dispatcher.Invoke((Action) delegate
                    {
                        item.ShowBorder = true;
                    });
                    continue;
                }

                // Set default item image, to be replaced
                Application.Current.Dispatcher.Invoke((Action) delegate
                {
                    item.OverlayIcon = ResourceTools.GetObjectFromResource <Geometry>("DownloadPathIcon");
                });

                itemTasks.Add(Task.Run(async() =>
                {
                    var response = await RequestManager.MakeRequestAsync(new ItemRequest
                    {
                        DataDragonVersion = dataVersion,
                        ItemID            = item.ItemId
                    }).ConfigureAwait(true);

                    if (response.IsFaulted)
                    {
                        _log.Warning($"Failed to load image for {(response.Request as ItemRequest).ItemID}");
                        Application.Current.Dispatcher.Invoke((Action) delegate
                        {
                            item.OverlayIcon = ResourceTools.GetObjectFromResource <Geometry>("ErrorPathIcon");
                        });
                    }
                    else
                    {
                        if (response.FromCache)
                        {
                            Application.Current.Dispatcher.Invoke((Action) delegate
                            {
                                item.OverlayIcon = null; // hide overlay icons, if any
                                item.ImageSource = ResourceTools.GetImageSourceFromPath(response.ResponsePath);
                            });
                        }
                        else
                        {
                            Application.Current.Dispatcher.Invoke((Action) delegate
                            {
                                item.OverlayIcon = null; // hide overlay icons, if any
                                item.ImageSource = response.ResponseBytes.ToBitmapImage();
                            });
                        }
                    }
                }));
            }

            await Task.WhenAll(itemTasks).ConfigureAwait(true);
        }
Пример #2
0
        public async Task LoadSinglePreviewPlayerThumbnails(ReplayPreview replay)
        {
            if (replay == null)
            {
                throw new ArgumentNullException(nameof(replay));
            }

            var dataVersion = await RequestManager.GetLatestDataDragonVersionAsync().ConfigureAwait(true);

            var allPlayers = new List <PlayerPreview>();

            allPlayers.AddRange(replay.BluePreviewPlayers);
            allPlayers.AddRange(replay.RedPreviewPlayers);

            _log.Information($"Processing {allPlayers.Count} champion thumbnail requests");
            var allRequests = new List <dynamic>(allPlayers.Select(x =>
                                                                   new
            {
                Player  = x,
                Request = new ChampionRequest()
                {
                    ChampionName      = x.ChampionName,
                    DataDragonVersion = dataVersion
                }
            }));

            var allTasks = new List <Task>();

            foreach (var request in allRequests)
            {
                Application.Current.Dispatcher.Invoke((Action) delegate
                {
                    request.Player.OverlayIcon = ResourceTools.GetObjectFromResource <Geometry>("DownloadPathIcon");
                });

                allTasks.Add(Task.Run(async() =>
                {
                    var response = await RequestManager.MakeRequestAsync(request.Request as RequestBase)
                                   .ConfigureAwait(true);

                    if (response.IsFaulted)
                    {
                        _log.Warning($"Failed to load image for {(response.Request as ChampionRequest).ChampionName}");
                        Application.Current.Dispatcher.Invoke((Action) delegate
                        {
                            request.Player.OverlayIcon = ResourceTools.GetObjectFromResource <Geometry>("ErrorPathIcon");
                        });
                    }

                    if (response.FromCache)
                    {
                        Application.Current.Dispatcher.Invoke((Action) delegate
                        {
                            request.Player.OverlayIcon = null; // hide overlay icons, if any
                            request.Player.ImageSource = ResourceTools.GetImageSourceFromPath(response.ResponsePath);
                        });
                    }
                    else
                    {
                        Application.Current.Dispatcher.Invoke((Action) delegate
                        {
                            request.Player.OverlayIcon = null; // hide overlay icons, if any
                            request.Player.ImageSource = response.ResponseBytes.ToBitmapImage();
                        });
                    }
                }));
            }

            await Task.WhenAll(allTasks).ConfigureAwait(true);
        }
Пример #3
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);
        }