Example #1
0
        public async Task<ObservableCollection<ForumCategoryEntity>> GetForumCategoryMainPage()
        {
            try
            {
                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)
                {
                    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(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;
            }
                // TODO: Expand catch for specific errors.
            catch (Exception)
            {
                return null;
            }
        }
 private void GetFavoriteForums()
 {
     if (!_localSettings.Values.ContainsKey("_forumIds")) return;
     DeserializeXmlToList((string)_localSettings.Values["_forumIds"]);
     var forumEntities = new List<ForumEntity>();
     foreach (var f in ForumGroupList.Select(forumGroup => forumGroup.ForumList.Where(forum => _forumIds.Contains(forum.ForumId)).ToList()))
     {
         forumEntities.AddRange(f);
     }
     _favoritesEntity = new ForumCategoryEntity("Favorites", "forumid=48")
     {
         ForumList = forumEntities
     };
     SetFavoriteForums(new ObservableCollection<ForumCategoryEntity> { _favoritesEntity });
 }
Example #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 void GetFavoriteForums()
 {
     using (var db = new FavoriteForumContext())
     {
         var forumEntities = db.Forums.ToList();
         _favoritesEntity = new ForumCategoryEntity("Favorites", "forumid=48")
         {
             ForumList = forumEntities
         };
         SetFavoriteForums(new ObservableCollection<ForumCategoryEntity> { _favoritesEntity });
     }  
 }
Example #5
0
 private void FavoriteForumButton_OnClick(object sender, RoutedEventArgs e)
 {
     // TODO: Move to view model? Change click handler?
     var forumList = new List<ForumEntity>();
     ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
     if (itemGridView.SelectedItems.Any())
     {
         forumList.AddRange(itemGridView.SelectedItems.Cast<ForumEntity>());
         List<long> forumIdList = forumList.Select(forum => forum.ForumId).ToList();
         
         localSettings.Values["_forumIds"] = SerializeListToXml(forumIdList);
         _favoritesEntity = new ForumCategoryEntity("Favorites", "forumid=48")
         {
             ForumList = forumList
         };
         _vm.SetFavoriteForums(new ObservableCollection<ForumCategoryEntity> { _favoritesEntity }); 
     }
     else
     {
         localSettings.Values["_forumIds"] = null;
         _vm.SetFavoriteForums(null);
     }
 }