Exemple #1
0
        public async Task<ObservableCollection<ForumCategoryEntity>> GetForumCategoryMainPage()
        {
            var forumGroupList = new ObservableCollection<ForumCategoryEntity>();
            var result = await _webManager.GetData(Constants.FORUM_LIST_PAGE);
            HtmlDocument doc = result.Document;

            HtmlNode forumNode =
                doc.DocumentNode.Descendants("select")
                    .FirstOrDefault(node => node.GetAttributeValue("name", string.Empty).Equals("forumid"));
            if (forumNode != null)
            {
                try
                {
                    IEnumerable<HtmlNode> forumNodes = forumNode.Descendants("option");

                    foreach (HtmlNode node in forumNodes)
                    {
                        string 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
                            {
                                Name = forumName.Trim(),
                                Location = string.Format(Constants.FORUM_PAGE, value),
                                IsSubforum =  isSubforum
                            };
                            forumSubCategory.SetForumId();
                            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);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Main Forum Parsing Error: " + ex.StackTrace);
                }
            }

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

            return forumGroupList;
        }
Exemple #2
0
 private ForumEntity AddDebugForum()
 {
     var forum = new ForumEntity()
     {
         Name = "Apps In Developmental States",
         Location = Constants.BASE_URL + "forumdisplay.php?forumid=261",
         IsSubforum = false
     };
     forum.SetForumId();
     return forum;
 }