Exemplo n.º 1
0
 public Post(Int32 threadId, Int32 postId, String poster, Int32 posterId, Int32 postNumber, DateTimeOffset ts,
             String postLink, String postTitle, String content, List <Bold> bolded, PostEdit edit)
 {
     Poster     = new Poster(poster, posterId);
     PostNumber = postNumber;
     Time       = ts.ToUniversalTime();
     PostLink   = postLink;
     PostId     = postId;
     Title      = postTitle;
     Edit       = edit;
     _content   = content;
     ThreadId   = threadId;
     _bolded    = bolded;
 }
Exemplo n.º 2
0
        protected override Post HtmlToPost(Int32 threadId, HtmlAgilityPack.HtmlNode html, DateTimeOffset pageTime)
        {
            string         posterName = "";
            Int32          postNumber = 0;
            String         postLink   = null;
            Int32          postId     = -1;
            DateTimeOffset postTime   = DateTime.Now;

            HtmlAgilityPack.HtmlNode postNumberNode = html.SelectSingleNode("div[@class='posthead']/span[@class='nodecontrols']/a[2]");

            if (postNumberNode != null)
            {
                String postNumberText = postNumberNode.Attributes["name"].Value;
                postNumber = Int32.Parse(postNumberText);
            }

            HtmlAgilityPack.HtmlNode postLinkNode = html.SelectSingleNode("div[@class='posthead']/span[@class='nodecontrols']/a[1]");
            if (postLinkNode != null)
            {
                postLink = HtmlAgilityPack.HtmlEntity.DeEntitize(postLinkNode.Attributes["href"].Value);
                if (postLink.Length > 3)
                {
                    // showthread.php?12931-Mafia-Convo-Thread&p=316289&viewfull=1#post316289
                    int startQuery = postLink.IndexOf('?');
                    if (startQuery > -1)
                    {
                        postLink = postLink.Substring(startQuery);
                    }
                    string sPost = HttpUtility.ParseQueryString(postLink).Get("p");
                    Int32.TryParse(sPost, out postId);
                }
            }

            RemoveComments(html);
            HtmlAgilityPack.HtmlNode postTimeNode = html.SelectSingleNode("div[@class='posthead']/span[1]/span[@class='date']");
            if (postTimeNode != null)
            {
                string date = postTimeNode.InnerText;
                date = HtmlAgilityPack.HtmlEntity.DeEntitize(date);
                //string time = postTimeNode.ChildNodes[1].InnerText;
                postTime = ParseItemTime(pageTime, date);
                //Trace.TraceInformation("Post time: {0}", postTime.DateTime.ToShortTimeString());
            }
            String postTitle = "";

            HtmlAgilityPack.HtmlNode titleNode = html.SelectSingleNode("div[@class='postdetails']/div[@class='postbody']/div[1]/h2");
            if (titleNode != null)
            {
                postTitle = HtmlAgilityPack.HtmlEntity.DeEntitize(titleNode.InnerText).Trim();
                //Trace.TraceInformation("title[{0}]:{1} ", postNumber, postTitle);
            }

            HtmlAgilityPack.HtmlNode editNode = html.SelectSingleNode("../div[@class='smallfont']/em");
            PostEdit edit = null;

            if (editNode != null)
            {
                String postEdit = HtmlAgilityPack.HtmlEntity.DeEntitize(editNode.InnerText);
                postEdit = postEdit.Trim();
                // Last edited by well named; 09-03-2012 at 08:50 PM. Reason: people who are out will receive the special ******* role
                String regex = @"Last edited by (.*); (.*)\.(?:\s*Reason: (.*))?";
                Match  m     = Regex.Match(postEdit, regex);
                if (m.Success)
                {
                    String         editor   = m.Groups[1].Value;
                    String         when     = m.Groups[2].Value;
                    DateTimeOffset editTime = ParseItemTime(pageTime, when);
                    String         editText = null;
                    if (m.Groups.Count > 2)
                    {
                        editText = m.Groups[3].Value.Trim();
                    }
                    edit = new PostEdit(editor, editTime, editText);
                }
            }

            Int32 posterId = -1;

            HtmlAgilityPack.HtmlNode userNode = html.SelectSingleNode("div[@class='postdetails']/div[@class='userinfo']/div[@class='username_container']/div[@class='popupmenu memberaction']/a");
            if (userNode != null)
            {
                posterName = HtmlAgilityPack.HtmlEntity.DeEntitize(userNode.InnerText);
                String profile = userNode.Attributes["href"].Value;
                posterId = Misc.ParseMemberId(profile);
            }
            HtmlAgilityPack.HtmlNode postContent = html.SelectSingleNode("div[@class='postdetails']/div[@class='postbody']/div[1]/div[@class='content']/div/blockquote");
            List <Bold> bolded = ParseBolded(postContent);
            Post        p      = new Post(threadId, postId, posterName, posterId, postNumber, postTime, postLink, postTitle,
                                          postContent.OuterHtml, bolded, edit);

            return(p);
        }
Exemplo n.º 3
0
        protected virtual Post HtmlToPost(Int32 threadId, HtmlAgilityPack.HtmlNode html, DateTimeOffset pageTime)
        {
            string         posterName = "";
            Int32          postNumber = 0;
            String         postLink   = null;
            Int32          postId     = -1;
            DateTimeOffset postTime   = DateTime.Now;

            HtmlAgilityPack.HtmlNode postNumberNode = html.SelectSingleNode("../../../tr[1]/td[2]/a[last()]");

            if (postNumberNode != null)
            {
                postNumber = Int32.Parse(postNumberNode.InnerText);
                postLink   = HtmlAgilityPack.HtmlEntity.DeEntitize(postNumberNode.Attributes["href"].Value);
                if (postLink.Length > 3)
                {
                    // showthread.php?12931-Mafia-Convo-Thread&p=316289&viewfull=1#post316289
                    String sPost      = postLink;
                    int    startQuery = sPost.IndexOf('?');
                    if (startQuery > -1)
                    {
                        sPost = sPost.Substring(startQuery);
                    }
                    sPost = HttpUtility.ParseQueryString(sPost).Get("p");
                    Int32.TryParse(sPost, out postId);
                    int startPage = postLink.LastIndexOf('/');
                    if (startPage > -1)
                    {
                        postLink = postLink.Substring(startPage + 1);
                    }
                }
            }
            RemoveComments(html);
            HtmlAgilityPack.HtmlNode postTimeNode = html.SelectSingleNode("../../../tr[1]/td[1]");
            if (postTimeNode != null)
            {
                string time = postTimeNode.InnerText.Trim();
                postTime = ParseItemTime(pageTime, time);
                //Trace.TraceInformation("Post time: {0}", postTime.DateTime.ToShortTimeString());
            }
            String postTitle = "";

            HtmlAgilityPack.HtmlNode titleNode = html.SelectSingleNode("../div[@class='smallfont']/strong");
            if (titleNode != null)
            {
                postTitle = HtmlAgilityPack.HtmlEntity.DeEntitize(titleNode.InnerText);
                //Trace.TraceInformation("title[{0}]:{1} ", postNumber, postTitle);
            }

            HtmlAgilityPack.HtmlNode editNode = html.SelectSingleNode("../div[@class='smallfont']/em");
            PostEdit edit = null;

            if (editNode != null)
            {
                String postEdit = HtmlAgilityPack.HtmlEntity.DeEntitize(editNode.InnerText);
                postEdit = postEdit.Trim();
                // Last edited by well named; 09-03-2012 at 08:50 PM. Reason: people who are out will receive the special ******* role
                String regex = @"Last edited by (.*); (.*)\.(?:\s*Reason: (.*))?";
                Match  m     = Regex.Match(postEdit, regex);
                if (m.Success)
                {
                    String         editor   = m.Groups[1].Value;
                    String         when     = m.Groups[2].Value;
                    DateTimeOffset editTime = ParseItemTime(pageTime, when);
                    String         editText = null;
                    if (m.Groups.Count > 2)
                    {
                        editText = m.Groups[3].Value.Trim();
                    }
                    edit = new PostEdit(editor, editTime, editText);
                }
            }

            Int32 posterId = -1;

            HtmlAgilityPack.HtmlNode userNode = html.SelectSingleNode("../../td[1]/div/a[starts-with(@class,'bigusername')]");
            if (userNode != null)
            {
                posterName = HtmlAgilityPack.HtmlEntity.DeEntitize(userNode.InnerText);
                String profile = userNode.Attributes["href"].Value;
                posterId = Misc.ParseMemberId(profile);
            }
            List <Bold> bolded = ParseBolded(html);
            Post        p      = new Post(threadId, postId, posterName, posterId, postNumber, postTime, postLink, postTitle,
                                          html.OuterHtml, bolded, edit);

            return(p);
        }
Exemplo n.º 4
0
 public Post(Int32 threadId, String poster, Int32 posterId, Int32 postNumber, DateTimeOffset ts,
             Int32 postId, String postTitle, String content, List <Bold> bolded, PostEdit edit) :
     this(threadId, postId, poster, posterId,
          postNumber, ts, "", postTitle, content, bolded, edit)
 {
     PostId = postId;
 }