Пример #1
0
        void GetSetID(string name, string set)
        {
            var url    = MTGSTOCKS_BASE_URL + MTGSTOCKS_QUERY_ID + name;
            var cardID = "";
            Dictionary <string, int> dictionary = new Dictionary <string, int>();

            using (WebClient wc = new WebClient())
            {
                var html = wc.DownloadString(url);
                html = html.Replace("[", "");
                html = html.Replace("]", "");

                try
                {
                    var json = JObject.Parse(html);
                    cardID = json["id"].ToString();
                }
                catch (Exception ex)
                {
                    Logger.LogError("Attempting to parse card", ex.ToString(), "Name: " + name + "\r\nSet: " + set + "\r\nHTML: " + html);
                    throw new Exception();
                }
            }

            var idURL = MTGSTOCKS_BASE_URL + MTGSTOCKS_QUERY_DATA + cardID;

            using (WebClient wc = new WebClient())
            {
                var html = wc.DownloadString(idURL);

                var json = JObject.Parse(html);

                DatabaseManager.UpdateSetID(set, json["card_set"]["id"].ToObject <int>());

                foreach (var card in json["sets"])
                {
                    var setID   = card["set_id"].ToObject <int>();
                    var setName = card["set_name"].ToString();

                    try
                    {
                        DatabaseManager.UpdateSetID(setName, setID);
                        Logger.LogActivity("Added ID: " + setID + " to set: " + setName);
                    }
                    catch (Exception ex)
                    {
                        Logger.LogError("Attempting to add ID", ex.ToString(), "Set: " + setName + "\r\nID: " + setID);
                    }
                }
            }
        }