// Author:
// Miguel de Icaza (miguel@novell.com)
// Gonzalo Paniagua (gonzalo@ximian.com)
-//
+// Matthias Bogad (bogad@cs.tum.edu)
+//
//
// Copyright (C) 2005-2009 Novell, Inc (http://www.novell.com)
//
// Events Disposed
//
+using System;
using System.IO;
using System.Collections;
+using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Diagnostics;
bool removeConfigurationFromCache;
bool fullInitComplete = false;
+ static DynamicModuleManager dynamicModuleManeger = new DynamicModuleManager ();
+
//
// These are used to detect the case where the EndXXX method is invoked
// from within the BeginXXXX delegate, so we detect whether we kick the
if (context == null)
context = HttpContext.Current;
HttpModuleCollection coll = modules.LoadModules (this);
+
+ HttpModuleCollection dynMods = CreateDynamicModules ();
+
+ for (int i = 0; i < dynMods.Count; i++) {
+ coll.AddModule (dynMods.GetKey (i), dynMods.Get (i));
+ }
+
Interlocked.CompareExchange (ref modcoll, coll, null);
HttpContext.Current = saved;
public void AddOnAcquireRequestStateAsync (BeginEventHandler bh, EndEventHandler eh)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this);
AcquireRequestState += new EventHandler (invoker.Invoke);
}
public void AddOnAuthenticateRequestAsync (BeginEventHandler bh, EndEventHandler eh)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this);
AuthenticateRequest += new EventHandler (invoker.Invoke);
}
public void AddOnAuthorizeRequestAsync (BeginEventHandler bh, EndEventHandler eh)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this);
AuthorizeRequest += new EventHandler (invoker.Invoke);
}
public void AddOnBeginRequestAsync (BeginEventHandler bh, EndEventHandler eh)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this);
BeginRequest += new EventHandler (invoker.Invoke);
}
public void AddOnEndRequestAsync (BeginEventHandler bh, EndEventHandler eh)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this);
EndRequest += new EventHandler (invoker.Invoke);
}
public void AddOnPostRequestHandlerExecuteAsync (BeginEventHandler bh, EndEventHandler eh)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this);
PostRequestHandlerExecute += new EventHandler (invoker.Invoke);
}
public void AddOnPreRequestHandlerExecuteAsync (BeginEventHandler bh, EndEventHandler eh)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this);
PreRequestHandlerExecute += new EventHandler (invoker.Invoke);
}
public void AddOnReleaseRequestStateAsync (BeginEventHandler bh, EndEventHandler eh)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this);
ReleaseRequestState += new EventHandler (invoker.Invoke);
}
public void AddOnResolveRequestCacheAsync (BeginEventHandler bh, EndEventHandler eh)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this);
ResolveRequestCache += new EventHandler (invoker.Invoke);
}
public void AddOnUpdateRequestCacheAsync (BeginEventHandler bh, EndEventHandler eh)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this);
UpdateRequestCache += new EventHandler (invoker.Invoke);
}
public void AddOnPostAuthenticateRequestAsync (BeginEventHandler bh, EndEventHandler eh, object data)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh, data);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this, data);
PostAuthenticateRequest += new EventHandler (invoker.Invoke);
}
public void AddOnPostAuthorizeRequestAsync (BeginEventHandler bh, EndEventHandler eh, object data)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh, data);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this, data);
PostAuthorizeRequest += new EventHandler (invoker.Invoke);
}
public void AddOnPostResolveRequestCacheAsync (BeginEventHandler bh, EndEventHandler eh, object data)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh, data);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this, data);
PostResolveRequestCache += new EventHandler (invoker.Invoke);
}
public void AddOnPostMapRequestHandlerAsync (BeginEventHandler bh, EndEventHandler eh, object data)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh, data);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this, data);
PostMapRequestHandler += new EventHandler (invoker.Invoke);
}
public void AddOnPostAcquireRequestStateAsync (BeginEventHandler bh, EndEventHandler eh, object data)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh, data);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this, data);
PostAcquireRequestState += new EventHandler (invoker.Invoke);
}
public void AddOnPostReleaseRequestStateAsync (BeginEventHandler bh, EndEventHandler eh, object data)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh, data);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this, data);
PostReleaseRequestState += new EventHandler (invoker.Invoke);
}
public void AddOnPostUpdateRequestCacheAsync (BeginEventHandler bh, EndEventHandler eh, object data)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh, data);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this, data);
PostUpdateRequestCache += new EventHandler (invoker.Invoke);
}
//
public void AddOnAcquireRequestStateAsync (BeginEventHandler bh, EndEventHandler eh, object data)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh, data);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this, data);
AcquireRequestState += new EventHandler (invoker.Invoke);
}
public void AddOnAuthenticateRequestAsync (BeginEventHandler bh, EndEventHandler eh, object data)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh, data);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this, data);
AuthenticateRequest += new EventHandler (invoker.Invoke);
}
public void AddOnAuthorizeRequestAsync (BeginEventHandler bh, EndEventHandler eh, object data)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh, data);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this, data);
AuthorizeRequest += new EventHandler (invoker.Invoke);
}
public void AddOnBeginRequestAsync (BeginEventHandler bh, EndEventHandler eh, object data)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh, data);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this, data);
BeginRequest += new EventHandler (invoker.Invoke);
}
public void AddOnEndRequestAsync (BeginEventHandler bh, EndEventHandler eh, object data)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh, data);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this, data);
EndRequest += new EventHandler (invoker.Invoke);
}
public void AddOnPostRequestHandlerExecuteAsync (BeginEventHandler bh, EndEventHandler eh, object data)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh, data);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this, data);
PostRequestHandlerExecute += new EventHandler (invoker.Invoke);
}
public void AddOnPreRequestHandlerExecuteAsync (BeginEventHandler bh, EndEventHandler eh, object data)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh, data);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this, data);
PreRequestHandlerExecute += new EventHandler (invoker.Invoke);
}
public void AddOnReleaseRequestStateAsync (BeginEventHandler bh, EndEventHandler eh, object data)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh, data);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this, data);
ReleaseRequestState += new EventHandler (invoker.Invoke);
}
public void AddOnResolveRequestCacheAsync (BeginEventHandler bh, EndEventHandler eh, object data)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh, data);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this, data);
ResolveRequestCache += new EventHandler (invoker.Invoke);
}
public void AddOnUpdateRequestCacheAsync (BeginEventHandler bh, EndEventHandler eh, object data)
{
- AsyncInvoker invoker = new AsyncInvoker (bh, eh, data);
+ AsyncInvoker invoker = new AsyncInvoker (bh, eh, this, data);
UpdateRequestCache += new EventHandler (invoker.Invoke);
}
public void AddOnLogRequestAsync (BeginEventHandler beginHandler, EndEventHandler endHandler, object state)
{
- AsyncInvoker invoker = new AsyncInvoker (beginHandler, endHandler, state);
+ AsyncInvoker invoker = new AsyncInvoker (beginHandler, endHandler, this, state);
LogRequest += new EventHandler (invoker.Invoke);
}
public void AddOnMapRequestHandlerAsync (BeginEventHandler beginHandler, EndEventHandler endHandler, object state)
{
- AsyncInvoker invoker = new AsyncInvoker (beginHandler, endHandler, state);
+ AsyncInvoker invoker = new AsyncInvoker (beginHandler, endHandler, this, state);
MapRequestHandler += new EventHandler (invoker.Invoke);
}
public void AddOnPostLogRequestAsync (BeginEventHandler beginHandler, EndEventHandler endHandler, object state)
{
- AsyncInvoker invoker = new AsyncInvoker (beginHandler, endHandler, state);
+ AsyncInvoker invoker = new AsyncInvoker (beginHandler, endHandler, this, state);
PostLogRequest += new EventHandler (invoker.Invoke);
}
//
// If we catch an error, queue this error
//
- void ProcessError (Exception e)
+ internal void ProcessError (Exception e)
{
bool first = context.Error == null;
context.AddError (e);
return true;
}
}
-
+
+ public static void RegisterModule (Type moduleType)
+ {
+ HttpRuntimeSection config = (HttpRuntimeSection)WebConfigurationManager.GetSection ("system.web/httpRuntime");
+
+ if (!config.AllowDynamicModuleRegistration)
+ throw new InvalidOperationException ("The Application has requested to register a dynamic Module, but dynamic module registration is disabled in web.config.");
+
+ dynamicModuleManeger.Add (moduleType);
+ }
+
+
+ HttpModuleCollection CreateDynamicModules ()
+ {
+ HttpModuleCollection modules = new HttpModuleCollection ();
+
+ foreach (var module in dynamicModuleManeger.LockAndGetModules ()) {
+ IHttpModule httpModule = CreateModuleInstance (module.Type);
+ httpModule.Init (this);
+ modules.AddModule (module.Name, httpModule);
+ }
+ return modules;
+ }
+
+ IHttpModule CreateModuleInstance (Type type)
+ {
+ return (IHttpModule) Activator.CreateInstance (type,
+ BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.CreateInstance,
+ null,
+ null,
+ null);
+ }
+
#region internals
internal void ClearError ()
{
public BeginEventHandler begin;
public EndEventHandler end;
public object data;
+ HttpApplication app;
+ AsyncCallback callback;
- public AsyncInvoker (BeginEventHandler bh, EndEventHandler eh, object d)
+ public AsyncInvoker (BeginEventHandler bh, EndEventHandler eh, HttpApplication a, object d)
{
begin = bh;
end = eh;
data = d;
+ app = a;
+ callback = new AsyncCallback (doAsyncCallback);
}
- public AsyncInvoker (BeginEventHandler bh, EndEventHandler eh)
- {
- begin = bh;
- end = eh;
- }
+ public AsyncInvoker (BeginEventHandler bh, EndEventHandler eh, HttpApplication app) : this(bh, eh, app, null) { }
public void Invoke (object sender, EventArgs e)
{
- throw new Exception ("This is just a dummy");
+ IAsyncResult res;
+ res = begin (app, e, callback, data);
+ }
+
+ void doAsyncCallback (IAsyncResult res)
+ {
+ ThreadPool.QueueUserWorkItem ((object ores) => {
+ IAsyncResult tres = (IAsyncResult) ores;
+ try {
+ end (tres);
+ } catch (Exception ee) {
+ // I tried using ProcessError(), but we only come here frome an Invokation in PipelineDone().
+ // Using ProcessError, I still get a blank screen, this way, we at least log the error to console...
+ Console.Error.WriteLine (ee.ToString ());
+ }
+ }, res);
}
}
#endregion
}
+