示例#1
0
        public static ForumPageMetadata Page(this ForumMetadata forum, int pageNumber)
        {
            ForumPageMetadata page = null;

            if (forum is UserBookmarksMetadata)
            {
                page = AwfulContentRequest.Forums.LoadUserBookmarks();
            }
            else
            {
                page = AwfulContentRequest.Forums.LoadForumPage(forum.ForumID, pageNumber);
            }
            return(page);
        }
示例#2
0
        // TODO: Remember to sort thread data by new posts
        private static IList <ThreadMetadata> GenerateThreadData(ForumPageMetadata page, IEnumerable <HtmlNode> threadsInfo)
        {
            //Logger.AddEntry("AwfulForumPage - Generating thread data...");

            List <ThreadMetadata> data = new List <ThreadMetadata>();

            foreach (var node in threadsInfo)
            {
                var thread = ThreadParser.ParseThread(node);
                data.Add(thread);
            }

            return(data);
        }
示例#3
0
        private static void HandleMaxPages(ForumPageMetadata page, HtmlNode node)
        {
            var maxPagesNode = node.Descendants("div")
                               .Where(n => n.GetAttributeValue("class", "").Equals("pages"))
                               .FirstOrDefault();

            if (maxPagesNode == null)
            {
                //Logger.AddEntry("AwfulForumPage - Could not parse maxPagesNode.");
                page.PageCount = 1;
            }
            else
            {
                page.PageCount = ExtractMaxForumPages(maxPagesNode);
                //Logger.AddEntry(string.Format("AwfulForumPage - maxPagesNode parsed. Value: {0}", page.Parent.TotalPages));
            }
        }
示例#4
0
        public static ForumPageMetadata ParseForumPage(HtmlDocument doc)
        {
            var top        = doc.DocumentNode;
            var page       = new ForumPageMetadata();
            int pageNumber = -1;

            // first, let's find the forum id
            var formNode = top.Descendants("form")
                           .Where(node => node.GetAttributeValue("id", "").Equals("ac_timemachine"))
                           .FirstOrDefault();

            if (formNode != null)
            {
                string idString = formNode.GetAttributeValue("action", "");
                // strip undesiriable stuff off
                idString     = idString.Replace("/forumdisplay.php?", "");
                idString     = idString.Split('=').Last();
                page.ForumID = idString;
            }

            // then, let's find the page number
            var pageNumberNode = top.Descendants("span")
                                 .Where(node => node.GetAttributeValue("class", "").Equals("curpage"))
                                 .FirstOrDefault();

            if (pageNumberNode != null)
            {
                var pageNumberText = pageNumberNode.InnerText;
                if (!int.TryParse(pageNumberText, out pageNumber))
                {
                    pageNumber = -1;
                }
            }

            page.PageNumber = pageNumber;

            HandleMaxPages(page, top);
            HandleThreads(page, top);
            return(page);
        }
示例#5
0
 public static ForumPageMetadata Refresh(this ForumPageMetadata page)
 {
     return(AwfulContentRequest.Forums.LoadForumPage(page.ForumID, page.PageNumber));
 }