private void SetRequestFormInfo(NewThreadRequest data, HtmlDocument doc)
        {
            var formNodes = doc.DocumentNode.Descendants("input").ToArray();

            var formKeyNode = formNodes
                .Where(node => node.GetAttributeValue("name", "").Equals("formkey"))
                .FirstOrDefault();

            var formCookieNode = formNodes
                .Where(node => node.GetAttributeValue("name", "").Equals("form_cookie"))
                .FirstOrDefault();

            try
            {
                data.FormKey = formKeyNode.GetAttributeValue("value", "");
                data.FormCookie = formCookieNode.GetAttributeValue("value", "");
            }
            catch (Exception)
            {
                throw new InvalidOperationException("Could not parse newReply form data.");
            }
        }
        private NewThreadRequest GenerateNewThreadRequest(WebGetDocumentArgs document)
        {
            if (document == null || document.Document == null) return null;

            NewThreadRequest request = new NewThreadRequest();
            HtmlNode parent = document.Document.DocumentNode;

            if (this._requestThread.CancellationPending)
                return null;

            this.SetRequestFormInfo(request, document.Document);

            var icons = parent.Descendants("div")
                .Where(node => node.GetAttributeValue("class", "").Equals("posticon"));

            request.Icons = new List<AwfulTag>(30);
            request.Icons.Add(AwfulTag.NoIcon);

            foreach (var icon in icons)
            {
                try
                {
                    if (this._requestThread.CancellationPending)
                        return null;

                    var inputNode = icon.Descendants("input").SingleOrDefault();
                    var imgNode = icon.Descendants("img").SingleOrDefault();

                    string title = imgNode.GetAttributeValue("alt", "");
                    string value = inputNode.GetAttributeValue("value", "");
                    string uri = imgNode.GetAttributeValue("src", "");

                    request.Icons.Add(new AwfulTag(title, value, uri));
                }

                catch (Exception ex)
                {
                    Logger.AddEntry(string.Format("There was an error while parsing post icons. [{0}] {1}",
                        ex.Message, ex.StackTrace));
                }
            }

            request.SelectedIcon = AwfulTag.NoIcon;
            return request;
        }