public async Task<ForumReplyEntity> GetReplyCookiesForEdit(long postId) { try { string url = string.Format(Constants.EDIT_BASE, postId); WebManager.Result result = await _webManager.GetData(url); HtmlDocument doc = result.Document; HtmlNode[] formNodes = doc.DocumentNode.Descendants("input").ToArray(); HtmlNode bookmarkNode = formNodes.FirstOrDefault(node => node.GetAttributeValue("name", "").Equals("bookmark")); HtmlNode[] textAreaNodes = doc.DocumentNode.Descendants("textarea").ToArray(); HtmlNode textNode = textAreaNodes.FirstOrDefault(node => node.GetAttributeValue("name", "").Equals("message")); var threadManager = new ThreadManager(); //Get previous posts from quote page. string url2 = string.Format(Constants.QUOTE_BASE, postId); WebManager.Result result2 = await _webManager.GetData(url2); HtmlDocument doc2 = result2.Document; var forumThreadPosts = new ObservableCollection<ForumPostEntity>(); HtmlNode threadNode = doc2.DocumentNode.Descendants("div") .FirstOrDefault(node => node.GetAttributeValue("id", string.Empty).Contains("thread")); foreach ( HtmlNode postNode in threadNode.Descendants("table") .Where(node => node.GetAttributeValue("class", string.Empty).Contains("post"))) { var post = new ForumPostEntity(); post.Parse(postNode); forumThreadPosts.Add(post); } ForumThreadEntity threadEntity = new ForumThreadEntity() { ForumPosts = forumThreadPosts }; string htmlThread = await HtmlFormater.FormatThreadHtml(threadEntity); var forumReplyEntity = new ForumReplyEntity(); try { string quote = WebUtility.HtmlDecode(textNode.InnerText); forumReplyEntity.PreviousPostsRaw = htmlThread; string bookmark = bookmarkNode.OuterHtml.Contains("checked") ? "yes" : "no"; forumReplyEntity.MapEditPostInformation(quote, postId, bookmark); return forumReplyEntity; } catch (Exception) { throw new InvalidOperationException("Could not parse newReply form data."); } } catch (Exception) { return null; } }
public async Task<ForumReplyEntity> GetReplyCookiesForEdit(long postId) { try { string url = string.Format(Constants.EDIT_BASE, postId); WebManager.Result result = await _webManager.DownloadHtml(url); HtmlDocument doc = result.Document; HtmlNode[] formNodes = doc.DocumentNode.Descendants("input").ToArray(); HtmlNode bookmarkNode = formNodes.FirstOrDefault(node => node.GetAttributeValue("name", "").Equals("bookmark")); HtmlNode[] textAreaNodes = doc.DocumentNode.Descendants("textarea").ToArray(); HtmlNode textNode = textAreaNodes.FirstOrDefault(node => node.GetAttributeValue("name", "").Equals("message")); var threadManager = new ThreadManager(); //Get previous posts from quote page. string url2 = string.Format(Constants.QUOTE_BASE, postId); WebManager.Result result2 = await _webManager.DownloadHtml(url2); HtmlDocument doc2 = result2.Document; string htmlThread = await threadManager.GetThreadHtml(doc2); var forumReplyEntity = new ForumReplyEntity(); try { string quote = WebUtility.HtmlDecode(textNode.InnerText); forumReplyEntity.PreviousPostsRaw = htmlThread; string bookmark = bookmarkNode.OuterHtml.Contains("checked") ? "yes" : "no"; forumReplyEntity.MapEditPostInformation(quote, postId, bookmark); return forumReplyEntity; } catch (Exception) { throw new InvalidOperationException("Could not parse newReply form data."); } } catch (Exception) { return null; } }