//DATA HANDLERS void UpdatePriceOfCard(string name, string set) { var price = -1f; var foilPrice = -1f; var preppedSetName = PrepareSetName(set); var url = GeneratePriceURL(name, preppedSetName); using (WebClient wc = new WebClient()) { string html = ""; JObject json = null; try { html = wc.DownloadString(url); json = JObject.Parse(html); } catch (Exception ex) { Logger.LogError("Atempting to parse HTML into JSON.", ex.ToString(), "HTML: " + html + "\r\nURL: " + url + "\r\nName" + name + "\r\nSet: " + set + "\r\nPrepped set name: " + preppedSetName); return; } try { price = json["price"].ToObject <float>(); } catch (Exception ex) { Logger.LogError("Atempting to get price for card", ex.ToString(), "Name: " + name + "\r\nSet: " + set + "\r\nSet Name: " + preppedSetName); } try { foilPrice = json["price_foil"].ToObject <float>(); } catch (Exception ex) { Logger.LogError("Atempting to get foil price for card", ex.ToString(), "Name: " + name + "\r\nSet: " + set + "\r\nSet Name: " + preppedSetName); } if (price != -1) { DatabaseManager.UpdatePrice(name, set, price, false); } if (foilPrice != -1) { DatabaseManager.UpdatePrice(name, set, foilPrice, true); } } }
void UpdateCardInSet(string set, JObject setData) { DatabaseManager.LockSet(set.Replace("'", "''")); var cardList = DatabaseManager.GetAllCardsForSet(set.Replace("'", "''")); var json = setData["prints"]; foreach (var card in json) { var id = card["id"].ToString(); var name = card["name"].ToString(); var cardObject = GetMTGStocksData(id); var cardData = ParseCardData(cardObject, set); var prices = GetPriceFromData(cardData); DatabaseManager.UpdatePrice(name, set, prices["price"], false); DatabaseManager.UpdatePrice(name, set, prices["foilPrice"], true); } Logger.LogActivity("Updated price of cards in set:" + set); DatabaseManager.UnlockSet(set.Replace("'", "''")); }