public static ItemPriceList Deserialize(string rawText) { ItemPriceList iPriceList = new ItemPriceList(); if (rawText != "") { string[] lines = rawText.Split("\n"); if (lines.Length > 0) { int count = 0; if (!int.TryParse(lines[0], out count)) { throw new Exception("Unable to serialize due to failure of retrieving available item count"); } foreach (string line in lines) { string[] values = line.Split('|'); if (values.Length == SUPPORTED_COLUMNS) { iPriceList.Add(new ItemPrice(values[0], int.Parse(values[1]), int.Parse(values[2]))); } } } } return(iPriceList); }
public static ItemPriceList GetItemPriceListFromUrl(string url) // retrieves the full item price list { if (iPriceList == null) // Not in cache? Rebuild then, user has to do it's own implementation to choose when to refresh items, perhaps just a resync button? { string raw = RefreshPrices(url); iPriceList = ItemPriceList.Deserialize(raw); return(iPriceList); } else if (iPriceList.GetCount() > 0) // the count shall not be zero either, however iPriceList wasn't null which it should so it's gonna throw an error. { return(iPriceList); // return immediately. } throw new Exception($"GetItemPriceListFromUrl({url}) failed for an unknown reason."); }