Exemplo n.º 1
0
        /// <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="configuration"></param>
        public override void Init(MonoRailConfiguration configuration)
        {
            XmlAttribute customSessionAtt =
                configuration.ConfigSection.Attributes["customsession"];

            if (customSessionAtt == null || customSessionAtt.Value.Length == 0)
            {
                throw new ConfigurationException("The CustomSessionExtension requires that " +
                                                 "the type that implements ICustomSessionFactory be specified through the " +
                                                 "'customsession' attribute on 'monoRail' configuration node");
            }

            Type customSessType = MonoRailConfiguration.GetType(customSessionAtt.Value);

            if (customSessType == null)
            {
                throw new ConfigurationException("The Type for the custom session could not be loaded. " +
                                                 customSessionAtt.Value);
            }

            try
            {
                customSession = (ICustomSessionFactory)Activator.CreateInstance(customSessType);
            }
            catch (InvalidCastException)
            {
                throw new ConfigurationException("The Type for the custom session must " +
                                                 "implement ICustomSessionFactory. " + customSessionAtt.Value);
            }
        }
        /// <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);
            }
        }
Exemplo n.º 3
0
		/// <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;

			string customSessionAtt =
				configuration.ConfigurationSection.Attributes["customSession"];

			if (customSessionAtt == null)
			{
				String message = "The CustomSessionExtension requires that " +
				                 "the type that implements ICustomSessionFactory be specified through the " +
				                 "'customSession' attribute on 'monorail' configuration node";
				throw new ConfigurationErrorsException(message);
			}

			Type customSessType = TypeLoadUtil.GetType(customSessionAtt);

			if (customSessType == null)
			{
				String message = "The Type for the custom session could not be loaded. " +
				                 customSessionAtt;
				throw new ConfigurationErrorsException(message);
			}

			try
			{
				customSession = (ICustomSessionFactory) Activator.CreateInstance(customSessType);
			}
			catch(InvalidCastException)
			{
				String message = "The Type for the custom session must " +
				                 "implement ICustomSessionFactory. " + customSessionAtt;
				throw new ConfigurationErrorsException(message);
			}
		}