/// <summary> /// Gets a What If Article from an archive entry /// </summary> /// <param name="archiveEntry">Archive entry</param> /// <returns>Whar If Article</returns> public static WhatIfArticle GetArticle(WhatIfArchiveEntry archiveEntry) { WhatIfArticle article = XkcdDatabase.GetWhatIfArticle(archiveEntry.Id); if (article != null) { return(article); } var web = new HtmlWeb(); HtmlDocument doc = web.Load(archiveEntry.PermaLink); HtmlNode articleContentNode = doc.DocumentNode.Descendants().FirstOrDefault(x => x.Name == "article" && x.HasClass("entry")); article = new WhatIfArticle { Id = archiveEntry.Id, PermaLink = archiveEntry.PermaLink, Title = archiveEntry.Title, Date = archiveEntry.Date, Html = articleContentNode.OuterHtml }; XkcdDatabase.InsertOrUpdateWhatIfArticle(article); return(article); }
/// <summary> /// Gets the first What If article /// </summary> /// <returns>First What If article</returns> public static WhatIfArticle GetFirstArticle() { WhatIfArchiveEntry first = WhatIfDictionary.OrderBy(x => x.Key).FirstOrDefault().Value; return(GetArticle(first)); }
/// <summary> /// Gets the latest What If article /// </summary> /// <returns>Latest What If article</returns> public static WhatIfArticle GetLatestArticle() { WhatIfArchiveEntry latest = WhatIfDictionary.OrderByDescending(x => x.Key).FirstOrDefault().Value; return(GetArticle(latest)); }