Exemple #1
0
 public SectionThread(int id, Section section)
     : base(id)
 {
     Section     = section;
     InitialPost = new SectionPost(0, this);
     Tags        = new List <string>();
     PageCount   = 1;
 }
Exemple #2
0
        /// <summary>
        /// Retrieves a list of all posts in the <c>SectionThread</c>
        /// </summary>
        /// <param name="session"> Session used for sending the request </param>
        /// <param name="firstPage"> Index of the first page to fetch </param>
        /// <param name="pageCount"> Amount of pages to get replies from. The higher this count, the more data will be generated and received </param>
        /// <returns> List of <c>SectionPost</c>s representing the replies </returns>
        public List <SectionPost> Replies <TUser>(AuthenticatedSession <TUser> session, uint pageCount, uint firstPage) where TUser : User
        {
            session.ThrowIfInvalid();
            if (ID == 0)
            {
                throw new ArgumentException("ID must not be empty");
            }

            var retrievedReplies = new List <SectionPost>();

            for (uint i = firstPage; i < (firstPage + pageCount); ++i)
            {
                var res          = session.Get(GetUrl(i));
                var htmlDocument = new HtmlDocument();
                htmlDocument.LoadHtml(res);

                var postsRootNode = htmlDocument.GetElementbyId("posts");
                if (postsRootNode == null)
                {
                    continue;
                }

                // for some reason, the lastpost container contains nothing and needs to be filtered out
                foreach (var postContainerNode in postsRootNode.ChildNodes.GetElementsByTagName("div").Where(element => element.Id != "lastpost"))
                {
                    // skip deleted posts, parsing them doesn't work (yet)
                    if (postContainerNode.SelectSingleNode("div[1]/div[1]/div[1]/table[1]/tr[1]/td[1]/a[1]/img[1]") == null)
                    {
                        continue;
                    }

                    var parsedPost = new SectionPost(0, this);
                    new SectionPostParser(parsedPost).Execute(postContainerNode);
                    retrievedReplies.Add(parsedPost);
                }

                // store the starting post and
                // remove it after storing since it is no reply
                if (i == 1 && retrievedReplies.Count != 0)
                {
                    InitialPost = retrievedReplies.First();
                    retrievedReplies.Remove(retrievedReplies.First());
                }
            }

            return(retrievedReplies);
        }
Exemple #3
0
        /// <summary>
        /// Replies to the <c>SectionThread</c>
        /// </summary>
        /// <param name="session"> Session that is used for sending the request </param>
        /// <param name="post"> Reply to post </param>
        /// <param name="settings"> Additional options that can be set </param>
        /// <remarks>
        /// The ID of the thread has to be given in order to reply
        /// </remarks>
        public void Reply <TUser>(AuthenticatedSession <TUser> session, SectionPost post,
                                  SectionPost.Settings settings = SectionPost.Settings.ParseUrl | SectionPost.Settings.ShowSignature)
            where TUser : User
        {
            if (ID == 0)
            {
                throw new ArgumentException("ID must not be empty");
            }
            session.ThrowIfInvalid();

            session.Post("https://www.elitepvpers.com/forum/newreply.php?do=postreply&t=" + ID,
                         new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("title", String.IsNullOrEmpty(post.Title) ? "-" : post.Title),
                new KeyValuePair <string, string>("message", post.Content.ToString()),
                new KeyValuePair <string, string>("wysiwyg", "0"),
                new KeyValuePair <string, string>("iconid", post.Icon.ToString()),
                new KeyValuePair <string, string>("s", String.Empty),
                new KeyValuePair <string, string>("securitytoken", session.SecurityToken),
                new KeyValuePair <string, string>("do", "postreply"),
                new KeyValuePair <string, string>("t", ID.ToString()),
                new KeyValuePair <string, string>("p", String.Empty),
                new KeyValuePair <string, string>("specifiedpost", "0"),
                new KeyValuePair <string, string>("posthash", "6fd3840e9b2ed6a8dcc9d9d0432abb14"),
                new KeyValuePair <string, string>("poststarttime", String.Empty),
                new KeyValuePair <string, string>("loggedinuser", session.User.ID.ToString()),
                new KeyValuePair <string, string>("multiquoteempty", String.Empty),
                new KeyValuePair <string, string>("sbutton", "Submit Reply"),
                new KeyValuePair <string, string>("signature", settings.HasFlag(SectionPost.Settings.ShowSignature) ? "1" : "0"),
                new KeyValuePair <string, string>("parseurl", settings.HasFlag(SectionPost.Settings.ParseUrl) ? "1" : "0"),
                new KeyValuePair <string, string>("parseame", "1"),
                new KeyValuePair <string, string>("vbseo_retrtitle", "1"),
                new KeyValuePair <string, string>("vbseo_is_retrtitle", "1"),
                new KeyValuePair <string, string>("emailupdate", "9999"),
                new KeyValuePair <string, string>("rating", "0"),
                new KeyValuePair <string, string>("openclose", "0")
            });
        }
Exemple #4
0
        /// <summary>
        /// Creates a <c>SectionThread</c>
        /// </summary>
        /// <param name="session"> Session that is used for sending the request </param>
        /// <param name="section"> Section under which the <c>SectionThread</c> is listed </param>
        /// <param name="startPost"> Represents the content and title of the <c>SectionThread</c> </param>
        /// <param name="settings"> Additional options that can be set </param>
        /// <param name="closed"> If true, the thread state is closed meaning that no one (except the staff) can answer to this thread </param>
        /// <returns> Freshly created <c>SectionThread</c> </returns>
        public static SectionThread Create <TUser>(AuthenticatedSession <TUser> session, Section section, SectionPost startPost,
                                                   SectionPost.Settings settings = SectionPost.Settings.ParseUrl | SectionPost.Settings.ShowSignature,
                                                   bool closed = false)
            where TUser : User
        {
            session.ThrowIfInvalid();

            session.Post("https://www.elitepvpers.com/forum/newthread.php?do=postthread&f=" + section.ID,
                         new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("subject", String.IsNullOrEmpty(startPost.Title) ? "-" : startPost.Title),
                new KeyValuePair <string, string>("message", startPost.Content.ToString()),
                new KeyValuePair <string, string>("wysiwyg", "0"),
                new KeyValuePair <string, string>("taglist", String.Empty),
                new KeyValuePair <string, string>("iconid", "0"),
                new KeyValuePair <string, string>("s", String.Empty),
                new KeyValuePair <string, string>("securitytoken", session.SecurityToken),
                new KeyValuePair <string, string>("f", section.ID.ToString()),
                new KeyValuePair <string, string>("do", "postthread"),
                new KeyValuePair <string, string>("posthash", "74532335f4d3a9f352db6af1b1c257f7"),
                new KeyValuePair <string, string>("poststarttime", "1389309192"),
                new KeyValuePair <string, string>("loggedinuser", session.User.ID.ToString()),
                new KeyValuePair <string, string>("sbutton", "Submit New Thread"),
                new KeyValuePair <string, string>("signature", settings.HasFlag(SectionPost.Settings.ShowSignature) ? "1" : "0"),
                new KeyValuePair <string, string>("parseurl", settings.HasFlag(SectionPost.Settings.ParseUrl) ? "1" : "0"),
                new KeyValuePair <string, string>("parseame", "1"),
                new KeyValuePair <string, string>("vbseo_retrtitle", "1"),
                new KeyValuePair <string, string>("vbseo_is_retrtitle", "1"),
                new KeyValuePair <string, string>("emailupdate", "9999"),
                new KeyValuePair <string, string>("polloptions", "4")
            });

            return(new SectionThread(0, section));
        }