private async Task FormatPmHtml(ForumPostEntity postEntity) { var list = new List <ForumPostEntity> { postEntity }; var thread = new ForumThreadEntity() { IsPrivateMessage = true }; #if WINDOWS_PHONE_APP thread.PlatformIdentifier = PlatformIdentifier.WindowsPhone; #else thread.PlatformIdentifier = PlatformIdentifier.Windows8; #endif Html = await HtmlFormater.FormatThreadHtml(thread, list); }
public async Task GetForumPosts(ForumThreadEntity forumThreadEntity) { IsLoading = true; bool isSuccess; string errorMessage = string.Empty; ThreadTitle = forumThreadEntity.Name; PostManager postManager = new PostManager(); try { await postManager.GetThreadPosts(forumThreadEntity); isSuccess = true; } catch (Exception ex) { IsLoading = false; isSuccess = false; errorMessage = ex.Message; } if (!isSuccess) { await AwfulDebugger.SendMessageDialogAsync("Failed to get thread posts.", new Exception(errorMessage)); return; } #if WINDOWS_PHONE_APP forumThreadEntity.PlatformIdentifier = PlatformIdentifier.WindowsPhone; #else forumThreadEntity.PlatformIdentifier = PlatformIdentifier.Windows8; #endif try { GetDarkModeSetting(forumThreadEntity); Html = await HtmlFormater.FormatThreadHtml(forumThreadEntity); ForumThreadEntity = forumThreadEntity; PageNumbers = Enumerable.Range(1, forumThreadEntity.TotalPages).ToArray(); } catch (Exception ex) { AwfulDebugger.SendMessageDialogAsync("An error occured creating the thread HTML", ex); } }
public async Task <string> GetPrivateMessageHtml(string url) { string html = await PathIO.ReadTextAsync("ms-appx:///Assets/thread.html"); var doc2 = new HtmlDocument(); doc2.LoadHtml(html); HtmlNode bodyNode = doc2.DocumentNode.Descendants("body").FirstOrDefault(); HtmlDocument doc = (await _webManager.GetData(url)).Document; HtmlNode[] replyNodes = doc.DocumentNode.Descendants("div").Where(node => node.GetAttributeValue("id", "").Equals("thread")).ToArray(); HtmlNode threadNode = replyNodes.FirstOrDefault(node => node.GetAttributeValue("id", "").Equals("thread")); int threadId = ParseInt(threadNode.GetAttributeValue("class", string.Empty)); IEnumerable <HtmlNode> postNodes = threadNode.Descendants("table") .Where(node => node.GetAttributeValue("class", string.Empty).Contains("post")); ObservableCollection <ForumPostEntity> postList = new ObservableCollection <ForumPostEntity>(); foreach ( HtmlNode postNode in postNodes) { var post = new ForumPostEntity(); post.Parse(postNode); postList.Add(post); } ForumThreadEntity threadEntity = new ForumThreadEntity() { ForumPosts = postList }; return(await HtmlFormater.FormatThreadHtml(threadEntity)); }
public async Task GetForumPostsAsync() { if (ForumThreadEntity == null) { AwfulDebugger.SendMessageDialogAsync("Something went wrong...", new Exception("ForumThreadEntity is null.")); return; } ThreadNotSelected = false; IsLoading = true; bool isSuccess; string errorMessage = string.Empty; var postManager = new PostManager(); var postList = new List <ForumPostEntity>(); try { postList = await postManager.GetThreadPostsAsync(ForumThreadEntity); isSuccess = true; } catch (Exception ex) { IsLoading = false; isSuccess = false; errorMessage = ex.Message; } if (!isSuccess) { await AwfulDebugger.SendMessageDialogAsync("Failed to get thread posts.", new Exception(errorMessage)); return; } var count = postList.Count(node => !node.HasSeen); if (ForumThreadEntity.RepliesSinceLastOpened > 0) { if (ForumThreadEntity.RepliesSinceLastOpened - count < 0) { ForumThreadEntity.RepliesSinceLastOpened = 0; } else { ForumThreadEntity.RepliesSinceLastOpened -= count; } } #if WINDOWS_PHONE_APP ForumThreadEntity.PlatformIdentifier = PlatformIdentifier.WindowsPhone; #else ForumThreadEntity.PlatformIdentifier = PlatformIdentifier.Windows8; #endif try { GetDarkModeSetting(ForumThreadEntity); // Force Garbage Collection when navigating to webview. The web view has nasty memory leaks :/. Locator.ViewModels.MainPageVm.MainWebView.NavigateToString(string.Empty); GC.Collect(); Locator.ViewModels.MainPageVm.MainWebView.NavigateToString(await HtmlFormater.FormatThreadHtml(ForumThreadEntity, postList)); ForumThreadEntity = ForumThreadEntity; PageNumbers = Enumerable.Range(1, ForumThreadEntity.TotalPages).ToArray(); } catch (Exception ex) { AwfulDebugger.SendMessageDialogAsync("An error occured creating the thread HTML", ex); } IsLoading = false; }
public async Task <ForumReplyEntity> GetReplyCookies(ForumThreadEntity forumThread) { try { string url = string.Format(Constants.REPLY_BASE, forumThread.ThreadId); WebManager.Result result = await _webManager.GetData(url); HtmlDocument doc = result.Document; HtmlNode[] formNodes = doc.DocumentNode.Descendants("input").ToArray(); HtmlNode formKeyNode = formNodes.FirstOrDefault(node => node.GetAttributeValue("name", "").Equals("formkey")); HtmlNode formCookieNode = formNodes.FirstOrDefault(node => node.GetAttributeValue("name", "").Equals("form_cookie")); 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")); HtmlNode threadIdNode = formNodes.FirstOrDefault(node => node.GetAttributeValue("name", "").Equals("threadid")); var threadManager = new ThreadManager(); var forumThreadPosts = new ObservableCollection <ForumPostEntity>(); HtmlNode threadNode = doc.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); } forumThread.ForumPosts = forumThreadPosts; string htmlThread = await HtmlFormater.FormatThreadHtml(forumThread); var forumReplyEntity = new ForumReplyEntity(); try { string formKey = formKeyNode.GetAttributeValue("value", ""); string formCookie = formCookieNode.GetAttributeValue("value", ""); string quote = WebUtility.HtmlDecode(textNode.InnerText); string threadId = threadIdNode.GetAttributeValue("value", ""); forumReplyEntity.MapThreadInformation(formKey, formCookie, quote, threadId); forumReplyEntity.PreviousPostsRaw = htmlThread; 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.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); } }