Beispiel #1
0
        private byte[] GetEditMultipartFormData(PostEditData data)
        {
            Stream        dataStream = new MemoryStream();
            StringBuilder sb         = new StringBuilder();

            AddFormDataString(sb, "action", EDIT_ACTION_REQUEST, EDIT_HEADER);
            AddFormDataString(sb, "postid", data.POSTID, EDIT_HEADER);
            AddFormDataString(sb, "message", data.TEXT, EDIT_HEADER);
            AddFormDataString(sb, "parseurl", PARSEURL_REQUEST, EDIT_HEADER);
            AddFormDataString(sb, "bookmark", BOOKMARK_REQUEST, EDIT_HEADER);
            AddFormDataString(sb, "submit", SUBMIT_REQUEST, EDIT_HEADER);
            sb.AppendLine(EDIT_FOOTER);

            string content = sb.ToString();

            AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "Begin form data...");
            AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, content);
            AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "...End form data.");

            dataStream.Write(encoding.GetBytes(content), 0, content.Length);

            dataStream.Position = 0;
            byte[] formData = new byte[dataStream.Length];
            dataStream.Read(formData, 0, formData.Length);
            dataStream.Close();

            return(formData);
        }
Beispiel #2
0
        private Uri SendEdit(ThreadPostMetadata post, string text)
        {
            PostEditData data = new PostEditData()
            {
                POSTID = post.PostID, TEXT = text
            };

            return(InitiateEditRequest(data));
        }
Beispiel #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);
        }
        private void InitiateEditRequest(PostEditData data, Action<ActionResult> result)
        {
            var dispatch = Deployment.Current.Dispatcher;

            Logger.AddEntry("ThreadReplyService - EditRequest initiated.");
            try
            {
                string url = "http://forums.somethingawful.com/editpost.php";
                request = AwfulWebRequest.CreateFormDataPostRequest(url, EDIT_CONTENT_TYPE);
                if (request == null)
                    throw new NullReferenceException("request is not an http request.");

                request.AllowAutoRedirect = true;

                request.BeginGetRequestStream((getRequestAsyncResult) =>
                {
                    byte[] formData = GetEditMultipartFormData(data);
                    if (HandleGetRequest(getRequestAsyncResult, formData))
                    {
                        var webRequest = getRequestAsyncResult.AsyncState as HttpWebRequest;
                        webRequest.BeginGetResponse((getResponseAsyncResult) =>
                        {
                            if (HandleGetResponse(getResponseAsyncResult))
                            {
                                Logger.AddEntry("ThreadReplyService - EditRequest successful.");
                                dispatch.BeginInvoke(() => { result(ActionResult.Success); });
                            }
                            else
                            {
                                Logger.AddEntry("ThreadReplyService - EditRequest failed.");
                                dispatch.BeginInvoke(() => { result(ActionResult.Failure); });
                            }

                        }, webRequest);
                    }
                    else
                    {
                        Logger.AddEntry("ThreadReplyService - EditRequest failed.");
                        dispatch.BeginInvoke(() => { result(ActionResult.Failure); });
                    }

                }, request);
            }

            catch (Exception) {
                Logger.AddEntry("ThreadReplyService - EditRequest failed.");
                dispatch.BeginInvoke(() => { result(ActionResult.Failure); }); }
        }
        private byte[] GetEditMultipartFormData(PostEditData data)
        {
            Stream dataStream = new MemoryStream();
            StringBuilder sb = new StringBuilder();

            AddFormDataString(sb, "action", EDIT_ACTION_REQUEST, EDIT_HEADER);
            AddFormDataString(sb, "postid", data.POSTID, EDIT_HEADER);
            AddFormDataString(sb, "message", data.TEXT, EDIT_HEADER);
            AddFormDataString(sb, "parseurl", PARSEURL_REQUEST, EDIT_HEADER);
            AddFormDataString(sb, "bookmark", BOOKMARK_REQUEST, EDIT_HEADER);
            AddFormDataString(sb, "submit", SUBMIT_REQUEST, EDIT_HEADER);
            sb.AppendLine(EDIT_FOOTER);

            string content = sb.ToString();

            dataStream.Write(encoding.GetBytes(content), 0, content.Length);

            dataStream.Position = 0;
            byte[] formData = new byte[dataStream.Length];
            dataStream.Read(formData, 0, formData.Length);
            dataStream.Close();

            return formData;
        }
        public void SendEditAsync(string postID, string text, Action<ActionResult> result)
        {
            PostEditData data = new PostEditData() { POSTID = postID, TEXT = text };

            ThreadPool.QueueUserWorkItem(new WaitCallback(state =>
                {
                    InitiateEditRequest(data, result);
                }),
                null);
        }
Beispiel #7
0
        private Uri SendEdit(ThreadPostMetadata post, string text)
        {
            PostEditData data = new PostEditData() { POSTID = post.PostID, TEXT = text };

            return InitiateEditRequest(data);
        }
Beispiel #8
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;
        }