Exemple #1
0
        public static bool ClearMarkedPosts(ThreadMetadata thread, int timeout = CoreConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS)
        {
            // create request
            HttpWebRequest request = AwfulWebRequest.CreateFormDataPostRequest(
                "http://forums.somethingawful.com/showthread.php",
                "application/x-www-form-urlencoded");

            // begin request stream creation and wait...
            var signal = new AutoResetEvent(false);
            var result = request.BeginGetRequestStream(callback =>
                                                       SendClearMarkedPostRequest(callback, signal, thread),
                                                       request);

            signal.WaitOne();

            // begin response stream and wait...
            request = result.AsyncState as HttpWebRequest;
            result  = request.BeginGetResponse(callback => { signal.Set(); }, request);
            signal.WaitOne(timeout);

            if (!result.IsCompleted)
            {
                throw new TimeoutException();
            }

            // process the response and return status
            bool success = ProcessClearMarkedPostResponse(result);

            return(success);
        }
Exemple #2
0
        private Uri InitiateReply(ThreadReplyData data, int timeout = DEFAULT_TIMEOUT)
        {
            // create request
            AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "Creating Reply Request...");

            string url     = "http://forums.somethingawful.com/newreply.php";
            var    request = AwfulWebRequest.CreateFormDataPostRequest(url, REPLY_CONTENT_TYPE);

            if (request == null)
            {
                throw new NullReferenceException("request is not an http request.");
            }

            request.AllowAutoRedirect = true;

            // begin request stream
            AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "Beginning Request Stream...");

            var signal = new AutoResetEvent(false);
            var result = request.BeginGetRequestStream(callback => { signal.Set(); }, request);

            signal.WaitOne();

            // process request
            AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "Creating Form Data...");

            FormDataDelegate replyFormData = () => { return(GetReplyMultipartFormData(data)); };
            var success = ProcessReplyRequest(result, replyFormData);

            // begin response
            AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "Waiting for response...");

            request = result.AsyncState as HttpWebRequest;
            result  = request.BeginGetResponse(callback => { signal.Set(); }, request);
            signal.WaitOne(timeout);

            if (!result.IsCompleted)
            {
                throw new TimeoutException("Thread Reply: timeout reached");
            }

            // process response and return status value
            AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "Processing response...");

            Uri redirect = HandleGetResponse(result);

            return(redirect);
        }
Exemple #3
0
        private Uri InitiateEditRequest(PostEditData data, int timeout = CoreConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS)
        {
            AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "Begin Edit Request...");

            string url     = "http://forums.somethingawful.com/editpost.php";
            var    request = AwfulWebRequest.CreateFormDataPostRequest(url, EDIT_CONTENT_TYPE);

            if (request == null)
            {
                throw new NullReferenceException("request is not an http request.");
            }

            request.AllowAutoRedirect = true;

            // begin request stream
            AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "Processing request stream...");

            var signal = new AutoResetEvent(false);
            var result = request.BeginGetRequestStream(callback => { signal.Set(); }, request);

            signal.WaitOne();

            // process request
            AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "Creating form data...");

            FormDataDelegate editFormData = () => { return(GetEditMultipartFormData(data)); };
            var success = ProcessReplyRequest(result, editFormData);

            // begin response
            AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "Waiting for server response...");

            request = result.AsyncState as HttpWebRequest;
            result  = request.BeginGetResponse(callback => { signal.Set(); }, request);
            signal.WaitOne(timeout);

            if (!result.IsCompleted)
            {
                throw new TimeoutException("The timeout was reached while trying to send an edit request.");
            }

            // process response and return status value
            AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "Processing server response...");

            Uri redirect = HandleGetResponse(result);

            return(redirect);
        }
Exemple #4
0
        private HttpWebRequest InitializePostRequest(string url)
        {
            HttpWebRequest request = AwfulWebRequest.CreateFormDataPostRequest(url, "application/x-www-form-urlencoded");

            return(request);
        }