Ejemplo n.º 1
0
		protected override IAsyncResult GetAsyncResult (Func<Task> taskFactory, AsyncCallback callback, object state)
		{
			Assert.IsNull (handler, "GetAsyncResult#A01");

			handler = new TestHttpTaskAsyncHandler (taskFactory, expectedContext);
			return handler.BeginProcessRequest (expectedContext, callback, state);
		}
Ejemplo n.º 2
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));
            }
        }
Ejemplo n.º 3
0
        protected override IAsyncResult GetAsyncResult(Func <Task> taskFactory, AsyncCallback callback, object state)
        {
            Assert.IsNull(handler, "GetAsyncResult#A01");

            handler = new TestHttpTaskAsyncHandler(taskFactory, expectedContext);
            return(handler.BeginProcessRequest(expectedContext, callback, state));
        }
Ejemplo n.º 4
0
 public IAsyncResult BeginProcessRequest(
     HttpContext context,
     AsyncCallback cb,
     object extraData
     )
 {
     return(Wrap(() => _httpHandler.BeginProcessRequest(context, cb, extraData)));
 }
Ejemplo n.º 5
0
 public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
 {
     _scope = _workContextAccessor.CreateWorkContextScope(new HttpContextWrapper(context));
     try {
         return(_httpAsyncHandler.BeginProcessRequest(context, cb, extraData));
     }
     catch {
         _scope.Dispose();
         throw;
     }
 }
 public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
 {
     return(_inner.BeginProcessRequest(context, ar =>
     {
         context.Response.AddHeader("ThisIs", "Custom");
         if (cb != null)
         {
             cb(ar);
         }
     }, extraData));
 }
Ejemplo n.º 7
0
 public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
 {
     _scope = _workContextAccessor.CreateWorkContextScope(new HttpContextWrapper(context));
     try {
         return(_httpAsyncHandler.BeginProcessRequest(context, cb, extraData));
     }
     catch {
         _scope.Dispose();
         HttpContext.Current.Response.Redirect("/StartPage");
         // throw;
         return(null);
     }
 }
Ejemplo n.º 8
0
        public void WrapForServerExecute_BeginProcessRequest_DelegatesCorrectly()
        {
            // Arrange
            IAsyncResult  expectedResult = new Mock <IAsyncResult>().Object;
            AsyncCallback cb             = delegate { };

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

            mockHttpHandler.Setup(o => o.BeginProcessRequest(httpContext, cb, "extraData")).Returns(expectedResult);

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

            // Act
            IAsyncResult actualResult = wrapper.BeginProcessRequest(httpContext, cb, "extraData");

            // Assert
            Assert.Equal(expectedResult, actualResult);
        }
Ejemplo n.º 9
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));
        }
Ejemplo n.º 10
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));
        }
 public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback callback, object state)
 {
     _handler = GetHttpHandler(context);
     return(_handler.BeginProcessRequest(context, callback, state));
 }
        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;
            }
        }
Ejemplo n.º 13
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);
            }
        }
			public void Execute ()
			{
				IHttpHandler handler = _app.Context.Handler;
				if (handler == null)
					return;

				// Check if we can execute async
				if (handler is IHttpAsyncHandler) {
					_async = true;
					_handler = (IHttpAsyncHandler) handler;

					IAsyncResult ar = _handler.BeginProcessRequest (_app.Context,
											_callback,
											null);

					if (ar.CompletedSynchronously) {
						_async = false;
						_handler = null;
						((IHttpAsyncHandler) handler).EndProcessRequest (ar);
					}
				} else {
					_async = false;

					// Sync handler
					handler.ProcessRequest (_app.Context);
				}
			}
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
0
 public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
 {
     return(_originalHandler.BeginProcessRequest(context, cb, extraData));
 }