/// <summary> /// Installs the exception handler. /// </summary> /// <param name="node">The node.</param> /// <param name="typeName">Name of the type.</param> private void InstallExceptionHandler(IConfiguration node, String typeName) { IExceptionHandler handler; var handlerType = TypeLoadUtil.GetType(typeName); if (handlerType == null) { var message = "The Type for the custom session could not be loaded. " + typeName; throw new ConfigurationErrorsException(message); } try { handler = (IExceptionHandler)Activator.CreateInstance(handlerType); } catch (InvalidCastException) { var message = "The Type for the custom session must " + "implement ICustomSessionFactory. " + typeName; throw new ConfigurationErrorsException(message); } var configurableHandler = handler as IConfigurableHandler; if (configurableHandler != null) { configurableHandler.Configure(node); } handler.Initialize(); if (firstHandler == null) { firstHandler = handler; } else { var navHandler = firstHandler; while (navHandler != null) { if (navHandler.Next == null) { navHandler.Next = handler; break; } navHandler = navHandler.Next; } } }
/// <summary> /// Reads the attribute <c>customSession</c> /// from <see cref="MonoRailConfiguration"/> and /// instantiate it based on the type name provided. /// </summary> /// <exception cref="ConfigurationException"> /// If the typename was not provided or the type /// could not be instantiated/found /// </exception> /// <param name="manager">The Extension Manager</param> /// <param name="configuration">The configuration</param> private void Init(ExtensionManager manager, IMonoRailConfiguration configuration) { manager.AcquireSessionState += OnAdquireSessionState; manager.ReleaseSessionState += OnReleaseSessionState; var customSessionAtt = configuration.ConfigurationSection.Attributes["customSession"]; if (customSessionAtt == null) { var message = "The CustomSessionExtension requires that " + "the type that implements ICustomSessionFactory be specified through the " + "'customSession' attribute on 'monorail' configuration node"; throw new ConfigurationErrorsException(message); } var customSessType = TypeLoadUtil.GetType(customSessionAtt); if (customSessType == null) { var message = "The Type for the custom session could not be loaded. " + customSessionAtt; throw new ConfigurationErrorsException(message); } try { customSession = (ICustomSessionFactory)Activator.CreateInstance(customSessType); } catch (InvalidCastException) { var message = "The Type for the custom session must " + "implement ICustomSessionFactory. " + customSessionAtt; throw new ConfigurationErrorsException(message); } }