private static void SetHolidayShareItem(Entry model) { string title = "Today is " + model.Year; string description = title + ReformatDescriptionForHolidays(model.Description); App.ShareViewModel = new ShareModel { Title = title, Description = description, Link = model.Link }; }
private static void SetEventShareItem(Entry model) { string title = "On this day in " + model.Year; string description = title + ": " + model.Description; App.ShareViewModel = new ShareModel { Title = title, Description = description, Link = model.Link }; }
private static string ExtractFirstLink(HtmlNode node, Entry entry) { // assumption - there is always one link besides a year int value; string firstLink = entry.Links.FirstOrDefault(e => !Int32.TryParse(e.Key, out value) && e.Key != "share...").Value; HtmlNode firstBoldItem = node.Descendants("b").FirstOrDefault(); if (firstBoldItem != null) { var first = firstBoldItem.Descendants("a").FirstOrDefault(); if (first != null) { firstLink = first.Attributes["href"].Value; } } return firstLink; }
private static Entry ExtractHolidayFromNode(HtmlNode node) { var entry = new Entry(); entry.Links = ExtractAllLinksFromHtmlNode(node); entry.Link = ExtractFirstLink(node, entry); // put sublists into a description if (node.HasChildNodes) { // TODO: redo this as node parsing HtmlNode extraListNode = node.Descendants("ul").FirstOrDefault(); if (extraListNode != null) { entry.Description = HttpUtility.HtmlDecode(extraListNode.InnerText).Trim(); node.RemoveChild(extraListNode); } } entry.Year = HttpUtility.HtmlDecode(node.InnerText.Trim().TrimEnd(':')); return entry; }
private static Entry ExtractEntryFromNode(HtmlNode node) { try { Entry entry = new Entry(); string innerText = HttpUtility.HtmlDecode(node.InnerText); // assumption - there is always a space around the separator // otherwise some string truncation will occur int splitIndex = innerText.IndexOfAny(new[] { '–', '-', '—' }); string secondPart = innerText.Substring(splitIndex + 1); string firstPart = innerText.Substring(0, splitIndex); entry.Year = firstPart.Trim(); entry.Description = secondPart.Trim(); entry.Links = ExtractAllLinksFromHtmlNode(node); entry.Link = ExtractFirstLink(node, entry); return entry; } catch (Exception) { return null; } }