Exemplo n.º 1
0
        private IPrivateMessageRequest GetMessageRequest(string url)
        {
            var web = new AwfulWebClient();
            var doc = web.FetchHtml(url).ToHtmlDocument();

            PrivateMessageRequest request = PrivateMessageParser.ParseNewPrivateMessageFormDocument(doc);

            return(request);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parses the html from SA's new message page and constructs a private message request
        /// object.
        /// </summary>
        /// <param name="doc">The html document.</param>
        /// <returns>A private message request, which can be sent or discarded.</returns>
        public static PrivateMessageRequest ParseNewPrivateMessageFormDocument(HtmlDocument doc)
        {
            var pmRequest  = new PrivateMessageRequest();
            var top        = doc.DocumentNode;
            var inputArray = top.Descendants("input").ToArray();

            string toUser  = GetInputValue(inputArray, NEW_MESSAGE_TOUSER);
            string title   = GetInputValue(inputArray, NEW_MESSAGE_TITLE);
            string forward = GetInputValue(inputArray, NEW_MESSAGE_FOWARD);

            var messageNode = top.Descendants("textarea")
                              .Where(node => node.GetAttributeValue("name", "").Equals(NEW_MESSAGE_MESSAGE))
                              .SingleOrDefault();

            string message = messageNode == null ? string.Empty : messageNode.InnerText;

            pmRequest.Body       = message;
            pmRequest.To         = toUser;
            pmRequest.Subject    = title;
            pmRequest.IsForward  = forward != string.Empty;
            pmRequest.TagOptions = ParseFormTagOptions(doc);

            return(pmRequest);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Parses the html from SA's new message page and constructs a private message request
        /// object.
        /// </summary>
        /// <param name="doc">The html document.</param>
        /// <returns>A private message request, which can be sent or discarded.</returns>
        public static PrivateMessageRequest ParseNewPrivateMessageFormDocument(HtmlDocument doc)
        {
            var pmRequest = new PrivateMessageRequest();
            var top = doc.DocumentNode;
            var inputArray = top.Descendants("input").ToArray();

            string toUser = GetInputValue(inputArray, NEW_MESSAGE_TOUSER);
            string title = GetInputValue(inputArray, NEW_MESSAGE_TITLE);
            string forward = GetInputValue(inputArray, NEW_MESSAGE_FOWARD);

            var messageNode = top.Descendants("textarea")
                .Where(node => node.GetAttributeValue("name", "").Equals(NEW_MESSAGE_MESSAGE))
                .SingleOrDefault();

            string message = messageNode == null ? string.Empty : messageNode.InnerText;

            pmRequest.Body = message;
            pmRequest.To = toUser;
            pmRequest.Subject = title;
            pmRequest.IsForward = forward != string.Empty;
            pmRequest.TagOptions = ParseFormTagOptions(doc);

            return pmRequest;
        }