private ThreadReplyData? GetReplyData(string threadID, string text)
        {
            string url = String.Format("http://forums.somethingawful.com/newreply.php?action=newreply&threadid={0}",
                threadID);

            AutoResetEvent replyDataSignal = new AutoResetEvent(false);
            HtmlDocument doc = null;
            bool success = false;
            var web = new Awful.Core.Web.WebGet();
            web.LoadAsync(url, (obj, loadAsyncArgs) =>
                {
                    if (loadAsyncArgs.Document != null)
                    {
                        doc = loadAsyncArgs.Document;
                        success = true;
                    }
                    replyDataSignal.Set();
                });

            replyDataSignal.WaitOne(App.Settings.ThreadTimeout);

            if (success == true)
            {
                ThreadReplyData data = GetReplyFormInfo(threadID, doc);
                data.TEXT = text;
                return data;
            }

            return null;
        }
Beispiel #2
0
        public void RunURLTaskAsync(string url, Action<Awful.Core.Models.ActionResult> result)
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback((state) =>
            {
                var web = new Awful.Core.Web.WebGet();
                var dispatch = Deployment.Current.Dispatcher;
                var signal = new AutoResetEvent(false);
                bool success = false;
                web.LoadAsync(url, (obj, args) =>
                {
                    if (args.Document != null)
                        success = true;

                    signal.Set();
                });

                signal.WaitOne(App.Settings.ThreadTimeout);

                if (success)
                {
                    dispatch.BeginInvoke(() => {result(Awful.Core.Models.ActionResult.Success); });
                }
                else
                {
                    dispatch.BeginInvoke(() => { result(Awful.Core.Models.ActionResult.Failure); });
                }
            }), null);
        }
        private void BeginGetTextFromWebForm(string webUrl, Action<Awful.Core.Models.ActionResult, string> result)
        {
            var web = new Awful.Core.Web.WebGet();
            var url = webUrl;

            Awful.Core.Event.Logger.AddEntry(string.Format("ThreadReplyServer - Retrieving text from '{0}'.", url));

            Awful.Core.Models.ActionResult success = Awful.Core.Models.ActionResult.Failure;
            string bodyText = String.Empty;
            HtmlNode docNode = null;

            web.LoadAsync(url, (obj, args) =>
            {
                switch (obj)
                {
                    case Awful.Core.Models.ActionResult.Success:
                        if (args.Document != null)
                        {
                            success = Awful.Core.Models.ActionResult.Success;
                            docNode = args.Document.DocumentNode;
                        }
                        else { success = Awful.Core.Models.ActionResult.Failure; }
                        break;
                }

                getTextSignal.Set();
            });

            getTextSignal.WaitOne(App.Settings.ThreadTimeout);

            if (getTextCancelled)
            {
                getTextCancelled = false;
                success = Awful.Core.Models.ActionResult.Cancelled;
            }

            if (success == Awful.Core.Models.ActionResult.Success)
            {
                bodyText = GetFormText(docNode);
                bodyText = HttpUtility.HtmlDecode(bodyText);
            }

            Awful.Core.Event.Logger.AddEntry(string.Format("ThreadReplyService - Get text result: success: {0}", success));
            var dispatcher = Deployment.Current.Dispatcher;

            dispatcher.BeginInvoke(() =>
            {
                result(success, bodyText);
            });
        }