private async Task <PrivateMessage> ParseMessage(string result) { var document = await new HtmlParser().ParseAsync(result); var privateMessage = new PrivateMessage(); var postCheck = document.QuerySelector("div[id='post']"); if (postCheck != null) { var titleCheck = postCheck.QuerySelector("div div strong"); if (titleCheck != null) { privateMessage.Title = WebUtility.HtmlDecode(titleCheck.TextContent.FixaRadbrytningar()); } var messageCheck = postCheck.QuerySelector("div[class='post_message']"); if (messageCheck != null) { var messageData = messageCheck.InnerHtml; if (_options.RenderEmoticons) { messageData = _options.ReplaceSmileys(messageData); } messageData = messageData.FixLeaveLink(); privateMessage.Message = _options.GetHtmlHeaders() + messageData + _options.GetHtmlFooter(); } var tokenCheck = document.QuerySelector("input[name='csrftoken']"); if (tokenCheck != null) { privateMessage.Token = tokenCheck.Attributes["value"].Value; } var folderIdCheck = document.QuerySelector("input[name='folderid']"); if (folderIdCheck != null) { privateMessage.FolderId = folderIdCheck.Attributes["value"].Value; } } return(privateMessage); }
/// <summary> /// Bygger upp html för enbart alla inlägg i en tråd /// </summary> /// <param name="poster"></param> /// <param name="userLoggedIn">Om vi ska rendera ut saker som enbart gäller för inloggade användare</param> /// <returns></returns> private string BuildHtmlForForumThreads(IHtmlCollection <IElement> poster, bool userLoggedIn) { if (poster == null) { return(""); } StringBuilder sb = new StringBuilder(); foreach (var post in poster) { var userNameCheck = post.QuerySelector("a.post-user-username"); string userName = ""; if (userNameCheck != null) { userName = userNameCheck.TextContent.FixaRadbrytningar(); } var userOnlineCheck = post.QuerySelector("div.post-user-title i[title='online']"); string onlinestatus; if (userOnlineCheck != null) { onlinestatus = "<span style=\"color:rgb(92, 140, 111);font-size:50%\">■ </span>"; } else { onlinestatus = "<span style=\"color:rgb(213, 89, 89);font-size:50%\">■ </span>"; } userName = onlinestatus + userName; var avatarCheck = post.QuerySelector("a.post-user-avatar img"); string avatar = ""; if (avatarCheck != null && _options.ShowAvatars) { avatar = "<img src=\"" + avatarCheck.Attributes["src"].Value + "\" class=\"avatar\" OnError=\"this.style.display = 'none'\">"; } var postDateCheck = post.QuerySelector("div.post-heading"); var postLink = ""; if (postDateCheck != null) { userName += " - " + postDateCheck.TextContent.FixaRadbrytningar(); var anchorCheck = postDateCheck.QuerySelector("a.jumptarget"); if (anchorCheck != null) { postLink = anchorCheck.Attributes["name"].Value; } } var postMessageCheck = post.QuerySelector("div.post_message"); string postMessage; if (postMessageCheck != null) { postMessage = postMessageCheck.InnerHtml; if (_options.ShowSignatures) { var signatureCheck = post.QuerySelector("div.signature"); if (signatureCheck != null) { postMessage = postMessage + "<br><small><div class=\"signature\">" + signatureCheck.InnerHtml + "</small></div>"; } } var titleCheck = post.QuerySelector("div.smallfont"); string postTitle = ""; if (titleCheck != null) { postTitle = titleCheck.InnerHtml + "<br>"; } postMessage = postTitle + postMessage.FixLeaveLink(); } else { continue; } if (_options.RenderEmoticons) { postMessage = _options.ReplaceSmileys(postMessage); } sb.AppendLine("<a id=\"" + postLink + "\" href=\"#" + postLink + "\"></a>"); sb.AppendLine("<p>"); sb.AppendLine(avatar); sb.AppendLine("<strong>"); sb.AppendLine(userName); sb.AppendLine("</strong>"); if (userLoggedIn) { sb.AppendLine("<span style=\"align='right'\"><input type=\"button\" onclick=\"prepareQuote('" + postLink.Replace("p", "post") + "')\" value=\"Citera\" /></span>"); } sb.AppendLine("</p>"); sb.AppendLine(postMessage); sb.AppendLine("<hr noshade>"); sb.AppendLine("<br>"); } return(sb.ToString()); }