private async Task LoadCache() { Progress.IsIndeterminate = false; Progress.Value = 0; Status.Text = Text.Loading; Cancel.Visibility = Visibility.Hidden; Hint.Visibility = Visibility.Visible; WebCache.Init(); if (WebCache.CacheGameVersion != await Riot.GetLatestVersionAsync() || WebCache.CacheLocale != CultureInfo.CurrentCulture.Name) { LogTo.Info("Clearing web cache due to a new LoL version being available, or a language change"); WebCache.Clear(); WebCache.CacheGameVersion = await Riot.GetLatestVersionAsync(); WebCache.CacheLocale = CultureInfo.CurrentCulture.Name; } Riot.SetLanguage(Config.Current.Culture); await Riot.CacheAllAsync(o => Dispatcher.Invoke(() => Progress.Value = o * 0.7)); await TeamGuesser.Load(new Progress <float>(o => Dispatcher.Invoke(() => Progress.Value = 0.7 + (o * 0.3)))); }
public async Task Load(IProgress <float> progress) { if (!File.Exists("guesser_data.json")) { var ugg = new UGGProvider(); var version = await Riot.GetLatestVersionAsync(); var data = JObject.Parse(await WebCache.String($"http://ddragon.leagueoflegends.com/cdn/{version}/data/en_US/champion.json")); var champions = data["data"].ToObject <Dictionary <string, TeamChampion> >(); var ev = new AsyncCountdownEvent(8); int champCount = 0; int totalChamps = champions.Count; foreach (var champs in Partitioner.Create(champions.Values).GetPartitions(8)) { new Thread(async() => { while (champs.MoveNext()) { var champ = champs.Current; var roles = (await ugg.GetDeepRoles(champ.ID)).ToArray(); Console.WriteLine($"{champ.Name}: {string.Join(", ", roles)}"); ChampionPositions[champ.ID] = roles; progress?.Report((float)champCount / totalChamps); } ev.Signal(); }).Start(); } await ev.WaitAsync(); ugg = null; GC.Collect(); File.WriteAllText("guesser_data.json", JsonConvert.SerializeObject(ChampionPositions)); } else { ChampionPositions = JsonConvert.DeserializeObject <Dictionary <int, PositionData[]> >(File.ReadAllText("guesser_data.json")); } }