public void Init(HttpApplication app) {

            string[] events = { "BeginRequest", "AuthenticateRequest",
                "PostAuthenticateRequest", "AuthorizeRequest", "ResolveRequestCache",
                "PostResolveRequestCache", "MapRequestHandler", "PostMapRequestHandler",
                "AcquireRequestState", "PostAcquireRequestState", 
                "PreRequestHandlerExecute", "PostRequestHandlerExecute", 
                 "ReleaseRequestState", "PostReleaseRequestState",
                "UpdateRequestCache", "LogRequest", "PostLogRequest",
                "EndRequest", "PreSendRequestHeaders", "PreSendRequestContent"};


            MethodInfo methodInfo = GetType().GetMethod("HandleEvent");
            foreach (string name in events) {
                EventInfo evInfo = app.GetType().GetEvent(name);

                evInfo.AddEventHandler(app, 
                    Delegate.CreateDelegate(evInfo.EventHandlerType,
                        this, methodInfo));
            }

            app.Error += (src, args) => {
                System.Diagnostics.Debug.WriteLine("Event: Error");
            };
        }
Exemplo n.º 2
0
        Hashtable GetApplicationTypeEvents(HttpApplication app)
        {
            if (have_app_events)
            {
                return(app_event_handlers);
            }

            return(GetApplicationTypeEvents(app.GetType()));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Disposes of the HTTP applications that was created as an entry point.
        /// </summary>
        private void DisposeHttpApplication()
        {
            HttpApplication httpApplication = this.httpApplication;
            this.httpApplication = null;

            if (httpApplication != null)
            {
                try
                {
                    MethodInfo method = HttpApplicationProbe.FindExitPoint(httpApplication.GetType());

                    if (method != null)
                    {
                        this.logger.Info("Invoking exit point for HTTP application {0}.", httpApplication.GetType().FullName);
                        this.InvokeEventHandler(httpApplication, method);
                    }
                    else
                    {
                        this.logger.Info("No exit point found for HTTP application {0}.", httpApplication.GetType().FullName);
                    }
                }
                finally
                {
                    httpApplication.Dispose();
                }
            }
        }
        /// <summary>
        ///     Register for events
        /// </summary>
        /// <param name="context"></param>
        public void Init(HttpApplication context)
        {
            context.PostRequestHandlerExecute += this.OnPostRequestHandlerExecute;
            context.PreRequestHandlerExecute += this.OnPreRequestHandlerExecute;
            context.PostMapRequestHandler += this.OnPostMapRequestHandler;

            // Connect runtime
            this._runtime.Subscribe(this);

            // Map application context
            this.MapApplicationContext(context.GetType());
        }
Exemplo n.º 5
0
		Hashtable GetApplicationTypeEvents (HttpApplication app)
		{
			if (have_app_events)
				return app_event_handlers;

			return GetApplicationTypeEvents (app.GetType ());
		}
Exemplo n.º 6
0
		/// <summary>
		/// Creates a new pseudo HttpContext and uses reflection to mimic what would happen
		/// in an ASP.net hosting environment.  Reflection is used only on the properties required
		/// by the session state module.
		/// </summary>
		/// <param name="request">Pseudo request object used in the context</param>
		/// <param name="response">Pseudo response object used in the context</param>
		/// <returns>A pseudo HttpContext object</returns>
		private HttpContext GetContext(out HttpRequest request, out HttpResponse response)
		{
			request = new HttpRequest("dummy.txt", "http://localhost/dummy.txt", string.Empty);

			HttpApplication httpApp = new HttpApplication();
			HttpApplicationState stateValue = (HttpApplicationState)Activator.CreateInstance(typeof(HttpApplicationState), true);

			var httpAppFactoryType = httpApp.GetType().Assembly.GetType("System.Web.HttpApplicationFactory");
			var httpAppFactory = Activator.CreateInstance(httpAppFactoryType, true);
			var httpAppFactoryStaticInstanceField = httpAppFactoryType.GetField("_theApplicationFactory", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
			var theHttpAppFactory = httpAppFactoryStaticInstanceField.GetValue(httpAppFactory);

			var httpAppStateField = httpAppFactoryType.GetField("_state", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
			httpAppStateField.SetValue(theHttpAppFactory, stateValue);

			var stateField = httpApp.GetType().GetField("_state", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
			stateField.SetValue(httpApp, stateValue);

			response = new HttpResponse(null);

			return new HttpContext(request, response);
		}
        /// <summary>
        /// Register for events
        /// </summary>
        /// <param name="context"></param>
        public void Init(HttpApplication context)
        {
            context.PostRequestHandlerExecute+= new EventHandler(OnPostRequestHandlerExecute);
            context.PreRequestHandlerExecute += new EventHandler(OnPreRequestHandlerExecute);
            context.PostMapRequestHandler += new EventHandler(OnPostMapRequestHandler);

            // Connect runtime
            _runtime.Subscribe(this);

            // Map application context
            MapApplicationContext(context.GetType());
        }
 /// <summary>
 /// Attach the <see cref="HttpApplication"/> that the <see cref="DreamApplication"/> to be built will be attached to.
 /// </summary>
 /// <param name="application">HttpApplication to attach to.</param>
 /// <returns>Current builder instance.</returns>
 public DreamApplicationConfigurationBuilder ForHttpApplication(HttpApplication application)
 {
     return WithApplicationAssembly(application.GetType().BaseType.Assembly);
 }
Exemplo n.º 9
0
 private static Assembly GetGlobalAssembly(HttpApplication app)
 {
     if (_globalAssembly != null) return _globalAssembly;
     lock (_syncRoot)
     {
         if (_globalAssembly != null) return _globalAssembly;
         if (app == null) throw new ApplicationException();
         Type t = app.GetType();
         while (t != null && t.Namespace == "ASP")
         {
             t = t.BaseType;
         }
         if (t == null) throw new ApplicationException();
         _globalAssembly = Assembly.GetAssembly(t);
         return _globalAssembly;
     }
 }
		IMonoRailConfiguration ObtainConfiguration( HttpApplication appInstance )
		{
			IMonoRailConfiguration config = MonoRailConfiguration.GetConfig();
			MethodInfo method = appInstance.GetType().GetMethod( "MonoRail_Configure" );

			if ( method != null )
			{
				config = config ?? new MonoRailConfiguration();

				if ( method.IsStatic )
				{
					method.Invoke( null, new object[] { config } );
				}
				else
				{
					method.Invoke( appInstance, new object[] { config } );
				}
			}

			if ( config == null )
			{
				throw new ApplicationException( "You have to provide a small configuration to use MonoRail. This can be done using the web.config or your global asax (your class that extends HttpApplication) through the method MonoRail_Configure(IMonoRailConfiguration config). Check the samples or the documentation." );
			}

			return config;
		}
		void FireContainerInitialized( HttpApplication instance, DefaultMonoRailContainer container )
		{
			ExecuteContainerEvent( 
				instance.GetType().GetMethod( "MonoRail_ContainerInitialized" ), 
				instance, 
				container );
		}