public virtual void Init(HttpApplication app)
        {
            // Keep track of the number of modules
            Interlocked.Increment(ref s_moduleCount);

            // Register our BeginRequest handler first so we can make sure everything is up to date
            // before trying to invoke user code
            app.BeginRequest += new EventHandler(OnBeginRequest);

            // Register for all the events on HttpApplication, and keep track of them in a dictionary
            _handlers = new Dictionary <string, EventHandlerWrapper>();

            EventInfo[] eventInfos = typeof(HttpApplication).GetEvents();
            foreach (EventInfo eventInfo in eventInfos)
            {
                EventHandlerWrapper eventHandlerWrapper = new EventHandlerWrapper(this);
                EventHandler        handler             = eventHandlerWrapper.Handler;
                try {
                    eventInfo.AddEventHandler(app, handler);
                } catch (TargetInvocationException tiException) {
                    if (tiException.InnerException is PlatformNotSupportedException)
                    {
                        // Ignore the event if we failed to add the handler.  This can happen with IIS7
                        // which has new events that only work in Integrated Pipeline mode
                        continue;
                    }

                    throw;
                }

                _handlers[eventInfo.Name] = eventHandlerWrapper;
            }
        }
        private void HookupScriptHandlers()
        {
            // This is done once per HttpApplication/HttpModule instance every time
            // a global.<ext> file changes

            // If it's the first request in the domain, call Application_OnStart (if any)
            if (s_firstRequest && s_buildResult != null)
            {
                s_buildResult.CallOnStartMethod();
            }

            // Hook up all the events implemented in the 'global' file
            foreach (string handlerName in _handlers.Keys)
            {
                EventHandlerWrapper eventHandlerWrapper = _handlers[handlerName];

                DynamicFunction f = null;

                if (s_buildResult != null && s_buildResult.EventHandlers != null)
                {
                    s_buildResult.EventHandlers.TryGetValue(handlerName, out f);
                }

                eventHandlerWrapper.SetDynamicFunction(f, s_globalVirtualPath);
            }
        }
Exemplo n.º 3
0
        internal void HookupHandler(IBuildProvider provider, ScriptScope moduleGlobals, object self, object target)
        {
            DynamicFunction scriptFunction = new DynamicFunction((object)moduleGlobals.GetVariable(_handlerName));

            Delegate handler = EventHandlerWrapper.GetWrapper(
                provider, self, scriptFunction, _scriptVirtualPath, typeof(EventHandler));

            _eventInfo.AddEventHandler(target, handler);
        }
Exemplo n.º 4
0
        public static Delegate GetWrapper(IBuildProvider provider, DynamicFunction f,
            string virtualPath, Type delegateType)
        {
            // Get the MethodInfo only once
            if (_handlerMethodInfo == null) {
                _handlerMethodInfo = typeof(EventHandlerWrapper).GetMethod("Handler");
            }

            EventHandlerWrapper wrapper = new EventHandlerWrapper(provider, f, virtualPath);

            // Create a delegate of the required type
            return Delegate.CreateDelegate(delegateType, wrapper, _handlerMethodInfo);
        }
        public static Delegate GetWrapper(IBuildProvider provider, DynamicFunction f,
                                          string virtualPath, Type delegateType)
        {
            // Get the MethodInfo only once
            if (_handlerMethodInfo == null)
            {
                _handlerMethodInfo = typeof(EventHandlerWrapper).GetMethod("Handler");
            }

            EventHandlerWrapper wrapper = new EventHandlerWrapper(provider, f, virtualPath);

            // Create a delegate of the required type
            return(Delegate.CreateDelegate(delegateType, wrapper, _handlerMethodInfo));
        }
Exemplo n.º 6
0
        public virtual void Init(HttpApplication app)
        {
            // Keep track of the number of modules
            Interlocked.Increment(ref s_moduleCount);

            // Register our BeginRequest handler first so we can make sure everything is up to date
            // before trying to invoke user code
            app.BeginRequest += new EventHandler(OnBeginRequest);

            // Register for all the events on HttpApplication, and keep track of them in a dictionary
            _handlers = new Dictionary<string, EventHandlerWrapper>();

            EventInfo[] eventInfos = typeof(HttpApplication).GetEvents();
            foreach (EventInfo eventInfo in eventInfos) {
                EventHandlerWrapper eventHandlerWrapper = new EventHandlerWrapper(this);
                EventHandler handler = eventHandlerWrapper.Handler;
                try {
                    eventInfo.AddEventHandler(app, handler);
                } catch (TargetInvocationException tiException) {
                    if (tiException.InnerException is PlatformNotSupportedException) {
                        // Ignore the event if we failed to add the handler.  This can happen with IIS7
                        // which has new events that only work in Integrated Pipeline mode
                        continue;
                    }

                    throw;
                }

                _handlers[eventInfo.Name] = eventHandlerWrapper;
            }
        }