/// <summary> /// Generates random comic /// Number is determined from current comics's issue number /// </summary> /// <remarks> /// We could have stored the random comics in a cache /// </remarks> public override void GenerateRandComic() { Random rnd = new Random(); ModJSONurl = DefaultJSON.Insert(15, "/" + rnd.Next(MaxNum).ToString()); RandomComicContent = GenerateComic(ModJSONurl); }
/// <summary> /// Deserialize json information on a comic /// Place information into ComDetails /// </summary> XKCDContent GenerateComic(string originalJson) { try { using (WebClient wc = new WebClient()) { var json = wc.DownloadString(originalJson); Dictionary <string, object> deserializedComic = JsonConvert.DeserializeObject <Dictionary <string, object> > (json, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); XKCDContent result = new XKCDContent(); result.XKCDComDetails = deserializedComic; return(result); } } catch (Exception e) { Console.WriteLine(e.Message); return(new XKCDContent()); } }
/// <summary> /// Sets the current comic as the standard comic /// Also sets properties based off of it /// </summary> public override void SetBaseComic() { BaseContent = GenerateComic(DefaultJSON); MaxNum = Convert.ToInt32(BaseContent.XKCDComDetails["num"]); }