示例#1
0
 private static void SpellInfo_SaveToCache(int spellID, WowheadSpellInfo info)
 {
     lock (DBLock)
     {
         LoadAndUpdateDBFile();
         using (SQLiteCommand command = new SQLiteCommand(dbConnection))
         {
             command.CommandText =
                 "INSERT INTO spells2 (spellID, name, image) " +
                 $"VALUES ({spellID}, '{info.Name.Replace("'", "''")}', '{JsonConvert.SerializeObject(info.ImageBytes)}')";
             try
             {
                 command.ExecuteNonQuery();
             }
             catch (Exception ex)
             {
                 log.Error($"SpellInfo_SaveToCache() error: {ex.Message}\r\n{command.CommandText}");
             }
         }
     }
 }
示例#2
0
        public static WowheadSpellInfo GetSpellInfo(int spellID)
        {
            if (!SpellInfos.TryGetValue(spellID, out WowheadSpellInfo info))
            {
                if ((info = SpellInfo_GetCachedValue(spellID)) == null)
                {
                    using (WebClient webClient = new WebClient())
                    {
                        webClient.Encoding = Encoding.UTF8;
                        string xml   = webClient.DownloadString("https://" + _locale + ".wowhead.com/spell=" + spellID + "&power");
                        Regex  regex = new Regex("\"name_.+\":\"(.+)\",\"icon\":\"?(.+?)\"?,");
                        Match  match = regex.Match(xml);
                        if (match.Success)
                        {
                            info = new WowheadSpellInfo(Regex.Unescape(match.Groups[1].Value));
                            if (!string.IsNullOrWhiteSpace(match.Groups[2].Value) && match.Groups[2].Value != "null")
                            {
                                using (MemoryStream ms = new MemoryStream(webClient.DownloadData("https://wow.zamimg.com/images/wow/icons/small/" + match.Groups[2].Value + ".jpg")))
                                {
                                    info.ImageBytes = ms.ToArray();
                                }
                            }
                            else
                            {
                                info.Image = Resources.DialogError;
                            }

                            SpellInfo_SaveToCache(spellID, info);
                        }
                        else
                        {
                            info = new WowheadSpellInfo(UNKNOWN);
                            log.Info("GetSpellInfo(): regex isn't match: " + JsonConvert.SerializeObject(xml));
                        }
                    }
                }
                SpellInfos.TryAdd(spellID, info);
            }
            return(info);
        }