Beispiel #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;
            }
        }
        public async Task<ForumReplyEntity> GetReplyCookies(ForumThreadEntity forumThread)
        {
            try
            {
                string url = string.Format(Constants.REPLY_BASE, forumThread.ThreadId);
                WebManager.Result result = await _webManager.DownloadHtml(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();

                string htmlThread = await threadManager.GetThreadHtml(doc);

                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;
            }
        }
Beispiel #3
0
 private async void WebView_ScriptNotify(object sender, NotifyEventArgs e)
 {
     string stringJson = e.Value;
     var command = JsonConvert.DeserializeObject<ReplyView.ThreadCommand>(stringJson);
     switch (command.Command)
     {
         case "profile":
             Frame.Navigate(typeof(UserProfileView), command.Id);
             break;
         case "post_history":
             Frame.Navigate(typeof(UserPostHistoryPage), command.Id);
             break;
         case "rap_sheet":
             Frame.Navigate(typeof(RapSheetView), command.Id);
             break;
         case "openThread":
             // Because we are coming from an existing thread, rather than the thread lists, we need to get the thread information beforehand.
             // However, right now the managers are not set up to support this. The thread is getting downloaded twice, when it really only needs to happen once.
             var threadManager = new ThreadManager();
             var thread = await threadManager.GetThread(new ForumThreadEntity(), command.Id);
             if (thread == null)
             {
                 var error = new MessageDialog("Specified post was not found in the live forums.")
                 {
                     DefaultCommandIndex = 1
                 };
                 await error.ShowAsync();
                 break;
             }
             string jsonObjectString = JsonConvert.SerializeObject(thread);
             Frame.Navigate(typeof(ThreadPage), jsonObjectString);
             break;
         case "setFont":
             if (_localSettings.Values.ContainsKey("zoomSize"))
             {
                 _zoomSize = Convert.ToInt32(_localSettings.Values["zoomSize"]);
                 RapSheetWebView.InvokeScriptAsync("ResizeWebviewFont", new[] { _zoomSize.ToString() });
             }
             else
             {
                 _zoomSize = 14;
             }
             break;
         default:
             var msgDlg = new MessageDialog("Not working yet!")
             {
                 DefaultCommandIndex = 1
             };
             await msgDlg.ShowAsync();
             break;
     }
 }
Beispiel #4
0
        public async Task<string> GetThreadPostInformation(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;
            }


            WebManager.Result 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;
                forumThread.ScrollToPostString = "#" + test[1];
            }

            HtmlNode 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[] pageNodes = doc.DocumentNode.Descendants("div").ToArray();
            HtmlNode pageNode =
                pageNodes.FirstOrDefault(node => node.GetAttributeValue("class", string.Empty).Equals("pages top"));
            pageNode = pageNode.Descendants("option").LastOrDefault();
            forumThread.TotalPages = pageNode == null
                ? 1
                : Convert.ToInt32(pageNode.GetAttributeValue("value", string.Empty));

            var threadManager = new ThreadManager();
            return await threadManager.GetThreadHtml(doc);
        }
Beispiel #5
0
 private async void PreviousPostsWebView_ScriptNotify(object sender, NotifyEventArgs e)
 {
     string stringJson = e.Value;
     var command = JsonConvert.DeserializeObject<ReplyView.ThreadCommand>(stringJson);
     var replyManager = new ReplyManager();
     switch (command.Command)
     {
         case "profile":
             Frame.Navigate(typeof(UserProfileView), command.Id);
             break;
         case "post_history":
             Frame.Navigate(typeof(UserPostHistoryPage), command.Id);
             break;
         case "rap_sheet":
             Frame.Navigate(typeof(RapSheetView), command.Id);
             break;
         case "quote":
               loadingProgressBar.Visibility = Visibility.Visible;
               string quoteString = await replyManager.GetQuoteString(Convert.ToInt64(command.Id));
                 quoteString = string.Concat(Environment.NewLine, quoteString);
                 string replyText = string.IsNullOrEmpty(ReplyText.Text) ? string.Empty : ReplyText.Text;
             if (replyText != null) ReplyText.Text = replyText.Insert(ReplyText.Text.Length, quoteString);
             loadingProgressBar.Visibility = Visibility.Collapsed;
             break;
         case "setFont":
             if (_localSettings.Values.ContainsKey("zoomSize"))
             {
                 _zoomSize = Convert.ToInt32(_localSettings.Values["zoomSize"]);
                 PreviewLastPostWebView.InvokeScriptAsync("ResizeWebviewFont", new[] { _zoomSize.ToString() });
             }
             else
             {
                 _zoomSize = 14;
             }
             break;
         case "edit":
             Frame.Navigate(typeof(EditReplyPage), command.Id);
             break;
         case "openThread":
             // Because we are coming from an existing thread, rather than the thread lists, we need to get the thread information beforehand.
             // However, right now the managers are not set up to support this. The thread is getting downloaded twice, when it really only needs to happen once.
             var threadManager = new ThreadManager();
             var thread = await threadManager.GetThread(new ForumThreadEntity(), command.Id);
             if (thread == null)
             {
                 var error = new MessageDialog("Specified post was not found in the live forums.")
                 {
                     DefaultCommandIndex = 1
                 };
                 await error.ShowAsync();
                 break;
             }
             string jsonObjectString = JsonConvert.SerializeObject(thread);
             Frame.Navigate(typeof(ThreadPage), jsonObjectString);
             break;
         default:
             var msgDlg = new MessageDialog("Not working yet!")
             {
                 DefaultCommandIndex = 1
             };
             await msgDlg.ShowAsync();
             break;
     }
 }
Beispiel #6
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;
            }
        }
Beispiel #7
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;
            }
        }
Beispiel #8
0
 private async void NewThread_OnClick(object sender, RoutedEventArgs e)
 {
     _vm.PostIcon = (PostIconEntity)PostIconComboBox.SelectedItem ??
                    new PostIconEntity { Id = 0, Title = "Shit" };
     _vm.NewThreadEntity.MapTo(SubjectTextBox.Text, ReplyText.Text, _vm.ForumEntity, _vm.PostIcon);
     ThreadManager threadManager = new ThreadManager();
     bool result = await threadManager.CreateNewThread(_vm.NewThreadEntity);
     if (result)
     {
         Frame.GoBack();
     }
     else
     {
         var msgDlg = new MessageDialog("Error making thread!");
         await msgDlg.ShowAsync();
     }
 }
Beispiel #9
0
 private async void WebView_ScriptNotify(object sender, NotifyEventArgs e)
 {
     string stringJson = e.Value;
     var command = JsonConvert.DeserializeObject<ThreadCommand>(stringJson);
     switch (command.Command)
     {
         case "quote":
             Frame.Navigate(typeof(ReplyPage), command.Id);
             break;
         case "edit":
             Frame.Navigate(typeof(EditPage), command.Id);
             break;
         case "setFont":
             break;
         case "scrollToPost":
             if (!string.IsNullOrEmpty(_vm.ForumThreadEntity.ScrollToPostString))
             await ThreadWebView.InvokeScriptAsync("ScrollToDiv", new[] { _vm.ForumThreadEntity.ScrollToPostString });
             break;
         case "markAsLastRead":
             await _threadManager.MarkPostAsLastRead(_forumThread, Convert.ToInt32(command.Id));
             int nextPost = Convert.ToInt32(command.Id) + 1;
             await ThreadWebView.InvokeScriptAsync("ScrollToDiv", new[] { string.Concat("#postId", nextPost.ToString()) });
             var message = new MessageDialog("Post marked as last read! Now go on and live your life!")
                 {
                     DefaultCommandIndex = 1
                 };
             await message.ShowAsync();
             break;
         case "openThread":
             // Because we are coming from an existing thread, rather than the thread lists, we need to get the thread information beforehand.
             // However, right now the managers are not set up to support this. The thread is getting downloaded twice, when it really only needs to happen once.
             var threadManager = new ThreadManager();
             var thread = await threadManager.GetThread(new ForumThreadEntity(), command.Id);
             if (thread == null)
             {
                 var error = new MessageDialog("Specified post was not found in the live forums.")
                 {
                     DefaultCommandIndex = 1
                 };
                 await error.ShowAsync();
                 break;
             }
             string jsonObjectString = JsonConvert.SerializeObject(thread);
             Frame.Navigate(typeof(ThreadPage), jsonObjectString);
             break;
         default:
             var msgDlg = new MessageDialog("Not working yet!")
             {
                 DefaultCommandIndex = 1
             };
             await msgDlg.ShowAsync();
             break;
     }
 }
 private async void ExecuteBookmarkCommand(object param)
 {
     var thread = param as ForumThreadEntity;
     if (thread == null)
         return;
     var threadManager = new ThreadManager();
     if (thread.IsBookmark)
     {
         await threadManager.RemoveBookmarks(new List<long> { thread.ThreadId });
         return;
     }
     await threadManager.AddBookmarks(new List<long> { thread.ThreadId });
     var msgDlg2 =
            new MessageDialog(string.Format("'{0}' has been added to your bookmarks! I love you!{1}{2}",
                thread.Name, Environment.NewLine, Constants.ASCII_1))
            {
                DefaultCommandIndex = 1
            };
     await msgDlg2.ShowAsync();
 }
 private async void ExecuteUnreadCommand(object param)
 {
     var threadId = (Int64)param;
     var thread = ForumPageScrollingCollection.FirstOrDefault(node => node.ThreadId == threadId);
     if (thread == null)
         return;
     var threadManager = new ThreadManager();
     await threadManager.MarkThreadUnread(new List<long> { thread.ThreadId });
     thread.HasBeenViewed = false;
     thread.HasSeen = false;
     thread.ReplyCount = 0;
 }
Beispiel #12
0
        public async Task<ForumReplyEntity> GetReplyCookiesForEdit(long postId)
        {
            try
            {
                string url = string.Format(Constants.EDIT_BASE, postId);
                WebManager.Result result = await _webManager.DownloadHtml(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.DownloadHtml(url2);
                HtmlDocument doc2 = result2.Document;

                string htmlThread = await threadManager.GetThreadHtml(doc2);

                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;
            }
        }
Beispiel #13
0
 private async void WebView_ScriptNotify(object sender, NotifyEventArgs e)
 {
     string stringJson = e.Value;
     var command = JsonConvert.DeserializeObject<ReplyView.ThreadCommand>(stringJson);
     switch (command.Command)
     {
         case "profile":
             Frame.Navigate(typeof (UserProfileView), command.Id);
             break;
         case "post_history":
             Frame.Navigate(typeof (UserPostHistoryPage), command.Id);
             break;
         case "rap_sheet":
             Frame.Navigate(typeof (RapSheetView), command.Id);
             break;
         case "quote":
             Frame.Navigate(typeof (ReplyView), command.Id);
             break;
         case "edit":
             Frame.Navigate(typeof (EditReplyPage), command.Id);
             break;
         case "scrollToPost":
             if (command.Id != null)
             {
                 await ThreadFullView.InvokeScriptAsync("ScrollToDiv", new[] { string.Concat("#postId", command.Id) });
                 await ThreadSnapView.InvokeScriptAsync("ScrollToDiv", new[] { string.Concat("#postId", command.Id) });
             }
             else if (!string.IsNullOrEmpty(_vm.ForumThreadEntity.ScrollToPostString))
             {
                 ThreadFullView.InvokeScriptAsync("ScrollToDiv", new[] { _vm.ForumThreadEntity.ScrollToPostString });
                 ThreadSnapView.InvokeScriptAsync("ScrollToDiv", new[] { _vm.ForumThreadEntity.ScrollToPostString });
             }
             break;
         case "markAsLastRead":
             await _threadManager.MarkPostAsLastRead(_forumThread, Convert.ToInt32(command.Id));
             int nextPost = Convert.ToInt32(command.Id) + 1;
             await ThreadFullView.InvokeScriptAsync("ScrollToDiv", new[] { string.Concat("#postId", nextPost.ToString()) });
             await ThreadSnapView.InvokeScriptAsync("ScrollToDiv", new[] { string.Concat("#postId", nextPost.ToString()) });
             NotifyStatusTile.CreateToastNotification("Post marked as last read! Now smash this computer and live your life!");
             break;
         case "setFont":
             if (_localSettings.Values.ContainsKey("zoomSize"))
             {
                 _zoomSize = Convert.ToInt32(_localSettings.Values["zoomSize"]);
                 ThreadFullView.InvokeScriptAsync("ResizeWebviewFont", new[] { _zoomSize.ToString() });
                 ThreadSnapView.InvokeScriptAsync("ResizeWebviewFont", new[] { _zoomSize.ToString() });
             }
             else
             {
                 _zoomSize = 14;
             }
             break;
         case "openThread":
             // Because we are coming from an existing thread, rather than the thread lists, we need to get the thread information beforehand.
             // However, right now the managers are not set up to support this. The thread is getting downloaded twice, when it really only needs to happen once.
             var threadManager = new ThreadManager();
             var newThreadEntity = new ForumThreadEntity();
             var thread = await threadManager.GetThread(newThreadEntity, command.Id);
             if (thread == null)
             {
                 var error = new MessageDialog("Specified post was not found in the live forums.")
                 {
                     DefaultCommandIndex = 1
                 };
                 await error.ShowAsync();
                 break;
             }
             string jsonObjectString = JsonConvert.SerializeObject(newThreadEntity);
             Frame.Navigate(typeof(ThreadPage), jsonObjectString);
             break;
         default:
             var msgDlg = new MessageDialog("Not working yet!")
             {
                 DefaultCommandIndex = 1
             };
             await msgDlg.ShowAsync();
             break;
     }
 }
Beispiel #14
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);
            }
        }
Beispiel #15
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);
            }
        }
Beispiel #16
0
        private async void WebView_ScriptNotify(object sender, NotifyEventArgs e)
        {
            if (_vm.ForumThreadEntity == null)
            {
                return;
            }
            if (e == null)
            {
                return;
            }
            string stringJson = e.Value;
            ThreadCommand command = null;
            try
            {
                command = JsonConvert.DeserializeObject<ThreadCommand>(stringJson);
            }
            catch (Exception ex)
            {
                AwfulDebugger.SendMessageDialogAsync("A thread javascript command failed", ex);
            }
            if (command == null)
            {
                return;
            }
            switch (command.Command)
            {
                case "quote":
                    Frame.Navigate(typeof(ReplyPage), command.Id);
                    break;
                case "edit":
                    Frame.Navigate(typeof(EditPage), command.Id);
                    break;
                case "setFont":
                    SetFontSize();
                    break;
                case "scrollToPost":
                    if (!string.IsNullOrEmpty(_vm.ForumThreadEntity.ScrollToPostString))
                        try
                        {
                            await ThreadWebView.InvokeScriptAsync("ScrollToDiv", new[] { _vm.ForumThreadEntity.ScrollToPostString });
                        }
                        catch (Exception ex)
                        {
                            AwfulDebugger.SendMessageDialogAsync("A thread javascript command failed", ex);
                        }
                    break;
                case "markAsLastRead":
                    await _threadManager.MarkPostAsLastRead(_forumThread, Convert.ToInt32(command.Id));
                    int nextPost = Convert.ToInt32(command.Id) + 1;

                    try
                    {
                        await ThreadWebView.InvokeScriptAsync("ScrollToDiv", new[] { string.Concat("#postId", nextPost.ToString()) });
                    }
                    catch (Exception ex)
                    {
                        AwfulDebugger.SendMessageDialogAsync("A thread javascript command failed", ex);
                        return;
                    }
                    var message = new MessageDialog("Post marked as last read! Now go on and live your life!")
                        {
                            DefaultCommandIndex = 1
                        };
                    await message.ShowAsync();
                    break;
                case "openThread":
                      var query = Extensions.ParseQueryString(command.Id);
                    if (query.ContainsKey("action") && query["action"].Equals("showPost"))
                    {
                        var postManager = new PostManager();
                        try
                        {
                            var html = await postManager.GetPost(Convert.ToInt32(query["postid"]));
                        }
                        catch (Exception ex)
                        {
                            AwfulDebugger.SendMessageDialogAsync("A thread javascript command failed", ex);
                            return;
                        }
                        return;
                    }
                    var threadManager = new ThreadManager();
                    var threadEntity = new ForumThreadEntity();
                    var thread = await threadManager.GetThread(threadEntity, command.Id);
                    if (thread == null)
                    {
                        var error = new MessageDialog("Specified post was not found in the live forums.")
                        {
                            DefaultCommandIndex = 1
                        };
                        await error.ShowAsync();
                        break;
                    }
                    string jsonObjectString = JsonConvert.SerializeObject(threadEntity);
                    Frame.Navigate(typeof(ThreadPage), jsonObjectString);
                    break;
                default:
                    var msgDlg = new MessageDialog("Not working yet!")
                    {
                        DefaultCommandIndex = 1
                    };
                    await msgDlg.ShowAsync();
                    break;
            }
        }
 private async void WebView_ScriptNotify(object sender, NotifyEventArgs e)
 {
     string stringJson = e.Value;
     var command = JsonConvert.DeserializeObject<ThreadPage.ThreadCommand>(stringJson);
     switch (command.Command)
     {
         case "openThread":
             // Because we are coming from an existing thread, rather than the thread lists, we need to get the thread information beforehand.
             // However, right now the managers are not set up to support this. The thread is getting downloaded twice, when it really only needs to happen once.
             var threadManager = new ThreadManager();
             var thread = await threadManager.GetThread(new ForumThreadEntity(), command.Id);
             if (thread == null)
             {
                 var error = new MessageDialog("Specified post was not found in the live forums.")
                 {
                     DefaultCommandIndex = 1
                 };
                 await error.ShowAsync();
                 break;
             }
             string jsonObjectString = JsonConvert.SerializeObject(thread);
             Frame.Navigate(typeof(ThreadPage), jsonObjectString);
             break;
     }
 }
Beispiel #18
0
 private async void ThreadWebView_ScriptNotify(object sender, NotifyEventArgs e)
 {
     string stringJson = e.Value;
     var command = JsonConvert.DeserializeObject<EditPage.ThreadCommand>(stringJson);
     var replyManager = new ReplyManager();
     switch (command.Command)
     {
         case "quote":
             LoadingProgressBar.Visibility = Visibility.Visible;
             string quoteString = await replyManager.GetQuoteString(Convert.ToInt64(command.Id));
             quoteString = string.Concat(Environment.NewLine, quoteString);
             string replyText = string.IsNullOrEmpty(ReplyTextBox.Text) ? string.Empty : ReplyTextBox.Text;
             if (replyText != null) ReplyTextBox.Text = replyText.Insert(ReplyTextBox.Text.Length, quoteString);
             LoadingProgressBar.Visibility = Visibility.Collapsed;
             break;
         case "edit":
             //Frame.Navigate(typeof(EditReplyPage), command.Id);
             break;
         case "openThread":
             // Because we are coming from an existing thread, rather than the thread lists, we need to get the thread information beforehand.
             // However, right now the managers are not set up to support this. The thread is getting downloaded twice, when it really only needs to happen once.
             var threadManager = new ThreadManager();
             var thread = await threadManager.GetThread(new ForumThreadEntity(), command.Id);
             if (thread == null)
             {
                 var error = new MessageDialog("Specified post was not found in the live forums.")
                 {
                     DefaultCommandIndex = 1
                 };
                 await error.ShowAsync();
                 break;
             }
             string jsonObjectString = JsonConvert.SerializeObject(thread);
             Frame.Navigate(typeof(ThreadPage), jsonObjectString);
             break;
         case "setFont":
             break;
         default:
             var msgDlg = new MessageDialog("Not working yet!")
             {
                 DefaultCommandIndex = 1
             };
             await msgDlg.ShowAsync();
             break;
     }
 }