public void Initialize()
        {
            if (!IsSetUp)
            {
                var context = AwfulTestService.TestContext;
                using (var dao = new AwfulForumsDAO(context))
                {
                    dao.SetDatabaseToDefaults();
                }
                try
                {
                    var forum = new AwfulForum() { ForumName = "test forum" };
                    context.Forums.InsertOnSubmit(forum);
                    context.SubmitChanges();

                    thread1.Author = "author";
                    thread1.Forum = forum;
                    for (int i = 0; i < 5; i++)
                    {
                        thread1.Pages.Add(new AwfulThreadPage(thread1, i));
                    }

                    context.Threads.InsertOnSubmit(thread1);
                    context.SubmitChanges();
                    this.IsSetUp = true;
                }
                catch (Exception ex)
                {
                    Assert.Fail(ex.Message);
                    this.IsSetUp = false;
                }
            }
        }
예제 #2
0
        public static AwfulForum Build(HtmlNode node)
        {
            var url = node.Attributes["href"].Value;
            var tokens = url.Split('=');

            AwfulForum forum = new AwfulForum();

            forum.ID = Int32.Parse(tokens.Last());
            forum.ForumName = node.InnerText.Trim();

            return forum;
        }
예제 #3
0
        public static IEnumerable<ForumData> ParseForumList(HtmlDocument doc)
        {
            List<ForumData> forums = new List<ForumData>(100);
            if (doc == null)
                return forums;

            var parent = doc.DocumentNode;

            var selectNode = parent.Descendants("select")
                .Where(node => node.GetAttributeValue("name", "").Equals("forumid"))
                .FirstOrDefault();

            if (selectNode != null)
            {
                var forumNodes = selectNode.Descendants("option").ToArray();

                foreach (var node in forumNodes)
                {
                    var value = node.Attributes["value"].Value;
                    int id = 0;
                    if (Int32.TryParse(value, out id) && id > 0)
                    {
                        string name = node.NextSibling.InnerText;
                        name = HttpUtility.HtmlDecode(name);
                        if (name != String.Empty)
                        {
                            name = name.Replace("-", "");
                            name = name.Trim();
                            if (!ForumBlacklist.Contains(name))
                            {
                                var forum = new AwfulForum() { ID = id, ForumName = name };
                                AwfulSubforum.SetDefaultSubforum(forum);
                                forums.Add(forum);
                            }
                        }
                    }
                }
            }

            return forums;
        }
예제 #4
0
        public static ForumPageData ParseForumPage(HtmlDocument doc)
        {
            var top = doc.DocumentNode;
            AwfulForum forum = new AwfulForum();
            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();
                int id = -1;
                if (int.TryParse(idString, out id))
                {
                    forum.ID = id;
                }
            }

            // 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; }
            }

            var page = new AwfulForumPage(forum, pageNumber);
            HandleMaxPages(page, top);
            HandleThreads(page, top);
            return page;
        }