Example #1
0
        public async Task<ForumThreadEntity> GetThreadPosts(ForumThreadEntity forumThread)
        {
            try
            {
                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 ObservableCollection<ForumPostEntity>();

                //TEMP CODE
                var threadManager = new ThreadManager();
                var doc = await threadManager.GetThread(forumThread, url);

                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"));
                if (threadNode != null)
                {
                    threadNode =
        threadNode.Descendants("option")
            .FirstOrDefault(node => node.GetAttributeValue("selected", string.Empty).Contains("selected"));

                    if (forumThread.CurrentPage <= 0)
                    {
                        forumThread.CurrentPage = GetPageNumber(threadNode);
                    }
                }
                forumThread.ForumPosts = forumThreadPosts;
                return forumThread;
            }
            catch (Exception)
            {
                return null;
            }
        }
        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);
        }
Example #3
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);
        }
Example #4
0
        public async Task <ForumThreadEntity> 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 ObservableCollection <ForumPostEntity>();

            //TEMP CODE
            var threadManager = new ThreadManager();
            var doc           = await threadManager.GetThread(forumThread, url);

            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"));
            if (threadNode != null)
            {
                threadNode =
                    threadNode.Descendants("option")
                    .FirstOrDefault(node => node.GetAttributeValue("selected", string.Empty).Contains("selected"));

                if (forumThread.CurrentPage <= 0)
                {
                    forumThread.CurrentPage = GetPageNumber(threadNode);
                }
            }
            forumThread.ForumPosts = forumThreadPosts;
            return(forumThread);
        }
Example #5
0
 public async Task<string> GetPost(int postId)
 {
     try
     {
         string url = string.Format(Constants.SHOW_POST, postId);
         WebManager.Result result = await _webManager.GetData(url);
         HtmlDocument doc = result.Document;
         HtmlNode threadNode =
             doc.DocumentNode.Descendants("div")
                 .FirstOrDefault(node => node.GetAttributeValue("id", string.Empty).Contains("thread"));
         HtmlNode postNode =
             threadNode.Descendants("table")
                 .FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("post"));
         var post = new ForumPostEntity();
         post.Parse(postNode);
         return await HtmlFormater.FormatPostHtml(post);
     }
     catch (Exception)
     {
         return null;
     }
 }
Example #6
0
        public async Task <string> GetPrivateMessageHtml(string url)
        {
            string html = await PathIO.ReadTextAsync("ms-appx:///Assets/thread.html");

            var doc2 = new HtmlDocument();

            doc2.LoadHtml(html);

            HtmlNode bodyNode = doc2.DocumentNode.Descendants("body").FirstOrDefault();

            HtmlDocument doc = (await _webManager.GetData(url)).Document;

            HtmlNode[] replyNodes = doc.DocumentNode.Descendants("div").Where(node => node.GetAttributeValue("id", "").Equals("thread")).ToArray();

            HtmlNode threadNode = replyNodes.FirstOrDefault(node => node.GetAttributeValue("id", "").Equals("thread"));

            int threadId = ParseInt(threadNode.GetAttributeValue("class", string.Empty));

            IEnumerable <HtmlNode> postNodes =
                threadNode.Descendants("table")
                .Where(node => node.GetAttributeValue("class", string.Empty).Contains("post"));
            ObservableCollection <ForumPostEntity> postList = new ObservableCollection <ForumPostEntity>();

            foreach (
                HtmlNode postNode in
                postNodes)
            {
                var post = new ForumPostEntity();
                post.Parse(postNode);
                postList.Add(post);
            }
            ForumThreadEntity threadEntity = new ForumThreadEntity()
            {
                ForumPosts = postList
            };

            return(await HtmlFormater.FormatThreadHtml(threadEntity));
        }
Example #7
0
        public async Task <string> GetPost(int postId)
        {
            try
            {
                string            url    = string.Format(Constants.SHOW_POST, postId);
                WebManager.Result result = await _webManager.GetData(url);

                HtmlDocument doc        = result.Document;
                HtmlNode     threadNode =
                    doc.DocumentNode.Descendants("div")
                    .FirstOrDefault(node => node.GetAttributeValue("id", string.Empty).Contains("thread"));
                HtmlNode postNode =
                    threadNode.Descendants("table")
                    .FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Contains("post"));
                var post = new ForumPostEntity();
                post.Parse(postNode);
                return(await HtmlFormater.FormatPostHtml(post));
            }
            catch (Exception)
            {
                return(null);
            }
        }
        public async Task<string> GetPrivateMessageHtml(string url)
        {

            string html = await PathIO.ReadTextAsync("ms-appx:///Assets/thread.html");

            var doc2 = new HtmlDocument();

            doc2.LoadHtml(html);

            HtmlNode bodyNode = doc2.DocumentNode.Descendants("body").FirstOrDefault();

            HtmlDocument doc = (await _webManager.GetData(url)).Document;

            HtmlNode[] replyNodes = doc.DocumentNode.Descendants("div").Where(node => node.GetAttributeValue("id", "").Equals("thread")).ToArray();

            HtmlNode threadNode = replyNodes.FirstOrDefault(node => node.GetAttributeValue("id", "").Equals("thread"));

            int threadId = ParseInt(threadNode.GetAttributeValue("class", string.Empty));

            IEnumerable<HtmlNode> postNodes =
                threadNode.Descendants("table")
                    .Where(node => node.GetAttributeValue("class", string.Empty).Contains("post"));
          ObservableCollection<ForumPostEntity> postList = new ObservableCollection<ForumPostEntity>();
            foreach (
     HtmlNode postNode in
         postNodes)
            {
                var post = new ForumPostEntity();
                post.Parse(postNode);
                postList.Add(post);
            }
            ForumThreadEntity threadEntity = new ForumThreadEntity()
            {
                ForumPosts = postList
            };
            return await HtmlFormater.FormatThreadHtml(threadEntity);
        }
Example #9
0
        public async Task<ForumReplyEntity> GetReplyCookies(ForumThreadEntity forumThread)
        {
            try
            {
                string url = string.Format(Constants.REPLY_BASE, forumThread.ThreadId);
                WebManager.Result result = await _webManager.GetData(url);
                HtmlDocument doc = result.Document;

                HtmlNode[] formNodes = doc.DocumentNode.Descendants("input").ToArray();

                HtmlNode formKeyNode =
                    formNodes.FirstOrDefault(node => node.GetAttributeValue("name", "").Equals("formkey"));

                HtmlNode formCookieNode =
                    formNodes.FirstOrDefault(node => node.GetAttributeValue("name", "").Equals("form_cookie"));

                HtmlNode bookmarkNode =
                    formNodes.FirstOrDefault(node => node.GetAttributeValue("name", "").Equals("bookmark"));

                HtmlNode[] textAreaNodes = doc.DocumentNode.Descendants("textarea").ToArray();

                HtmlNode textNode =
                    textAreaNodes.FirstOrDefault(node => node.GetAttributeValue("name", "").Equals("message"));

                HtmlNode threadIdNode =
                    formNodes.FirstOrDefault(node => node.GetAttributeValue("name", "").Equals("threadid"));

                var threadManager = new ThreadManager();

                var forumThreadPosts = new ObservableCollection<ForumPostEntity>();

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

                forumThread.ForumPosts = forumThreadPosts;

                string htmlThread = await HtmlFormater.FormatThreadHtml(forumThread);

                var forumReplyEntity = new ForumReplyEntity();
                try
                {
                    string formKey = formKeyNode.GetAttributeValue("value", "");
                    string formCookie = formCookieNode.GetAttributeValue("value", "");
                    string quote = WebUtility.HtmlDecode(textNode.InnerText);
                    string threadId = threadIdNode.GetAttributeValue("value", "");
                    forumReplyEntity.MapThreadInformation(formKey, formCookie, quote, threadId);
                    forumReplyEntity.PreviousPostsRaw = htmlThread;
                    return forumReplyEntity;
                }
                catch (Exception)
                {
                    throw new InvalidOperationException("Could not parse newReply form data.");
                }
            }
            catch (Exception)
            {
                return null;
            }
        }
Example #10
0
        public async Task<ForumReplyEntity> GetReplyCookiesForEdit(long postId)
        {
            try
            {
                string url = string.Format(Constants.EDIT_BASE, postId);
                WebManager.Result result = await _webManager.GetData(url);
                HtmlDocument doc = result.Document;

                HtmlNode[] formNodes = doc.DocumentNode.Descendants("input").ToArray();

                HtmlNode bookmarkNode =
                    formNodes.FirstOrDefault(node => node.GetAttributeValue("name", "").Equals("bookmark"));

                HtmlNode[] textAreaNodes = doc.DocumentNode.Descendants("textarea").ToArray();

                HtmlNode textNode =
                    textAreaNodes.FirstOrDefault(node => node.GetAttributeValue("name", "").Equals("message"));

                var threadManager = new ThreadManager();

                //Get previous posts from quote page.
                string url2 = string.Format(Constants.QUOTE_BASE, postId);
                WebManager.Result result2 = await _webManager.GetData(url2);
                HtmlDocument doc2 = result2.Document;

                var forumThreadPosts = new ObservableCollection<ForumPostEntity>();

                HtmlNode threadNode =
                   doc2.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);
                }

                ForumThreadEntity threadEntity = new ForumThreadEntity()
                {
                    ForumPosts = forumThreadPosts
                };

                string htmlThread = await HtmlFormater.FormatThreadHtml(threadEntity);

                var forumReplyEntity = new ForumReplyEntity();
                try
                {
                    string quote = WebUtility.HtmlDecode(textNode.InnerText);
                    forumReplyEntity.PreviousPostsRaw = htmlThread;
                    string bookmark = bookmarkNode.OuterHtml.Contains("checked") ? "yes" : "no";
                    forumReplyEntity.MapEditPostInformation(quote, postId, bookmark);
                    return forumReplyEntity;
                }
                catch (Exception)
                {
                    throw new InvalidOperationException("Could not parse newReply form data.");
                }
            }
            catch (Exception)
            {
                return null;
            }
        }
Example #11
0
        public async Task <ForumReplyEntity> GetReplyCookies(ForumThreadEntity forumThread)
        {
            try
            {
                string            url    = string.Format(Constants.REPLY_BASE, forumThread.ThreadId);
                WebManager.Result result = await _webManager.GetData(url);

                HtmlDocument doc = result.Document;

                HtmlNode[] formNodes = doc.DocumentNode.Descendants("input").ToArray();

                HtmlNode formKeyNode =
                    formNodes.FirstOrDefault(node => node.GetAttributeValue("name", "").Equals("formkey"));

                HtmlNode formCookieNode =
                    formNodes.FirstOrDefault(node => node.GetAttributeValue("name", "").Equals("form_cookie"));

                HtmlNode bookmarkNode =
                    formNodes.FirstOrDefault(node => node.GetAttributeValue("name", "").Equals("bookmark"));

                HtmlNode[] textAreaNodes = doc.DocumentNode.Descendants("textarea").ToArray();

                HtmlNode textNode =
                    textAreaNodes.FirstOrDefault(node => node.GetAttributeValue("name", "").Equals("message"));

                HtmlNode threadIdNode =
                    formNodes.FirstOrDefault(node => node.GetAttributeValue("name", "").Equals("threadid"));

                var threadManager = new ThreadManager();

                var forumThreadPosts = new ObservableCollection <ForumPostEntity>();

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

                forumThread.ForumPosts = forumThreadPosts;

                string htmlThread = await HtmlFormater.FormatThreadHtml(forumThread);

                var forumReplyEntity = new ForumReplyEntity();
                try
                {
                    string formKey    = formKeyNode.GetAttributeValue("value", "");
                    string formCookie = formCookieNode.GetAttributeValue("value", "");
                    string quote      = WebUtility.HtmlDecode(textNode.InnerText);
                    string threadId   = threadIdNode.GetAttributeValue("value", "");
                    forumReplyEntity.MapThreadInformation(formKey, formCookie, quote, threadId);
                    forumReplyEntity.PreviousPostsRaw = htmlThread;
                    return(forumReplyEntity);
                }
                catch (Exception)
                {
                    throw new InvalidOperationException("Could not parse newReply form data.");
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
Example #12
0
        public async Task <ForumReplyEntity> GetReplyCookiesForEdit(long postId)
        {
            try
            {
                string            url    = string.Format(Constants.EDIT_BASE, postId);
                WebManager.Result result = await _webManager.GetData(url);

                HtmlDocument doc = result.Document;

                HtmlNode[] formNodes = doc.DocumentNode.Descendants("input").ToArray();

                HtmlNode bookmarkNode =
                    formNodes.FirstOrDefault(node => node.GetAttributeValue("name", "").Equals("bookmark"));

                HtmlNode[] textAreaNodes = doc.DocumentNode.Descendants("textarea").ToArray();

                HtmlNode textNode =
                    textAreaNodes.FirstOrDefault(node => node.GetAttributeValue("name", "").Equals("message"));

                var threadManager = new ThreadManager();

                //Get previous posts from quote page.
                string            url2    = string.Format(Constants.QUOTE_BASE, postId);
                WebManager.Result result2 = await _webManager.GetData(url2);

                HtmlDocument doc2 = result2.Document;

                var forumThreadPosts = new ObservableCollection <ForumPostEntity>();

                HtmlNode threadNode =
                    doc2.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);
                }

                ForumThreadEntity threadEntity = new ForumThreadEntity()
                {
                    ForumPosts = forumThreadPosts
                };

                string htmlThread = await HtmlFormater.FormatThreadHtml(threadEntity);

                var forumReplyEntity = new ForumReplyEntity();
                try
                {
                    string quote = WebUtility.HtmlDecode(textNode.InnerText);
                    forumReplyEntity.PreviousPostsRaw = htmlThread;
                    string bookmark = bookmarkNode.OuterHtml.Contains("checked") ? "yes" : "no";
                    forumReplyEntity.MapEditPostInformation(quote, postId, bookmark);
                    return(forumReplyEntity);
                }
                catch (Exception)
                {
                    throw new InvalidOperationException("Could not parse newReply form data.");
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }