示例#1
0
        public static SAPost Build(HtmlNode node, SAThreadPage page)
        {
            SAPost result = null;
            Awful.Core.Event.Logger.AddEntry("SAPost - Parsing postNode for html...");

            int id = Factory.ParsePostID(node);
            try
            {
                result = new SAPost();
                result.ID = id;
                result.ThreadPageID = page.ID;
                Factory.ParseSeenUrl(result, node);
                Factory.ParseAuthor(result, node);
                Factory.ParsePostDate(result, node);
                Factory.ParseUserID(result, node);
                result.ContentNode = Factory.ParseContent(node);
                Factory.ParseHasSeen(result, node);
                Factory.ParseIcon(result, node);
            }

            catch (Exception ex)
            {
                string error = string.Format("An error occured while processing the post to the database. [{0}] {1}",
                    ex.Message, ex.StackTrace);

                Awful.Core.Event.Logger.AddEntry(error);
            }

            return result;
        }
示例#2
0
        private string BuildPreviewHtml(HtmlNode node)
        {
            SAPost post = new SAPost();
            post.PostAuthor = "Post Preview";
            post.PostDate = DateTime.Now;
            post.ShowPostIcon = false;
            post.PostIndex = 1;

            var previewContentNode = node.Descendants("div")
                .Where(n => n.GetAttributeValue("class", "").Contains("postbody"))
                .FirstOrDefault();

            if (previewContentNode != null)
            {
                post.ContentNode = previewContentNode;
                this.Posts = new List<PostData>(1);
                this.Posts.Add(post);
            }

            string content = PostWebViewContentItemBuilder.MergePostsToHtml(this.Posts);
            return content;
        }
示例#3
0
        private void ParseAuthor(SAPost post, HtmlNode postNode)
        {
            var authorNode = postNode.Descendants()
              .Where(node =>
                  (node.GetAttributeValue("class", "").Equals("author")) ||
                  (node.GetAttributeValue("title", "").Equals("Administrator")) ||
                  (node.GetAttributeValue("title", "").Equals("Moderator")))
              .FirstOrDefault();

            if (authorNode != null)
            {
                var type = authorNode.GetAttributeValue("title", "");
                switch (type)
                {
                    case "Administrator":
                        post.AccountType = Models.AccountType.Admin;
                        break;

                    case "Moderator":
                        post.AccountType = Models.AccountType.Moderator;
                        break;

                    default:
                        post.AccountType = Models.AccountType.Normal;
                        break;
                }

                post.PostAuthor = authorNode.InnerText;
            }

            else
            {
                post.PostAuthor = "SAPoster";
                post.AccountType = Models.AccountType.Normal;
            }

            post.PostAuthor = ContentFilter.Censor(post.PostAuthor);
        }
示例#4
0
        private void HandleMark(SAPost post)
        {
            var confirm = MessageBox.Show("Mark this post as last read?", ":o", MessageBoxButton.OKCancel);
            if (confirm == MessageBoxResult.Cancel)
                return;

            App.IsBusy = true;
            threadSvc.MarkThreadToPostAsync(post, result =>
            {
                if (result == Awful.Core.Models.ActionResult.Success)
                    MessageBox.Show("Mark successful.", ":)", MessageBoxButton.OK);
                else
                    MessageBox.Show("Mark failed.", ":(", MessageBoxButton.OK);

                App.IsBusy = false;
            });
        }
示例#5
0
        public void MarkThreadToPostAsync(SAPost post, Action<Awful.Core.Models.ActionResult> result)
        {
            if (Awful.Core.Event.Logger.IsEnabled)
            {
                Awful.Core.Event.Logger.AddEntry(
                    string.Format("MarkThreadToPost - PostID: {0}", post.ID));
            }

            var markUrl = post.MarkSeenUrl;
            RunURLTaskAsync(markUrl, result);
        }
示例#6
0
        private Brush HandleForeground(SAPost post)
        {
            if (post != null && post.HasSeen)
                return new SolidColorBrush() { Color = App.Layout.CurrentTheme.PostHasSeen };

            return new SolidColorBrush() { Color = App.Layout.CurrentTheme.PostForeground };
        }
示例#7
0
        private object HandleAccountType(SAPost post)
        {
            var colorString = ((Color)App.Current.Resources["PhoneForegroundColor"]).ToString();

            if (post == null)
                return colorString;

            switch (post.AccountType)
            {
                case AccountType.Moderator:
                    colorString = "gold";
                    break;

                case AccountType.Admin:
                    colorString = "red";
                    break;
            }

            return colorString;
        }
        private static string AppendPostAuthor(SAPost post)
        {
            var color = string.Empty;
            switch (post.AccountType)
            {
                case AccountType.Admin:
                    color = "style='color:red; font-size: large'";
                    break;

                case AccountType.Moderator:
                    color = "style='color:yellow; font-size: large'";
                    break;

                case AccountType.Normal:
                    color = string.Format("style='color:#{0}; font-size: large'", Globals.Resources.Foreground.ToString().Substring(3));
                    break;
            }
              return string.Format("<span class='text_title3style' {1}>{0}</span><br/>", post.PostAuthor, color);
        }
        private void ScrollToPost(SAPost post)
        {
            if (post == null) return;

            string smooth;

            if (App.Settings.SmoothScrolling == true)
            {
                smooth = "true";
                ThreadContentView.InvokeScript("scrollTo", "postlink" + post.PostIndex, smooth);
            }
            else
            {
                smooth = "false";
                ThreadContentView.InvokeScript("scrollTo", "post_" + post.PostIndex, smooth);
            }
        }
示例#10
0
        private void ParseIcon(SAPost post, HtmlNode postNode)
        {
            try
            {
                 post.PostIconUri = postNode.Descendants()
                    .Where(node => node.GetAttributeValue("class", "").Equals("title"))
                    .First()
                    .Descendants("img")
                    .First()
                    .GetAttributeValue("src", "");

                post.ShowPostIcon = true;
            }

            catch (Exception)
            {
                post.PostIconUri = null;
                post.ShowPostIcon = false;
            }
        }
 private void PostJumpListItemTap(object sender, Telerik.Windows.Controls.GroupPickerItemTapEventArgs e)
 {
     _selectedPost = e.DataItem as SAPost;
 }
示例#12
0
        private void ParseUserID(SAPost post, HtmlNode postNode)
        {
            var userIDNode = postNode.Descendants()
                .Where(node => node.GetAttributeValue("class", "").Contains("userid"))
                .FirstOrDefault();

            if (userIDNode != null)
            {
                string value = userIDNode.GetAttributeValue("class", "");
                value = value.Replace("userinfo userid-", "");
                int userid = 0;
                int.TryParse(value, out userid);
                post.UserID = userid;
            }
        }
示例#13
0
        private void ParseSeenUrl(SAPost post, HtmlNode postNode)
        {
            var seenUrlNode = postNode.Descendants("a")
                .Where(node => node.GetAttributeValue("title", "").Equals("Mark thread seen up to this post"))
                .FirstOrDefault();

            if (seenUrlNode == null)
            {
                post.MarkSeenUrl = String.Empty;
            }

            else
            {
                // make sure the string is in the right format so the uri class can parse correctly.
                var nodeValue = seenUrlNode.GetAttributeValue("href", "");
                post.MarkSeenUrl = string.Format("http://forums.somethingawful.com{0}", HttpUtility.HtmlDecode(nodeValue));
            }
        }
示例#14
0
        private void ParsePostDate(SAPost post, HtmlNode postNode)
        {
            var postDateNode = postNode.Descendants()
              .Where(node => node.GetAttributeValue("class", "").Equals("postdate"))
              .FirstOrDefault();

            var postDateString = postDateNode == null ? string.Empty : postDateNode.InnerText;

            post.PostDate = postDateNode == null ? default(DateTime) :
                Convert.ToDateTime(postDateString.SanitizeDateTimeHTML());
        }
示例#15
0
 private void HandleQuote(SAPost post)
 {
     App.IsBusy = true;
     string id = post.ID.ToString();
     replySvc.GetQuote(id, (result, text) =>
     {
         ContentLoaded.Fire<WebContentLoadedEventArgs>(this, new WebContentLoadedEventArgs(RequestType.Quote, text));
         App.IsBusy = false;
     });
 }
 private void PostJumpList_CloseAnimationEnded(object sender, EventArgs e)
 {
     if (_selectedPost != null)
     {
         this._reloaded = true;
         ScrollToPost(_selectedPost);
         this._selectedPost = null;
         ThreadContentView.Visibility = System.Windows.Visibility.Visible;
         PostJumpList.Visibility = System.Windows.Visibility.Collapsed;
     }
 }
示例#17
0
        private void ParseHasSeen(SAPost post, HtmlNode postNode)
        {
            var hasSeenMarker = postNode.Descendants("tr")
                .Where(node => node.GetAttributeValue("class", "").Contains(HAS_SEEN_FLAG))
                .FirstOrDefault();

            var hasNotSeenMarker = postNode.Descendants("img")
            .Where(node => node.GetAttributeValue("src", "")
                .Equals(HAS_NOT_SEEN_URL)).FirstOrDefault();

            bool firstGuess = hasSeenMarker != null;
            bool secondGuess = hasNotSeenMarker == null;

            post.HasSeen = firstGuess || secondGuess;
        }