Exemple #1
0
        public async Task <ForumUserEntity> GetUserFromProfilePage(ForumUserEntity user, long userId)
        {
            string url = Constants.BASE_URL + string.Format(Constants.USER_PROFILE, userId);
            var    doc = (await _webManager.DownloadHtml(url)).Document;

            return(string.IsNullOrEmpty(user.Username) ? ForumUserEntity.FromPost(doc.DocumentNode.Descendants("td").FirstOrDefault(node => node.GetAttributeValue("id", string.Empty).Contains("thread"))) : ForumUserEntity.FromUserProfile(doc.DocumentNode.Descendants("td").FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("info"))));
        }
Exemple #2
0
        public async Task <List <SmileCategoryEntity> > GetSmileList()
        {
            var smileCategoryList = new List <SmileCategoryEntity>();

            //inject this
            var doc = (await _webManager.DownloadHtml(Constants.SMILE_URL)).Document;

            var           smileCategoryTitles = doc.DocumentNode.Descendants("div").FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("inner")).Descendants("h3");
            List <string> categoryTitles      = smileCategoryTitles.Select(smileCategoryTitle => WebUtility.HtmlDecode(smileCategoryTitle.InnerText)).ToList();
            var           smileNodes          = doc.DocumentNode.Descendants("ul").Where(node => node.GetAttributeValue("class", string.Empty).Contains("smilie_group"));
            int           smileCount          = 0;

            foreach (var smileNode in smileNodes)
            {
                var smileList  = new List <SmileEntity>();
                var smileIcons = smileNode.Descendants("li");
                foreach (var smileIcon in smileIcons)
                {
                    var smileEntity = new SmileEntity();
                    smileEntity.Parse(smileIcon);
                    smileList.Add(smileEntity);
                }
                smileCategoryList.Add(new SmileCategoryEntity(categoryTitles[smileCount], smileList));
                smileCount++;
            }
            return(smileCategoryList);
        }
Exemple #3
0
        public async Task <List <ForumCategoryEntity> > GetForumCategoryMainPage()
        {
            var forumGroupList = new List <ForumCategoryEntity>();

            var doc = (await _webManager.DownloadHtml(Constants.FORUM_LIST_PAGE)).Document;

            HtmlNode forumNode = doc.DocumentNode.Descendants("select").FirstOrDefault(node => node.GetAttributeValue("name", string.Empty).Equals("forumid"));

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

                foreach (var node in forumNodes)
                {
                    var value = node.Attributes["value"].Value;
                    int id;
                    if (!int.TryParse(value, out id) || id <= -1)
                    {
                        continue;
                    }
                    if (node.NextSibling.InnerText.Contains("--"))
                    {
                        string forumName        = WebUtility.HtmlDecode(node.NextSibling.InnerText.Replace("-", string.Empty));
                        bool   isSubforum       = node.NextSibling.InnerText.Count(c => c == '-') > 2;
                        var    forumSubCategory = new ForumEntity(forumName, string.Format(Constants.FORUM_PAGE, value), string.Empty, isSubforum);
                        forumGroupList.LastOrDefault().ForumList.Add(forumSubCategory);
                    }
                    else
                    {
                        string forumName  = WebUtility.HtmlDecode(node.NextSibling.InnerText);
                        var    forumGroup = new ForumCategoryEntity(forumName, string.Format(Constants.FORUM_PAGE, value));
                        forumGroupList.Add(forumGroup);
                    }
                }
            }

#if DEBUG
            forumGroupList[3].ForumList.Add(AddDebugForum());
#endif

            return(forumGroupList);
        }
        public async Task <List <ForumSearchEntity> > GetSearchResults(String url)
        {
            var searchResults = new List <ForumSearchEntity>();

            //inject this
            var doc = (await _webManager.DownloadHtml(url)).Document;

            HtmlNode searchNode = doc.DocumentNode.Descendants("div").FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("inner"));

            url = Constants.BASE_URL + "search.php" + searchNode.Descendants("a").FirstOrDefault().GetAttributeValue("href", string.Empty);

            doc = (await _webManager.DownloadHtml(url)).Document;
            //Test persisting Html from search page.
            //HtmlDocument doc = new HtmlDocument();
            //string html = await LoadSearchPage("search.txt");
            //doc.LoadHtml(html);
            searchResults = ParseSearchRows(doc.DocumentNode.Descendants("table").FirstOrDefault(node => node.GetAttributeValue("id", string.Empty).Contains("main_full")));
            //ForumSearchManager.SaveSearchPage("search.txt", doc.DocumentNode.OuterHtml.ToString());
            return(searchResults);
        }
Exemple #5
0
        public async Task <List <ForumPostEntity> > GetThreadPosts(ForumThreadEntity forumThread)
        {
            string url = forumThread.Location;

            if (forumThread.CurrentPage > 0)
            {
                url = forumThread.Location + string.Format(Constants.PAGE_NUMBER, forumThread.CurrentPage);
            }
            else if (forumThread.HasBeenViewed)
            {
                url = forumThread.Location + Constants.GOTO_NEW_POST;
            }

            var forumThreadPosts = new List <ForumPostEntity>();

            //TEMP CODE
            var result = await _webManager.DownloadHtml(url);

            HtmlDocument doc         = result.Document;
            string       responseUri = result.AbsoluteUri;

            /* TODO: The following checks the thread URL for "pti" (which indicated which post to scroll to)
             * Having it in the post manager though, is wrong. This needs to be refactored and a better method of
             * getting this needs to be put in.
             */
            string[] test = responseUri.Split('#');
            if (test.Length > 1 && test[1].Contains("pti"))
            {
                forumThread.ScrollToPost = Int32.Parse(Regex.Match(responseUri.Split('#')[1], @"\d+").Value) - 1;
            }
            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);
            }

            threadNode = doc.DocumentNode.Descendants("div").FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("pages top"));
            threadNode = threadNode.Descendants("option").FirstOrDefault(node => node.GetAttributeValue("selected", string.Empty).Contains("selected"));

            if (forumThread.CurrentPage <= 0)
            {
                forumThread.CurrentPage = GetPageNumber(threadNode);
            }

            HtmlNode pageNode = doc.DocumentNode.Descendants("select").FirstOrDefault();

            forumThread.TotalPages = forumThread.CurrentPage <= 1 ? 1 : Convert.ToInt32(pageNode.Descendants("option").LastOrDefault().GetAttributeValue("value", string.Empty));

            return(forumThreadPosts);
        }
Exemple #6
0
        public async Task <List <ForumThreadEntity> > GetBookmarks(ForumEntity forumCategory)
        {
            var    forumSubcategoryList = new List <ForumEntity>();
            var    forumThreadList      = new List <ForumThreadEntity>();
            String url = forumCategory.Location;

            if (forumCategory.CurrentPage > 0)
            {
                url = forumCategory.Location + string.Format(Constants.PAGE_NUMBER, forumCategory.CurrentPage);
            }

            HtmlDocument doc       = (await _webManager.DownloadHtml(url)).Document;
            HtmlNode     forumNode = doc.DocumentNode.Descendants().FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("threadlist"));


            foreach (HtmlNode threadNode in forumNode.Descendants("tr").Where(node => node.GetAttributeValue("class", string.Empty).StartsWith("thread")))
            {
                var threadEntity = new ForumThreadEntity();
                threadEntity.Parse(threadNode);
                forumThreadList.Add(threadEntity);
            }
            return(forumThreadList);
        }
Exemple #7
0
        public async Task <List <ForumUserRapSheetEntity> > GetRapSheet(string url)
        {
            var rapSheets = new List <ForumUserRapSheetEntity>();
            var doc       = (await _webManager.DownloadHtml(url)).Document;

            HtmlNode rapSheetNode = doc.DocumentNode.Descendants("table").FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("standard full"));

            rapSheetNode.Descendants("tr").FirstOrDefault().Remove();
            if (rapSheetNode.Descendants("tr").Any())
            {
                rapSheets.AddRange(rapSheetNode.Descendants("tr").Select(ForumUserRapSheetEntity.FromRapSheet));
            }
            return(rapSheets);
        }
Exemple #8
0
        public async Task <List <TagCategoryEntity> > GetTagList(long forumId)
        {
            var tagList = new List <TagEntity>();

            //inject this
            var doc = (await _webManager.DownloadHtml(string.Format(Constants.NEW_THREAD, forumId))).Document;

            var icons = doc.DocumentNode.Descendants("div").Where(node => node.GetAttributeValue("class", string.Empty).Equals("posticon"));

            foreach (var icon in icons)
            {
                var tag = new TagEntity();
                tag.Parse(icon);
                tagList.Add(tag);
            }
            var tagCategoryList = new List <TagCategoryEntity>();
            var tagCategory     = new TagCategoryEntity("Tags", tagList);

            tagCategoryList.Add(tagCategory);
            return(tagCategoryList);
        }
 public async Task <HtmlDocument> GetFrontPage()
 {
     return((await _webManager.DownloadHtml(Constants.FRONT_PAGE)).Document);
 }