Exemplo n.º 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 async void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
 {
     var jsonObjectString = (string)e.NavigationParameter;
     var forumInfo = JsonConvert.DeserializeObject<ForumEntity>(jsonObjectString);
     if (forumInfo == null) return;
     pageTitle.Text = string.Format("New Thread - {0}", forumInfo.Name);
     _forumEntity = forumInfo;
     _newThreadEntity = await _threadManager.GetThreadCookies(forumInfo.ForumId);
     if (_newThreadEntity == null)
     {
         var msgDlg = new MessageDialog("You can't make a new thread in this forum!");
         await msgDlg.ShowAsync();
         Frame.GoBack();
         return;
     }
     var blankPostIconEntity = new PostIconEntity {Id = 0, Title = "Shit"};
     PostIconImage.Source = new BitmapImage(new Uri("ms-appx://Assets/shitpost.gif"));
     _postIcon = blankPostIconEntity;
 }
Exemplo n.º 2
0
        public async Task<bool> CreateNewThread(NewThreadEntity newThreadEntity)
        {
            if (newThreadEntity == null)
                return false;
            var form = new MultipartFormDataContent
            {
                {new StringContent("postthread"), "action"},
                {new StringContent(newThreadEntity.Forum.ForumId.ToString(CultureInfo.InvariantCulture)), "forumid"},
                {new StringContent(newThreadEntity.FormKey), "formkey"},
                {new StringContent(newThreadEntity.FormCookie), "form_cookie"},
                {new StringContent(newThreadEntity.PostIcon.Id.ToString(CultureInfo.InvariantCulture)), "iconid"},
                {new StringContent(HtmlEncode(newThreadEntity.Subject)), "subject"},
                {new StringContent(HtmlEncode(newThreadEntity.Content)), "message"},
                {new StringContent(newThreadEntity.ParseUrl.ToString()), "parseurl"},
                {new StringContent("Submit Reply"), "submit"}
            };
            HttpResponseMessage response = await _webManager.PostFormData(Constants.NEW_THREAD_BASE, form);

            return response.IsSuccessStatusCode;
        }
Exemplo n.º 3
0
        public async Task<string> CreateNewThreadPreview(NewThreadEntity newThreadEntity)
        {
            if (newThreadEntity == null)
                return string.Empty;
            var form = new MultipartFormDataContent
            {
                {new StringContent("postthread"), "action"},
                {new StringContent(newThreadEntity.Forum.ForumId.ToString(CultureInfo.InvariantCulture)), "forumid"},
                {new StringContent(newThreadEntity.FormKey), "formkey"},
                {new StringContent(newThreadEntity.FormCookie), "form_cookie"},
                {new StringContent(newThreadEntity.PostIcon.Id.ToString(CultureInfo.InvariantCulture)), "iconid"},
                {new StringContent(HtmlEncode(newThreadEntity.Subject)), "subject"},
                {new StringContent(HtmlEncode(newThreadEntity.Content)), "message"},
                {new StringContent(newThreadEntity.ParseUrl.ToString()), "parseurl"},
                {new StringContent("Submit Post"), "submit"},
                {new StringContent("Preview Post"), "preview"}
            };

            // We post to SA the same way we would for a normal reply, but instead of getting a redirect back to the
            // thread, we'll get redirected to back to the reply screen with the preview message on it.
            // From here we can parse that preview and return it to the user.

            HttpResponseMessage response = await _webManager.PostFormData(Constants.NEW_THREAD_BASE, form);
            Stream stream = await response.Content.ReadAsStreamAsync();
            using (var reader = new StreamReader(stream))
            {
                string html = reader.ReadToEnd();
                var doc = new HtmlDocument();
                doc.LoadHtml(html);
                HtmlNode[] replyNodes = doc.DocumentNode.Descendants("div").ToArray();

                HtmlNode previewNode =
                    replyNodes.FirstOrDefault(node => node.GetAttributeValue("class", "").Equals("inner postbody"));
                return previewNode == null ? string.Empty : FixPostHtml(previewNode.OuterHtml);
            }
        }
Exemplo n.º 4
0
        public async Task<NewThreadEntity> GetThreadCookies(long forumId)
        {
            try
            {
                string url = string.Format(Constants.NEW_THREAD, forumId);
                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"));

                var newForumEntity = new NewThreadEntity();
                try
                {
                    string formKey = formKeyNode.GetAttributeValue("value", "");
                    string formCookie = formCookieNode.GetAttributeValue("value", "");
                    newForumEntity.FormKey = formKey;
                    newForumEntity.FormCookie = formCookie;
                    return newForumEntity;
                }
                catch (Exception)
                {
                    throw new InvalidOperationException("Could not parse new thread form data.");
                }
            }
            catch (Exception)
            {
                return null;
            }
        }