public async Task OnInit() { if (Definitions != null && Definitions.Count > 0) { return; } try { logger.Information($"Pseudo stat service initialization started."); var result = await poeApiClient.Fetch <StatDataCategory>(useDefaultLanguage : true); logger.Information($"{result.Count} attributes fetched."); var groups = InitGroups(result); foreach (var category in result) { var first = category.Entries.FirstOrDefault(); if (first == null || first.Id.Split('.').First() == "pseudo") { continue; } foreach (var entry in category.Entries) { foreach (var group in groups) { if (group.Exception != null && group.Exception.IsMatch(entry.Text)) { continue; } foreach (var pattern in group.Patterns) { if (pattern.Pattern.IsMatch(entry.Text)) { pattern.Matches.Add(new PseudoPatternMatch(entry.Id, entry.Type, entry.Text)); } } } } } foreach (var group in groups) { var definition = new PseudoDefinition(group.Id, group.Text); foreach (var pattern in group.Patterns) { PseudoDefinitionModifier modifier = null; foreach (var match in pattern.Matches.OrderBy(x => x.Type).ThenBy(x => x.Text.Length)) { if (modifier != null) { if (modifier.Type != match.Type) { modifier = null; } else if (!match.Text.StartsWith(modifier.Text)) { modifier = null; } } if (modifier == null) { modifier = new PseudoDefinitionModifier(match.Type, match.Text, pattern.Multiplier); } modifier.Ids.Add(match.Id); if (!definition.Modifiers.Contains(modifier)) { definition.Modifiers.Add(modifier); } } } Definitions.Add(definition); } } catch (Exception) { logger.Information($"Could not initialize pseudo service."); throw; } }
public async Task OnInit() { if (Definitions != null && Definitions.Count > 0) { return; } try { logger.Information($"Pseudo stat service initialization started."); var response = await client.GetAsync("https://www.pathofexile.com/api/trade/data/stats/"); var content = await response.Content.ReadAsStreamAsync(); var result = await JsonSerializer.DeserializeAsync <FetchResult <StatDataCategory> >(content, poeApiClient.Options); logger.Information($"{result.Result.Count} attributes fetched."); var groups = InitGroups(result.Result); foreach (var category in result.Result) { var first = category.Entries.FirstOrDefault(); if (first == null || first.Id.Split('.').First() == "pseudo") { continue; } foreach (var entry in category.Entries) { foreach (var group in groups) { if (group.Exception != null && group.Exception.IsMatch(entry.Text)) { continue; } foreach (var pattern in group.Patterns) { if (pattern.Pattern.IsMatch(entry.Text)) { pattern.Matches.Add(new PseudoPatternMatch(entry.Id, entry.Type, entry.Text)); } } } } } foreach (var group in groups) { var definition = new PseudoDefinition(group.Id, group.Text); foreach (var pattern in group.Patterns) { PseudoDefinitionModifier modifier = null; foreach (var match in pattern.Matches.OrderBy(x => x.Type).ThenBy(x => x.Text.Length)) { if (modifier != null) { if (modifier.Type != match.Type) { modifier = null; } else if (!match.Text.StartsWith(modifier.Text)) { modifier = null; } } if (modifier == null) { modifier = new PseudoDefinitionModifier(match.Type, match.Text, pattern.Multiplier); } modifier.Ids.Add(match.Id); if (!definition.Modifiers.Contains(modifier)) { definition.Modifiers.Add(modifier); } } } Definitions.Add(definition); } } catch (Exception) { logger.Information($"Could not initialize pseudo service."); throw; } }