public async override void Execute(object parameter) { var args = parameter as ItemClickEventArgs; if (args == null) { AwfulDebugger.SendMessageDialogAsync("Navigation failed", new Exception("Arguments are null")); return; } Locator.ViewModels.SaclopediaPageVm.IsLoading = true; try { var navEntity = (SaclopediaNavigationTopicEntity)args.ClickedItem; var result = await Locator.ViewModels.SaclopediaPageVm.SaclopediaManager.GetSaclopediaEntity(Constants.BaseUrl + navEntity.Link); Locator.ViewModels.SaclopediaPageVm.Title = result.Title; var platformIdentifier = PlatformIdentifier.Windows8; //App.RootFrame.Navigate(typeof (SaclopediaEntryPage)); Locator.ViewModels.SaclopediaPageVm.Body = await HtmlFormater.FormatSaclopediaEntry(result.Body, platformIdentifier); } catch (Exception ex) { AwfulDebugger.SendMessageDialogAsync("Navigation failed", ex); } Locator.ViewModels.SaclopediaPageVm.IsLoading = false; }
/// <summary> /// 格式化Html /// </summary> /// <param name="xmldoc"></param> /// <returns></returns> public static Dictionary <string, string> HtmlFormat(XmlDocument xmldoc) { var resultDic = new Dictionary <string, string>(); string input = HttpUtility.UrlDecode(GetNodeInnerText(xmldoc, "input")); string result = HtmlFormater.FormatHtml(input, true); string status = result.StartsWith("异常") ? "err" : "ok"; resultDic.Add("result", result); resultDic.Add("status", status); return(resultDic); }
public void FormatAsBold_WhenCalled_ShouldEncloseTheStringWithStrongElement() { HtmlFormater formater = new HtmlFormater(); string content = "abc"; string result = formater.FormatAsBold(content); Assert.That(result, Does.StartWith("<strong>").IgnoreCase); Assert.That(result, Does.EndWith("</strong>").IgnoreCase); Assert.That(result, Does.Contain(content)); }
private void Html格式化toolStripMenuItem_Click(object sender, EventArgs e) { try { TxtHTML.Text = HtmlFormater.FormatHtml(TxtHTML.Text, true); } catch (Exception ex) { WriteErrMsg(ex.Message); } }
public void FormatAsBold_WhenCalled_ShouldEncloseTheStringWithStrongElement() { var formatter = new HtmlFormater(); var result = formatter.FormatAsBold("abc"); Assert.Contains("abc", result); Assert.StartsWith("<strong>", result); Assert.EndsWith("</strong>", result); }
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 <string> GetPost(int postId) { try { string url = string.Format(Constants.SHOW_POST, postId); WebManager.Result result = await _webManager.GetData(url); HtmlDocument doc = result.Document; HtmlNode threadNode = doc.DocumentNode.Descendants("div") .FirstOrDefault(node => node.GetAttributeValue("id", string.Empty).Contains("thread")); HtmlNode postNode = threadNode.Descendants("table") .FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("post")); var post = new ForumPostEntity(); post.Parse(postNode); return(await HtmlFormater.FormatPostHtml(post)); } catch (Exception) { return(null); } }
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); } }