示例#1
0
        /// <summary>
        ///     Populates the page with content passed during navigation. Any saved state is also
        ///     provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        ///     The source of the event; typically <see cref="NavigationHelper" />
        /// </param>
        /// <param name="e">
        ///     Event data that provides both the navigation parameter passed to
        ///     <see cref="Frame.Navigate(Type, Object)" /> when this page was initially requested and
        ///     a dictionary of state preserved by this page during an earlier
        ///     session. The state will be null the first time a page is visited.
        /// </param>
        private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            _forumPost = e.NavigationParameter as ForumPostEntity;
            if(_forumPost != null)
            ReplyText.Text = string.Format(Constants.QUOTE_EXP, _forumPost.User.Username, _forumPost.PostId, _forumPost.PostFormatted);

            _forumThread = e.NavigationParameter as ForumThreadEntity;
        }
示例#2
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;
        }
        private static ForumPostEntity ParseEntity(string html)
        {
            var doc = new HtmlDocument();
            doc.LoadHtml(html);
            var entity = new ForumPostEntity();

            entity.Parse(doc.DocumentNode.Descendants("table").FirstOrDefault());
            return entity;
        }