public static void BuildAsync(Action<Awful.Core.Models.ActionResult> result, SAForumPage page) { if (Factory._worker.IsBusy) { result(Awful.Core.Models.ActionResult.Busy); return; } RunWorkerCompletedEventHandler completed = null; completed = (obj, args) => { Factory._worker.RunWorkerCompleted -= new RunWorkerCompletedEventHandler(completed); if (args.Cancelled) { result(Awful.Core.Models.ActionResult.Cancelled); } else { SAForumPage loaded = args.Result as SAForumPage; if (loaded == null) { result(Awful.Core.Models.ActionResult.Failure); } else { loaded.LastUpdated = DateTime.Now; result(Awful.Core.Models.ActionResult.Success); } } }; Factory._worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(completed); Factory._worker.RunWorkerAsync(page); }
private Awful.Core.Models.ActionResult BuildPageFromHtml(SAForumPage page, WebGetDocumentArgs args) { try { var node = args.Document.DocumentNode; this.HandleMaxPages(page, node); this.HandleThreads(page, node); return Awful.Core.Models.ActionResult.Success; } catch (Exception ex) { return Awful.Core.Models.ActionResult.Failure; } }
private void HandleMaxPages(SAForumPage page, HtmlNode node) { var maxPagesNode = node.Descendants("div") .Where(n => n.GetAttributeValue("class", "").Equals("pages")) .FirstOrDefault(); if (maxPagesNode == null) { Awful.Core.Event.Logger.AddEntry("AwfulForumPage - Could not parse maxPagesNode."); page.Parent.MaxPages = 1; } else { page.Parent.MaxPages = this.ExtractMaxForumPages(maxPagesNode); Awful.Core.Event.Logger.AddEntry(string.Format("AwfulForumPage - maxPagesNode parsed. Value: {0}", page.Parent.MaxPages)); } }
private void HandleThreads(SAForumPage page, HtmlNode node) { var forumThreadsTable = node.Descendants("table") .Where(n => n.Id.Equals("forum")) .First(); var threadList = forumThreadsTable.Descendants("tbody").First(); var threadsInfo = threadList.Descendants("tr"); page.Threads = this.GenerateThreadData(page, threadsInfo); }
private IList<ThreadData> GenerateThreadData(SAForumPage page, IEnumerable<HtmlNode> threadsInfo) { Awful.Core.Event.Logger.AddEntry("AwfulForumPage - Generating thread data..."); List<ThreadData> data = new List<ThreadData>(); foreach (var node in threadsInfo) { SAThread thread = SAThreadFactory.Build(node, page.ForumID); data.Add(thread); } data.Sort(SortThreadsByNewPostCount.Comparer); return data; }