private static void ItemInfo_SaveToCache(uint itemID, WowheadItemInfo info) { lock (DBLock) { LoadAndUpdateDBFile(); using (SQLiteCommand command = new SQLiteCommand(dbConnection)) { command.CommandText = "INSERT INTO items2 (itemID, name, class, level, quality, image) " + $"VALUES ({itemID}, '{info.Name.Replace("'", "''")}', {info.Class}, {info.Level}, {info.Quality}, '{JsonConvert.SerializeObject(info.ImageBytes)}')"; try { command.ExecuteNonQuery(); } catch (Exception ex) { log.Error($"ItemInfo_SaveToCache() error: {ex.Message}\r\n{command.CommandText}"); } } } }
public static WowheadItemInfo GetItemInfo(uint itemID) { // <name><![CDATA[Iceblade Arrow]]></name> // <class id="1"><![CDATA[Контейнеры]]></class> // <level>85</level> // <quality id="1">Обычный</quality> // "inv_misc_questionmark" if (!ItemInfos.TryGetValue(itemID, out WowheadItemInfo info)) { if ((info = ItemInfo_GetCachedValue(itemID)) == null) { using (WebClient webClient = new WebClient()) { webClient.Encoding = Encoding.UTF8; string xml = webClient.DownloadString("https://" + _locale + ".wowhead.com/item=" + itemID + "&xml"); Regex regex = new Regex("<name><!\\[CDATA\\[(.+)\\]\\]></name>.*<level>(\\d+)</level>.*<quality id=\"(\\d+)\">.*</quality>.*<class id=\"(\\d+)\">.*<icon.*>(.+)</icon>"); Match match = regex.Match(xml); if (match.Success) { info = new WowheadItemInfo(Regex.Unescape(match.Groups[1].Value), uint.Parse(match.Groups[4].Value), uint.Parse(match.Groups[2].Value), uint.Parse(match.Groups[3].Value)); using (MemoryStream ms = new MemoryStream(webClient.DownloadData("https://wow.zamimg.com/images/wow/icons/small/" + match.Groups[5].Value + ".jpg"))) { info.ImageBytes = ms.ToArray(); } ItemInfo_SaveToCache(itemID, info); } else { info = new WowheadItemInfo(UNKNOWN, 0, 0, 0); log.Info("GetItemInfo(): regex isn't match: " + JsonConvert.SerializeObject(xml)); } } } ItemInfos.TryAdd(itemID, info); } return(info); }