protected string SwikiTableRow( int itemNo, Entrant item) { var sb = new StringBuilder(); sb.Append($"|| {WikiUtils.ColumnOf(3, itemNo.ToString())} "); sb.Append($"|| {WikiUtils.ColumnOf(40, item.Name)} "); sb.Append($"|| {WikiUtils.ColumnOf(20, item.Balls.ToString())} "); sb.Append("||"); sb.AppendLine(); return(sb.ToString()); }
protected override async Task LoadAsync(HttpClient httpClient) { if (Directory.Exists(SavePath)) { Directory.Delete(SavePath, true); } Directory.CreateDirectory(SavePath); _httpClient = httpClient; _wikiUtils = new WikiUtils(httpClient); var jewelTask = Task.WhenAll(ItemGroup.Jewel.Types().Select(LoadJewelAsync)); await _wikiUtils.ForEachBaseItemAsync(ParseTable); await jewelTask; }
private async Task Overwrite(HttpClient httpClient) { var wikiUtils = new WikiUtils(httpClient); var gemTasks = await wikiUtils.SelectFromGemsAsync(ParseGemTable); foreach (var task in gemTasks) { var gem = await task; if (gem == null) { continue; } ItemDB.Add(gem); } }
protected string SwikiTableHeader( string itemName) { var sb = new StringBuilder(); sb.AppendLine($"=== {itemName} Contenders ==="); var tableHeader = $@"|| **#** || { WikiUtils.ColumnOf(40, "**Item**") } || { WikiUtils.ColumnOf(20, "**Weighting**" )} ||"; sb.Append(tableHeader); return(sb.ToString()); }
private static IEnumerable <XmlItemBase> ParseTable(HtmlNode table, ItemType itemType) { // Select the item box in the first cell of each (non-header) row foreach (var cell in table.SelectNodes("tr/td[1]//*[contains(@class, 'item-box')]")) { var itemBox = WikiUtils.ParseItemBox(cell); var statGroups = itemBox.StatGroups; var itemBase = new XmlItemBase { ItemType = itemType, Name = itemBox.TypeLine }; var requirementsGroup = statGroups.FirstOrDefault(stats => stats.Any(s => s.StatsCombined.StartsWith("Requires ") || s.StatsCombined.StartsWith("Drop Level: "))); var implicitsGroup = statGroups.FirstOrDefault(stats => stats.All(s => s.Stats.All(t => t.Item2 == WikiStatColor.Mod))); var propertiesGroup = statGroups[0] == requirementsGroup ? null : statGroups[0]; var implicitFrom = 1F; var implicitTo = 1F; if (implicitsGroup != null) { var implicits = new List <XmlStat>(); foreach (var wikiItemStat in implicitsGroup) { implicits.AddRange(ParseImplicit(wikiItemStat)); } if (implicits.Any()) { implicitFrom += implicits[0].From / 100; implicitTo += implicits[0].To / 100; } itemBase.Implicit = implicits.ToArray(); } if (propertiesGroup != null) { itemBase.Properties = ParseProperties(propertiesGroup, implicitFrom, implicitTo).ToArray(); } if (requirementsGroup != null) { ParseRequirements(requirementsGroup, itemBase); } yield return(itemBase); } }
private async Task <ImageSource> LoadFromWiki() { using (var client = new HttpClient()) { var wikiUtils = new WikiUtils(client); var imgTuple = await wikiUtils.LoadItemBoxImageAsync(_baseName).ConfigureAwait(false); var imgData = await client.GetByteArrayAsync(imgTuple).ConfigureAwait(false); var fileName = string.Format(AssetPathFormat, _baseName); CreateDirectories(fileName); using (var ms = new MemoryStream(imgData)) using (var image = Image.FromStream(ms)) using (var outputStream = File.Create(fileName, 65536, FileOptions.Asynchronous)) { var resized = image.Resize((int)(image.Width * WikiUtils.ItemImageResizeFactor), (int)(image.Height * WikiUtils.ItemImageResizeFactor)); resized.Save(outputStream, ImageFormat.Png); } Log.InfoFormat("Downloaded base item image for {0} to the file system.", _baseName); return(ImageSourceFromPath(fileName)); } }
private static IEnumerable <Attribute> ParseInfobox(HtmlDocument doc, string name, ICollection <string> tags) { var found = doc.DocumentNode.SelectNodes("//span[contains(@class,'item-box -gem')]"); if (found == null || found.Count == 0) { Log.Warn($"Gem infobox table not found for {name}"); yield break; } var itemBox = WikiUtils.ParseItemBox(found[0]); var statGroups = itemBox.StatGroups; if (!statGroups.Any()) { Log.Warn($"Gem infobox table for {name} is empty"); yield break; } // Some attributes are both in first and fixed group. Don't allow such duplicates. var fixedAttrNames = new HashSet <string>(); // Attributes in first group (property group) foreach (var wikiItemStat in statGroups[0]) { var stats = wikiItemStat.Stats; if (stats.Length != 2 || stats[0].Item2 != WikiStatColor.Default || stats[1].Item2 != WikiStatColor.Value) { continue; } var attr = ParseSingleValueAttribute(wikiItemStat.StatsCombined); if (attr == null) { continue; } if (fixedAttrNames.Add(attr.Name)) { yield return(attr); } } // Tags if (statGroups[0].Any()) { var tagStat = statGroups[0][0]; if (tagStat.Stats.Length == 1) { tagStat.StatsCombined.Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries).ForEach(tags.Add); } } // Per 1% Quality var qualityGroupIndex = -1; for (var i = 0; i < statGroups.Length; i++) { if (statGroups[i].Any() && statGroups[i].First().StatsCombined.Contains("Per 1% Quality:")) { qualityGroupIndex = i; break; } } if (qualityGroupIndex < 0) { yield break; } var texts = statGroups[qualityGroupIndex].Skip(1).Select(s => s.StatsCombined); foreach (var token in ParseTokens(texts)) { if (token.Value != null) { yield return(new Attribute { Name = token.Name, Values = new List <Value> { new ValuePerQuality { Text = token.Value } } }); } } // Values fixed per level var fixedGroupIndex = qualityGroupIndex + 1; if (fixedGroupIndex < 1 || fixedGroupIndex >= statGroups.Length) { yield break; } var attrs = statGroups[fixedGroupIndex] .Select(s => s.StatsCombined) .Select(ParseSingleValueAttribute) .Where(a => a != null); foreach (var attr in attrs) { if (fixedAttrNames.Add(attr.Name)) { yield return(attr); } } }
private async Task Overwrite(HttpClient httpClient) { var wikiUtils = new WikiUtils(httpClient); var gemTasks = await wikiUtils.SelectFromGemsAsync(ParseGemTable); foreach (var task in gemTasks) { var gem = await task; if (gem == null) continue; ItemDB.Add(gem); } }
private async Task<ImageSource> LoadFromWiki() { using (var client = new HttpClient()) { var wikiUtils = new WikiUtils(client); var imgTuple = await wikiUtils.LoadItemBoxImageAsync(_baseName).ConfigureAwait(false); var imgData = await client.GetByteArrayAsync(imgTuple).ConfigureAwait(false); var fileName = string.Format(AssetPathFormat, _baseName); CreateDirectories(fileName); using (var ms = new MemoryStream(imgData)) using (var image = Image.FromStream(ms)) using (var outputStream = File.Create(fileName, 65536, FileOptions.Asynchronous)) { var resized = image.Resize((int)(image.Width * WikiUtils.ItemImageResizeFactor), (int)(image.Height * WikiUtils.ItemImageResizeFactor)); resized.Save(outputStream, ImageFormat.Png); } Log.InfoFormat("Downloaded base item image for {0} to the file system.", _baseName); return ImageSourceFromPath(fileName); } }