示例#1
0
        private Awful.Core.Models.ActionResult BuildPageFromHtml(SAForumPage page, WebGetDocumentArgs args)
        {
            try
            {
                var node = args.Document.DocumentNode;
                this.HandleMaxPages(page, node);
                this.HandleThreads(page, node);
                return Awful.Core.Models.ActionResult.Success;
            }

            catch (Exception ex) { return Awful.Core.Models.ActionResult.Failure; }
        }
示例#2
0
        private void ProcessGetResponse(IAsyncResult callback)
        {
            try
            {
                var request = (HttpWebRequest)callback.AsyncState;
                var response = (HttpWebResponse)request.EndGetResponse(callback);
                using (StreamReader reader = new StreamReader(response.GetResponseStream(),
                    System.Text.Encoding.GetEncoding(Constants.WEB_RESPONSE_ENCODING)))
                {
                    this._result = reader.ReadToEnd();
                    this._success = true;
                    reader.Close();
                }

                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(this._result);
                string uri = response.ResponseUri.ToString();
                this._args = new WebGetDocumentArgs(doc, uri);
                signal.Set();
            }

            catch (Exception ex)
            {
                Logger.AddEntry(string.Format("WebGet: There was an error while processing the response. [{0}] {1}",
                    ex.Message, ex.StackTrace));

                this._success = false;
                this._args = null;
                this._result = null;

                signal.Set();
            }
        }
        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;
        }
示例#4
0
        private void ProcessRequest(AwfulSmileyRequest request, WebGetDocumentArgs args)
        {
            if (request == null) return;

            try
            {
                request.List = SASmileyFactory.Build(args.Document);
                request.Status = Awful.Core.Models.ActionResult.Success;
            }

            catch (Exception ex)
            {
                string error = string.Format("An error occurred while processing a smiley request: [{0}] {1}",
                    ex.Message, ex.StackTrace);

                Awful.Core.Event.Logger.AddEntry(error);
                request.Status = Awful.Core.Models.ActionResult.Failure;
            }
        }