Exemple #1
0
        private static ThreadPostMetadata ParsePostThreadIndexAndMarkUrl(this ThreadPostMetadata post, HtmlNode postNode)
        {
            var seenUrlNode = postNode.Descendants("a")
                              .Where(node => node.GetAttributeValue("class", "").Contains(MARK_THREAD_CLASS_ID))
                              .FirstOrDefault();

            if (seenUrlNode == null)
            {
                post.ThreadIndex = -1;
            }

            else
            {
                // make sure the string is in the right format so the uri class can parse correctly.
                var nodeValue = seenUrlNode.GetAttributeValue("href", "");
                post.MarkPostUri = new Uri(string.Format("http://forums.somethingawful.com{0}",
                                                         HttpUtility.HtmlDecode(nodeValue)), UriKind.Absolute);
                int    index      = -1;
                string indexValue = nodeValue.Split('&').LastOrDefault();
                if (indexValue != null)
                {
                    indexValue       = indexValue.Split('=').Last();
                    post.ThreadIndex = int.TryParse(indexValue, out index)
                        ? index
                        : -1;
                }
            }

            return(post);
        }
Exemple #2
0
        private static ThreadPageMetadata ParsePostTable(this ThreadPageMetadata page, HtmlNode top)
        {
            if (page.Posts == null)
            {
                page.Posts = new List <ThreadPostMetadata>();
            }

            AwfulDebugger.AddLog(top, AwfulDebugger.Level.Debug, "Parsing post data...");

            var postArray = top.Descendants(THREAD_POST_HTML_ELEMENT)
                            .Where(tables => tables.GetAttributeValue(THREAD_POST_HTML_ATTRIBUTE, "").Equals(THREAD_POST_HTML_VALUE))
                            .ToArray();

            int index = 1;

            foreach (var postNode in postArray)
            {
                ThreadPostMetadata post = PostParser.ParsePost(postNode);
                post.PageIndex = index;
                page.Posts.Add(post);
                index++;
            }

            // check if there is at least one post on the page. If not, there was a parsing error.
            if (page.Posts.Count == 0)
            {
                throw new Exception("Parse Error: Could not parse the posts on this page.");
            }

            AwfulDebugger.AddLog(top, AwfulDebugger.Level.Debug, "Thread page parsing complete.");

            return(page);
        }
Exemple #3
0
 public static void MarkAsLastReadAsync(ThreadPostMetadata post, Action <bool> predicate)
 {
     ThreadPool.QueueUserWorkItem((markedPost) =>
     {
         bool marked = MarkAsLastRead(markedPost as ThreadPostMetadata);
         predicate(marked);
     }, post);
 }
Exemple #4
0
 public static void QuoteAsync(ThreadPostMetadata post, Action <string> predicate)
 {
     ThreadPool.QueueUserWorkItem((markedPost) =>
     {
         string quote = Quote(markedPost as ThreadPostMetadata);
         predicate(quote);
     }, post);
 }
Exemple #5
0
        private Uri SendEdit(ThreadPostMetadata post, string text)
        {
            PostEditData data = new PostEditData()
            {
                POSTID = post.PostID, TEXT = text
            };

            return(InitiateEditRequest(data));
        }
Exemple #6
0
        public static ThreadPostMetadata AsSample(this ThreadPostMetadata data)
        {
            var random = new Random();

            data.Author      = "Sample Author";
            data.AuthorType  = ThreadPostMetadata.PostType.Moderator;
            data.IsNew       = true;
            data.PostID      = random.Next().ToString();
            data.ThreadIndex = random.Next(0, 100);
            data.PostDate    = DateTime.Now;
            data.PostBody    = HtmlTextNode.CreateNode("<p>Sample Post Body.</p>");
            return(data);
        }
Exemple #7
0
        public static ThreadPostMetadata ParsePost(HtmlNode postNode)
        {
            ThreadPostMetadata post = new ThreadPostMetadata()
                                      .ParseIcon(postNode)
                                      .ParseAuthor(postNode)
                                      .ParseContent(postNode)
                                      .ParsePostDate(postNode)
                                      .ParsePostID(postNode)
                                      .ParseUserID(postNode)
                                      .ParsePostThreadIndexAndMarkUrl(postNode)
                                      .ParseIsEditable(postNode)
                                      .ParseHasSeen(postNode);

            return(post);
        }
Exemple #8
0
        private static ThreadPostMetadata ParseUserID(this ThreadPostMetadata 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-", "");
                post.UserID = value;
            }

            return(post);
        }
Exemple #9
0
        private static ThreadPostMetadata ParseContent(this ThreadPostMetadata post, HtmlNode postNode)
        {
            var content = postNode.Descendants("td")
                          .Where(node => node.GetAttributeValue("class", "")
                                 .Equals("postbody"))
                          .FirstOrDefault();

            if (content == null)
            {
                throw new ArgumentException("Content should not be null");
            }

            post.PostBody = content;
            return(post);
        }
Exemple #10
0
        private static ThreadPostMetadata ParsePostID(this ThreadPostMetadata post, HtmlNode postNode)
        {
            string idValue = postNode.GetAttributeValue(POST_ID_ATTRIBUTE, "");

            string result = null;

            if (idValue != null)
            {
                string postID = idValue.Replace("post", "");
                result = postID;
            }

            post.PostID = result;
            return(post);
        }
Exemple #11
0
        private static ThreadPostMetadata ParseHasSeen(this ThreadPostMetadata post, HtmlNode postNode)
        {
            var hasSeenMarker = postNode.Descendants("tr")
                                .Where(node => node.GetAttributeValue("class", "").Contains(CoreConstants.LASTREAD_FLAG))
                                .FirstOrDefault();

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

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

            post.IsNew = !(firstGuess || secondGuess);
            return(post);
        }
Exemple #12
0
 public static ThreadPageMetadata AsSample(this ThreadPageMetadata data)
 {
     data.ThreadTitle = "Sample Thread Title";
     data.ThreadID    = "1";
     data.LastPage    = 10;
     data.PageNumber  = 1;
     data.RawHtml     = "<html><head/><body>Sample Page Html</body></html>";
     data.Posts       = new List <ThreadPostMetadata>(10);
     for (int i = 0; i < 10; i++)
     {
         var post = new ThreadPostMetadata().AsSample();
         post.PageIndex = i + 1;
         data.Posts.Add(post);
     }
     return(data);
 }
Exemple #13
0
        private static ThreadPostMetadata ParseIsEditable(this ThreadPostMetadata post, HtmlNode postNode)
        {
            var postbuttons = postNode.Descendants("ul")
                              .Where(node => node.GetAttributeValue("class", string.Empty).Equals("postbuttons"))
                              .SingleOrDefault();

            if (postbuttons != null)
            {
                var editButton = postbuttons.Descendants("img")
                                 .Where(node => node.GetAttributeValue("alt", string.Empty).Contains("Edit"))
                                 .SingleOrDefault();

                post.IsEditable = editButton != null;
            }

            return(post);
        }
Exemple #14
0
        private static ThreadPostMetadata ParsePostDate(this ThreadPostMetadata post, HtmlNode postNode)
        {
            var postDateNode = postNode.Descendants()
                               .Where(node => node.GetAttributeValue("class", "").Equals("postdate"))
                               .FirstOrDefault();

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

            try
            {
                post.PostDate = postDateNode == null ? default(DateTime) :
                                Convert.ToDateTime(postDateString.SanitizeDateTimeHTML());
            }

            catch (Exception)
            {
                post.PostDate = DateTime.Parse(postDateString.SanitizeDateTimeHTML(), System.Globalization.CultureInfo.InvariantCulture);
            }

            return(post);
        }
Exemple #15
0
        private static string AppendPostAuthor(ThreadPostMetadata post)
        {
            string style = string.Empty;

            switch (post.AuthorType)
            {
            case ThreadPostMetadata.PostType.Administrator:
                style = "admin_post";
                break;

            case ThreadPostMetadata.PostType.Moderator:
                style = "mod_post";
                break;

            case ThreadPostMetadata.PostType.Standard:
                style = "user_post";
                break;
            }

            return(string.Format("<span class='text_title3style'><span class='{0}'>{1}</span></span><br/>", style, post.Author));
        }
Exemple #16
0
        private static ThreadPostMetadata ParseAuthor(this ThreadPostMetadata post, HtmlNode postNode)
        {
            var authorNode = postNode.Descendants()
                             .Where(node =>
                                    (node.GetAttributeValue("class", "").Equals("author")) ||
                                    (node.GetAttributeValue("class", "").Equals("author op")) ||
                                    (node.GetAttributeValue("title", "").Equals("Administrator")) ||
                                    (node.GetAttributeValue("title", "").Equals("Moderator")))
                             .FirstOrDefault();

            if (authorNode != null)
            {
                var type = authorNode.GetAttributeValue("title", "");
                switch (type)
                {
                case "Administrator":
                    post.AuthorType = ThreadPostMetadata.PostType.Administrator;
                    break;

                case "Moderator":
                    post.AuthorType = ThreadPostMetadata.PostType.Moderator;
                    break;

                default:
                    post.AuthorType = ThreadPostMetadata.PostType.Standard;
                    break;
                }

                post.Author = authorNode.InnerText;
            }

            else
            {
                post.Author     = "AwfulPoster";
                post.AuthorType = ThreadPostMetadata.PostType.Standard;
            }

            return(post);
        }
Exemple #17
0
        private static ThreadPostMetadata ParseIcon(this ThreadPostMetadata post, HtmlNode postNode)
        {
            try
            {
                var uriString = postNode.Descendants()
                                .Where(node => node.GetAttributeValue("class", "").Equals("title"))
                                .First()
                                .Descendants("img")
                                .First()
                                .GetAttributeValue("src", "");

                post.PostIconUri = new Uri(uriString, UriKind.Absolute);
                post.ShowIcon    = true;
            }

            catch (Exception)
            {
                post.PostIconUri = null;
                post.ShowIcon    = false;
            }

            return(post);
        }
Exemple #18
0
        private string GetEdit(ThreadPostMetadata post)
        {
            var url = string.Format("http://forums.somethingawful.com/editpost.php?action=editpost&postid={0}", post.PostID);

            return(BeginGetTextFromWebForm(url));
        }
Exemple #19
0
 public static IThreadPostRequest BeginEdit(this ThreadPostMetadata post)
 {
     return(AwfulContentRequest.Threads.BeginPostEdit(post.PostID));
 }
Exemple #20
0
 public static bool MarkAsRead(this ThreadPostMetadata post)
 {
     return(AwfulContentRequest.Threads.MarkPostAsRead(post));
 }
Exemple #21
0
 public static string Quote(this ThreadPostMetadata post)
 {
     return(AwfulContentRequest.Threads.QuotePost(post.PostID));
 }
Exemple #22
0
 public static bool MarkAsLastRead(ThreadPostMetadata post)
 {
     return(RunURLTask(post.MarkPostUri));
 }
Exemple #23
0
 public static string Quote(ThreadPostMetadata post)
 {
     return(instance.QuotePost(post));
 }
 public abstract bool MarkPostAsRead(ThreadPostMetadata post);
Exemple #25
0
 public static string Quote(ThreadPostMetadata post)
 {
     return(ThreadReplyTask.Quote(post));
 }
Exemple #26
0
 public static Uri Edit(ThreadPostMetadata post, string text)
 {
     return(instance.SendEdit(post, text));
 }
Exemple #27
0
 public static string FetchEditText(ThreadPostMetadata post)
 {
     return(instance.GetEdit(post));
 }
Exemple #28
0
 public static string FetchEditText(ThreadPostMetadata post)
 {
     return(ThreadReplyTask.FetchEditText(post));
 }
Exemple #29
0
        private string QuotePost(ThreadPostMetadata post)
        {
            var url = string.Format("http://forums.somethingawful.com/newreply.php?action=newreply&postid={0}", post.PostID);

            return(BeginGetTextFromWebForm(url));
        }
Exemple #30
0
 public static Uri Edit(ThreadPostMetadata post, string text)
 {
     return(ThreadReplyTask.Edit(post, text));
 }