コード例 #1
0
        protected internal virtual IAsyncResult BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, object state)
        {
            IHttpHandler      httpHandler      = GetHttpHandler(httpContext);
            IHttpAsyncHandler httpAsyncHandler = httpHandler as IHttpAsyncHandler;

            if (httpAsyncHandler != null)
            {
                // asynchronous handler
                BeginInvokeDelegate beginDelegate = delegate(AsyncCallback asyncCallback, object asyncState)
                {
                    return(httpAsyncHandler.BeginProcessRequest(HttpContext.Current, asyncCallback, asyncState));
                };
                EndInvokeDelegate endDelegate = delegate(IAsyncResult asyncResult)
                {
                    httpAsyncHandler.EndProcessRequest(asyncResult);
                };
                return(AsyncResultWrapper.Begin(callback, state, beginDelegate, endDelegate, _processRequestTag));
            }
            else
            {
                // synchronous handler
                Action action = delegate
                {
                    httpHandler.ProcessRequest(HttpContext.Current);
                };
                return(AsyncResultWrapper.BeginSynchronous(callback, state, action, _processRequestTag));
            }
        }
コード例 #2
0
 public void EndProcessRequest(IAsyncResult result)
 {
     try {
         _httpAsyncHandler.EndProcessRequest(result);
     }
     finally {
         _scope.Dispose();
     }
 }
コード例 #3
0
        public void WrapForServerExecute_EndProcessRequest_DelegatesCorrectly()
        {
            // Arrange
            IAsyncResult asyncResult = new Mock <IAsyncResult>().Object;

            HttpContext httpContext = GetHttpContext();
            Mock <IHttpAsyncHandler> mockHttpHandler = new Mock <IHttpAsyncHandler>();

            mockHttpHandler.Setup(o => o.EndProcessRequest(asyncResult)).Verifiable();

            IHttpAsyncHandler wrapper = (IHttpAsyncHandler)HttpHandlerUtil.WrapForServerExecute(mockHttpHandler.Object);

            // Act
            wrapper.EndProcessRequest(asyncResult);

            // Assert
            mockHttpHandler.Verify();
        }
コード例 #4
0
        protected virtual IAsyncResult BeginProcessRequest(
            HttpContextBase context, AsyncCallback callback, object state)
        {
            IHttpHandler      handler      = GetHttpHandler(context);
            IHttpAsyncHandler asyncHandler = (handler as IHttpAsyncHandler);

            if (asyncHandler == null)
            {
                Action action = delegate {
                    handler.ProcessRequest(context.Unwrap());
                };
                return(AsyncResultWrapper.BeginSynchronous(callback, state, action, _tag));
            }
            BeginInvokeDelegate beginDelegate = delegate(AsyncCallback asyncCallback, object asyncState) {
                return(asyncHandler.BeginProcessRequest(context.Unwrap(), asyncCallback, asyncState));
            };
            EndInvokeDelegate endDelegate = delegate(IAsyncResult asyncResult) {
                asyncHandler.EndProcessRequest(asyncResult);
            };

            return(AsyncResultWrapper.Begin(callback, state, beginDelegate, endDelegate, _tag));
        }
コード例 #5
0
        protected internal virtual IAsyncResult BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, object state)
        {
            BeginInvokeDelegate delegate4      = null;
            EndInvokeDelegate   delegate5      = null;
            Action            action2          = null;
            IHttpHandler      httpHandler      = GetHttpHandler(httpContext);
            IHttpAsyncHandler httpAsyncHandler = httpHandler as IHttpAsyncHandler;

            if (httpAsyncHandler != null)
            {
                if (delegate4 == null)
                {
                    delegate4 = (asyncCallback, asyncState) => httpAsyncHandler.BeginProcessRequest(HttpContext.Current, asyncCallback, asyncState);
                }
                BeginInvokeDelegate beginDelegate = delegate4;
                if (delegate5 == null)
                {
                    delegate5 = delegate(IAsyncResult asyncResult)
                    {
                        httpAsyncHandler.EndProcessRequest(asyncResult);
                    };
                }
                EndInvokeDelegate endDelegate = delegate5;
                return(AsyncResultWrapper.Begin(callback, state, beginDelegate, endDelegate, _processRequestTag));
            }
            if (action2 == null)
            {
                action2 = delegate
                {
                    httpHandler.ProcessRequest(HttpContext.Current);
                }
            }
            ;
            Action action = action2;

            return(AsyncResultWrapper.BeginSynchronous(callback, state, action, _processRequestTag));
        }
コード例 #6
0
 public void EndProcessRequest(IAsyncResult asyncResult)
 {
     _handler.EndProcessRequest(asyncResult);
 }
コード例 #7
0
 public void EndProcessRequest(IAsyncResult result)
 {
     _inner.EndProcessRequest(result);
 }
コード例 #8
0
        internal void Execute(IHttpHandler handler, TextWriter writer, bool preserveForm, string exePath, string queryString, bool isTransfer, bool isInclude)
        {
#if !TARGET_J2EE
            // If the target handler is not Page, the transfer must not occur.
            // InTransit == true means we're being called from Transfer
            bool is_static = (handler is StaticFileHandler);
            if (isTransfer && !(handler is Page) && !is_static)
            {
                throw new HttpException("Transfer is only allowed to .aspx and static files");
            }
#endif

            HttpRequest request  = context.Request;
            string      oldQuery = request.QueryStringRaw;
            if (queryString != null)
            {
                request.QueryStringRaw = queryString;
            }
            else if (!preserveForm)
            {
                request.QueryStringRaw = String.Empty;
            }

            HttpResponse    response = context.Response;
            WebROCollection oldForm  = request.Form as WebROCollection;
            if (!preserveForm)
            {
                request.SetForm(new WebROCollection());
            }

            TextWriter output = writer;
            if (output == null)
            {
                output = response.Output;
            }

            TextWriter previous     = response.SetTextWriter(output);
            string     oldExePath   = request.CurrentExecutionFilePath;
            bool       oldIsInclude = context.IsProcessingInclude;
            try
            {
                context.PushHandler(handler);
                if (is_static) // Not sure if this should apply to Page too
                {
                    request.SetFilePath(exePath);
                }

                request.SetCurrentExePath(exePath);
                context.IsProcessingInclude = isInclude;

                if (!(handler is IHttpAsyncHandler))
                {
                    handler.ProcessRequest(context);
                }
                else
                {
                    IHttpAsyncHandler asyncHandler    = (IHttpAsyncHandler)handler;
                    IAsyncResult      ar              = asyncHandler.BeginProcessRequest(context, null, null);
                    WaitHandle        asyncWaitHandle = ar != null ? ar.AsyncWaitHandle : null;
                    if (asyncWaitHandle != null)
                    {
                        asyncWaitHandle.WaitOne();
                    }
                    asyncHandler.EndProcessRequest(ar);
                }
            }
            finally
            {
                if (oldQuery != request.QueryStringRaw)
                {
                    if (oldQuery != null && oldQuery.Length > 0)
                    {
                        oldQuery = oldQuery.Substring(1);  // Ignore initial '?'
                        request.QueryStringRaw = oldQuery; // which is added here.
                    }
                    else
                    {
                        request.QueryStringRaw = String.Empty;
                    }
                }

                response.SetTextWriter(previous);
                if (!preserveForm)
                {
                    request.SetForm(oldForm);
                }

                context.PopHandler();
                request.SetCurrentExePath(oldExePath);
                context.IsProcessingInclude = oldIsInclude;
            }
        }
コード例 #9
0
        static void Process(HttpWorkerRequest req)
        {
            bool error = false;

#if TARGET_J2EE
            HttpContext context = HttpContext.Current;
            if (context == null)
            {
                context = new HttpContext(req);
            }
            else
            {
                context.SetWorkerRequest(req);
            }
#else
            if (firstRun)
            {
                firstRun = false;
                if (initialException != null)
                {
                    FinishWithException(req, HttpException.NewWithCode("Initial exception", initialException, WebEventCodes.RuntimeErrorRequestAbort));
                    error = true;
                }
                SetupOfflineWatch();
            }
            HttpContext context = new HttpContext(req);
#endif
            HttpContext.Current = context;
#if !TARGET_J2EE
            if (AppIsOffline(context))
            {
                return;
            }
#endif

            //
            // Get application instance (create or reuse an instance of the correct class)
            //
            HttpApplication app = null;
            if (!error)
            {
                try {
                    app = HttpApplicationFactory.GetApplication(context);
                } catch (Exception e) {
                    FinishWithException(req, HttpException.NewWithCode(String.Empty, e, WebEventCodes.RuntimeErrorRequestAbort));
                    error = true;
                }
            }

            if (error)
            {
                context.Request.ReleaseResources();
                context.Response.ReleaseResources();
                HttpContext.Current = null;
            }
            else
            {
                context.ApplicationInstance = app;
                req.SetEndOfSendNotification(end_of_send_cb, context);

                //
                // Ask application to service the request
                //

#if TARGET_J2EE
                IHttpAsyncHandler ihah = app;
                if (context.Handler == null)
                {
                    ihah.BeginProcessRequest(context, new AsyncCallback(request_processed), context);
                }
                else
                {
                    app.Tick();
                }
                //ihh.ProcessRequest (context);
                IHttpExtendedHandler extHandler = context.Handler as IHttpExtendedHandler;
                if (extHandler != null && !extHandler.IsCompleted)
                {
                    return;
                }
                if (context.Error is UnifyRequestException)
                {
                    return;
                }

                ihah.EndProcessRequest(null);
#else
                IHttpHandler ihh = app;
//				IAsyncResult appiar = ihah.BeginProcessRequest (context, new AsyncCallback (request_processed), context);
//				ihah.EndProcessRequest (appiar);
                ihh.ProcessRequest(context);
#endif

                HttpApplicationFactory.Recycle(app);
            }
        }
コード例 #10
0
 public void EndProcessRequest(IAsyncResult result)
 {
     Wrap(() => _httpHandler.EndProcessRequest(result));
 }
コード例 #11
0
        private void ExecuteInternal(IHttpHandler handler, TextWriter writer, bool preserveForm, bool setPreviousPage, VirtualPath path, VirtualPath filePath, string physPath, Exception error, string queryStringOverride)
        {
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }
            HttpRequest         request             = this._context.Request;
            HttpResponse        response            = this._context.Response;
            HttpApplication     applicationInstance = this._context.ApplicationInstance;
            HttpValueCollection form   = null;
            VirtualPath         path2  = null;
            string     queryStringText = null;
            TextWriter writer2         = null;
            AspNetSynchronizationContext syncContext = null;

            this.VerifyTransactionFlow(handler);
            this._context.PushTraceContext();
            this._context.SetCurrentHandler(handler);
            bool enabled = this._context.SyncContext.Enabled;

            this._context.SyncContext.Disable();
            try
            {
                try
                {
                    this._context.ServerExecuteDepth++;
                    path2 = request.SwitchCurrentExecutionFilePath(filePath);
                    if (!preserveForm)
                    {
                        form = request.SwitchForm(new HttpValueCollection());
                        if (queryStringOverride == null)
                        {
                            queryStringOverride = string.Empty;
                        }
                    }
                    if (queryStringOverride != null)
                    {
                        queryStringText         = request.QueryStringText;
                        request.QueryStringText = queryStringOverride;
                    }
                    if (writer != null)
                    {
                        writer2 = response.SwitchWriter(writer);
                    }
                    Page page = handler as Page;
                    if (page != null)
                    {
                        if (setPreviousPage)
                        {
                            page.SetPreviousPage(this._context.PreviousHandler as Page);
                        }
                        Page page2 = this._context.Handler as Page;
                        if ((page2 != null) && page2.SmartNavigation)
                        {
                            page.SmartNavigation = true;
                        }
                        if (page is IHttpAsyncHandler)
                        {
                            syncContext = this._context.InstallNewAspNetSynchronizationContext();
                        }
                    }
                    if (((handler is StaticFileHandler) || (handler is DefaultHttpHandler)) && !DefaultHttpHandler.IsClassicAspRequest(filePath.VirtualPathString))
                    {
                        try
                        {
                            response.WriteFile(physPath);
                        }
                        catch
                        {
                            error = new HttpException(0x194, string.Empty);
                        }
                    }
                    else if (!(handler is Page))
                    {
                        error = new HttpException(0x194, string.Empty);
                    }
                    else
                    {
                        if (handler is IHttpAsyncHandler)
                        {
                            bool isInCancellablePeriod = this._context.IsInCancellablePeriod;
                            if (isInCancellablePeriod)
                            {
                                this._context.EndCancellablePeriod();
                            }
                            try
                            {
                                IHttpAsyncHandler handler2 = (IHttpAsyncHandler)handler;
                                IAsyncResult      result   = handler2.BeginProcessRequest(this._context, null, null);
                                if (!result.IsCompleted)
                                {
                                    bool flag3 = false;
                                    try
                                    {
                                        try
                                        {
                                        }
                                        finally
                                        {
                                            Monitor.Exit(applicationInstance);
                                            flag3 = true;
                                        }
                                        WaitHandle asyncWaitHandle = result.AsyncWaitHandle;
                                        if (asyncWaitHandle == null)
                                        {
                                            goto Label_0210;
                                        }
                                        asyncWaitHandle.WaitOne();
                                        goto Label_0226;
Label_020A:
                                        Thread.Sleep(1);
Label_0210:
                                        if (!result.IsCompleted)
                                        {
                                            goto Label_020A;
                                        }
                                    }
                                    finally
                                    {
                                        if (flag3)
                                        {
                                            Monitor.Enter(applicationInstance);
                                        }
                                    }
                                }
Label_0226:
                                try
                                {
                                    handler2.EndProcessRequest(result);
                                }
                                catch (Exception exception)
                                {
                                    error = exception;
                                }
                                goto Label_0306;
                            }
                            finally
                            {
                                if (isInCancellablePeriod)
                                {
                                    this._context.BeginCancellablePeriod();
                                }
                            }
                        }
                        using (new DisposableHttpContextWrapper(this._context))
                        {
                            try
                            {
                                handler.ProcessRequest(this._context);
                            }
                            catch (Exception exception2)
                            {
                                error = exception2;
                            }
                        }
                    }
                }
                finally
                {
                    this._context.ServerExecuteDepth--;
                    this._context.RestoreCurrentHandler();
                    if (writer2 != null)
                    {
                        response.SwitchWriter(writer2);
                    }
                    if ((queryStringOverride != null) && (queryStringText != null))
                    {
                        request.QueryStringText = queryStringText;
                    }
                    if (form != null)
                    {
                        request.SwitchForm(form);
                    }
                    request.SwitchCurrentExecutionFilePath(path2);
                    if (syncContext != null)
                    {
                        this._context.RestoreSavedAspNetSynchronizationContext(syncContext);
                    }
                    if (enabled)
                    {
                        this._context.SyncContext.Enable();
                    }
                    this._context.PopTraceContext();
                }
            }
            catch
            {
                throw;
            }
Label_0306:
            if (error == null)
            {
                return;
            }
            if ((error is HttpException) && (((HttpException)error).GetHttpCode() != 500))
            {
                error = null;
            }
            if (path != null)
            {
                throw new HttpException(System.Web.SR.GetString("Error_executing_child_request_for_path", new object[] { path }), error);
            }
            throw new HttpException(System.Web.SR.GetString("Error_executing_child_request_for_handler", new object[] { handler.GetType().ToString() }), error);
        }
コード例 #12
0
 public void EndProcessRequest(IAsyncResult result)
 {
     _originalHandler.EndProcessRequest(result);
 }
コード例 #13
0
        protected override void Wait(IAsyncResult result)
        {
            Assert.IsNotNull(handler, "Wait#A01");

            handler.EndProcessRequest(result);
        }