private void SetProperties(PrivateMessageMetadata metadata) { this.Title = metadata.From; this.Subtitle = metadata.Subject; this.Description = GetBodySnippet(metadata.Body); this.IsNew = metadata.Status == PrivateMessageMetadata.MessageStatus.New; this.PostDate = GetFormattedPostDate(metadata.PostDate); }
public static string Metrofy(PrivateMessageMetadata message) { if (message.Body == null) message = message.Refresh(); HtmlDocument html = new HtmlDocument(); html.LoadHtml(message.Body); HtmlNode postbody = html.DocumentNode.Descendants() .Where(node => node.GetAttributeValue("class", "").Equals("postbody")) .FirstOrDefault(); string result = new ForumContentParser(postbody.FirstChild).Body; return result; }
private DataTemplate GetGlyph(PrivateMessageMetadata metadata) { DataTemplate value = null; var status = metadata.Status; switch (status) { case PrivateMessageMetadata.MessageStatus.Forwarded: value = ForwardGlyph; break; case PrivateMessageMetadata.MessageStatus.Replied: value = ReplyGlyph; break; default: value = EmptyGlyph; break; } return(value); }
/// <summary> /// /// </summary> /// <param name="doc"></param> /// <returns></returns> public static PrivateMessageMetadata ParsePrivateMessageDocument(HtmlDocument doc) { var pm = new PrivateMessageMetadata(); var top = doc.DocumentNode; // **** PARSE BODY ***** var postBodyNode = top.Descendants("td") .Where(node => node.GetAttributeValue("class", string.Empty).Equals(NEW_MESSAGE_POSTBODY)) .SingleOrDefault(); if (postBodyNode != null) { pm.RawHtml = postBodyNode.InnerHtml; pm.RawText = postBodyNode.InnerText; } // ***** PARSE AUTHOR ***** var authorNode = top.Descendants("dt") .Where(node => node.GetAttributeValue("class", string.Empty).Equals(NEW_MESSAGE_AUTHOR)) .FirstOrDefault(); pm.From = authorNode == null ? NEW_MESSAGE_UNKNOWN_AUTHOR : authorNode.InnerText; // ***** PARSE MESSAGE ID ***** var messageIdNode = top.Descendants(NEW_MESSAGE_INPUT_TAG) .Where(node => node.GetAttributeValue("name", string.Empty).Equals(NEW_MESSAGE_PRIVATEMESSAGEID)) .FirstOrDefault(); int id = 0; if (messageIdNode != null) { string value = messageIdNode.GetAttributeValue("value", string.Empty); int.TryParse(value, out id); } pm.PrivateMessageId = id.ToString(); // ***** PARSE SUBJECT ***** var subjectNode = top.Descendants("div") .Where(node => node.GetAttributeValue("class", string.Empty).Equals("breadcrumbs")) .FirstOrDefault(); if (subjectNode != null) { string subject = subjectNode.ParseTitleFromBreadcrumbsNode(); pm.Subject = subject; } // ***** PARSE POST MARK ***** var postmarkNode = top.Descendants("td") .Where(node => node.GetAttributeValue("class", string.Empty) .Equals("postdate")) .FirstOrDefault(); if (postmarkNode != null) { string postmark = postmarkNode.InnerText; try { pm.PostDate = Convert.ToDateTime(postmark); } catch (Exception) { pm.PostDate = DateTime.Parse(postmark, System.Globalization.CultureInfo.InvariantCulture); } } return pm; }
/// <summary> /// /// </summary> /// <param name="doc"></param> /// <returns></returns> public static IList<PrivateMessageMetadata> ParseMessageList(HtmlDocument doc) { List<PrivateMessageMetadata> messages = new List<PrivateMessageMetadata>(); var top = doc.DocumentNode; var messagesNode = top.Descendants("table").FirstOrDefault(); var messageTable = messagesNode.Descendants("tr").ToArray(); // remove last element from the table messageTable[messageTable.Length - 1] = null; // remove first element from the table messageTable[0] = null; foreach (var item in messageTable) { if (item != null && string.IsNullOrEmpty(item.GetAttributeValue("class", string.Empty)) == true) { if (item.InnerText.Contains(PRIVATE_MESSAGE_EMPTY_FOLDER_TEXT)) break; var message = new PrivateMessageMetadata(); var rows = item.Descendants("td").ToArray(); var statusNode = rows[0]; message.Status = GetMessageStatusFromNode(statusNode); // thread tag var tagNode = rows.SingleOrDefault(row => row.GetAttributeValue("class", string.Empty).Contains("icon")); message.IconUri = GetMessageIconUriFromNode(tagNode); // title node has our subject and message id var titleNode = rows[2]; message.Subject = GetMessageTitleFromNode(titleNode); message.PrivateMessageId = GetMessageIDFromNode(titleNode); // author node is next <td> var authorNode = rows[3]; message.From = GetMessageAuthorFromNode(authorNode); // postmark node is next <td> var postmarkNode = rows[4]; message.PostDate = GetPostMarkFromNode(postmarkNode); messages.Add(message); } } return messages; }