private void ProcessExtensionsNode(XmlNode routingNode, MonoRailConfiguration config)
        {
            foreach (XmlNode node in routingNode.ChildNodes)
            {
                if (node.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                if (node.Name != Extension_Node_Name)
                {
                    String message = String.Format("Unexpected node '{0}' within '{1}' node. " +
                                                   "Expected {2}", node.Name, Extensions_Node_Name, Extension_Node_Name);
                    throw new ConfigurationException(message);
                }

                XmlAttribute typeAtt = node.Attributes["type"];

                if (typeAtt == null || typeAtt.Value.Length == 0)
                {
                    String message = String.Format("An {0} node must have a 'type' attribute " +
                                                   "to declare the extension full type name", Extension_Node_Name);
                    throw new ConfigurationException(message);
                }

                config.Extensions.Add(typeAtt.Value);
            }
        }
		/// <summary>
		/// Creates a configuration section handler.
		/// </summary>
		/// <param name="parent"></param>
		/// <param name="configContext">Configuration context object.</param>
		/// <param name="section"></param>
		/// <returns>The created section handler object.</returns>
		public virtual object Create(object parent, object configContext, XmlNode section)
		{
			MonoRailConfiguration config = new MonoRailConfiguration(section);
			
			Deserialize(section, config);
			
			return config;
		}
Beispiel #3
0
        /// <summary>
        /// Creates a configuration section handler.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="configContext">Configuration context object.</param>
        /// <param name="section"></param>
        /// <returns>The created section handler object.</returns>
        public virtual object Create(object parent, object configContext, XmlNode section)
        {
            var config = new MonoRailConfiguration(section);

            Deserialize(section, config);

            return(config);
        }
        protected void Validate(MonoRailConfiguration config)
        {
            if (config.CustomControllerFactory != null)
            {
                ValidateTypeImplements(config.CustomControllerFactory, typeof(IControllerFactory));
            }
            else
            {
                if (config.ControllerAssemblies.Count == 0)
                {
                    throw new ConfigurationException("Inside the node controllers, you have to specify " +
                                                     "at least one assembly entry");
                }
            }

            IList extensionTypes = new ArrayList();

            foreach (String typeName in config.Extensions)
            {
                Type extensionType = MonoRailConfiguration.GetType(typeName);

                ValidateTypeImplements(extensionType, typeof(IMonoRailExtension));

                extensionTypes.Add(extensionType);
            }

            config.Extensions = extensionTypes;

            if (config.CustomFilterFactory != null)
            {
                ValidateTypeImplements(config.CustomFilterFactory, typeof(IFilterFactory));
            }
            if (config.CustomViewComponentFactory != null)
            {
                ValidateTypeImplements(config.CustomViewComponentFactory, typeof(IViewComponentFactory));
            }
            if (config.CustomEngineTypeName != null)
            {
                ValidateTypeImplements(config.CustomEngineTypeName, typeof(IViewEngine));
            }
            if (config.ViewsPhysicalPath == null || config.ViewsPhysicalPath.Length == 0)
            {
                throw new ConfigurationException("You must provide a '" + Views_Node_Name + "' node and a " +
                                                 "absolute or relative path to the views directory with the attribute " + View_Path_Root);
            }

            // Reasonable assumption

            if (config.ControllerAssemblies.Count != 0 && config.ComponentsAssemblies.Count == 0)
            {
                foreach (String entry in config.ControllerAssemblies)
                {
                    config.ComponentsAssemblies.Add(entry);
                }
            }
        }
        private void ProcessComponentFactoryNode(XmlNode node, MonoRailConfiguration config)
        {
            XmlAttribute type = node.Attributes["type"];

            if (type == null)
            {
                throw new ConfigurationException("The custom controller factory node must specify a 'type' attribute");
            }

            config.CustomViewComponentFactory = type.Value;
        }
		private static void AssertCommon( MonoRailConfiguration config )
		{
			Assert.AreEqual( "castleproject.org", config.SmtpConfig.Host);
			Assert.AreEqual( "secret", config.SmtpConfig.Password);
			Assert.AreEqual( "JoeDoe", config.SmtpConfig.Username);
			Assert.AreEqual( "Castle.MonoRail.Framework.Views.NVelocity.NVelocityViewEngine", 
			                 config.ViewEngineConfig.ViewEngines[0].Engine.FullName );			
			Assert.AreEqual( "MoviesDemo", config.ControllersConfig.Assemblies[0] );
	
			Assert.IsTrue( config.ViewEngineConfig.ViewPathRoot.EndsWith("views") );
		}
        private void ProcessComponentsNode(XmlNode controllersNode, MonoRailConfiguration config)
        {
            foreach (XmlNode node in controllersNode.ChildNodes)
            {
                if (node.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                ProcessComponentEntry(node, config);
            }
        }
        private void ProcessRoutingNode(XmlNode routingNode, MonoRailConfiguration config)
        {
            foreach (XmlNode node in routingNode.ChildNodes)
            {
                if (node.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                ProcessRuleEntry(node, config);
            }
        }
        private void ProcessComponentEntry(XmlNode componentNode, MonoRailConfiguration config)
        {
            if (!componentNode.HasChildNodes)
            {
                throw new ConfigurationException("Inside the node components, you have to specify the assemblies " +
                                                 "through the value of each child node");
            }

            String assemblyName = componentNode.FirstChild.Value;

            config.ComponentsAssemblies.Add(assemblyName);
        }
Beispiel #10
0
        internal static MonoRailConfiguration GetConfig()
        {
            MonoRailConfiguration config = (MonoRailConfiguration)
                                           ConfigurationSettings.GetConfig(MonoRailConfiguration.SectionName);

            if (config == null)
            {
                throw new ApplicationException("Unfortunately, you have to provide " +
                                               "a small configuration to use MonoRail. Check the samples or the documentation.");
            }

            return(config);
        }
        private void ProcessRuleEntry(XmlNode node, MonoRailConfiguration config)
        {
            XmlNode patternNode = node.SelectSingleNode("pattern");
            XmlNode replaceNode = node.SelectSingleNode("replace");

            if (patternNode == null || patternNode.ChildNodes[0] == null)
            {
                throw new ConfigurationException("A rule node must have a pattern (child) node denoting the regular expression to be matched");
            }
            if (replaceNode == null || replaceNode.ChildNodes[0] == null)
            {
                throw new ConfigurationException("A rule node must have a replace (child) node denoting the string to be replaced");
            }

            String pattern = patternNode.ChildNodes[0].Value;
            String replace = replaceNode.ChildNodes[0].Value;

            config.RoutingRules.Add(new RoutingRule(pattern.Trim(), replace.Trim()));
        }
        private void ProcessViewNode(XmlNode node, MonoRailConfiguration config)
        {
            XmlAttribute viewPath = node.Attributes[View_Path_Root];

            if (viewPath == null)
            {
                throw new ConfigurationException("The views node must specify the '" + View_Path_Root +
                                                 "' attribute");
            }

            String path = viewPath.Value;

            if (!Path.IsPathRooted(path))
            {
                path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path);
            }

            config.ViewsPhysicalPath = path;

            XmlAttribute xhtmlRendering = node.Attributes["xhtmlRendering"];

            if (xhtmlRendering != null)
            {
                try
                {
                    config.ViewsXhtmlRendering = bool.Parse(xhtmlRendering.Value);
                }
                catch (FormatException ex)
                {
                    throw new ConfigurationException("The xhtmlRendering attribute of the views node must be a boolean value.", ex);
                }
            }

            XmlAttribute customEngine = node.Attributes["customEngine"];

            if (customEngine != null)
            {
                config.CustomEngineTypeName = customEngine.Value;
            }
        }
        public object Create(object parent, object configContext, XmlNode section)
        {
            MonoRailConfiguration config = new MonoRailConfiguration();

            config.ConfigSection = section;

            XmlAttribute useWindsorAtt = section.Attributes["useWindsorIntegration"];

            if (useWindsorAtt != null && "true".Equals(useWindsorAtt.Value))
            {
                ConfigureWindsorIntegration(config);
            }

            XmlAttribute smtpHostAtt = section.Attributes["smtpHost"];
            XmlAttribute smtpUserAtt = section.Attributes["smtpUsername"];
            XmlAttribute smtpPwdAtt  = section.Attributes["smtpPassword"];

            if (smtpHostAtt != null && smtpHostAtt.Value != String.Empty)
            {
                config.SmtpConfig.Host = smtpHostAtt.Value;
            }
            if (smtpUserAtt != null && smtpUserAtt.Value != String.Empty)
            {
                config.SmtpConfig.Username = smtpUserAtt.Value;
            }
            if (smtpPwdAtt != null && smtpPwdAtt.Value != String.Empty)
            {
                config.SmtpConfig.Password = smtpPwdAtt.Value;
            }

            foreach (XmlNode node in section.ChildNodes)
            {
                if (node.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                if (String.Compare(Controllers_Node_Name, node.Name, true) == 0)
                {
                    ProcessControllersNode(node, config);
                }
                else if (String.Compare(Components_Node_Name, node.Name, true) == 0)
                {
                    ProcessComponentsNode(node, config);
                }
                else if (String.Compare(Views_Node_Name, node.Name, true) == 0)
                {
                    ProcessViewNode(node, config);
                }
                else if (String.Compare(Custom_Controller_Factory_Node_Name, node.Name, true) == 0)
                {
                    ProcessControllerFactoryNode(node, config);
                }
                else if (String.Compare(Custom_Component_Factory_Node_Name, node.Name, true) == 0)
                {
                    ProcessComponentFactoryNode(node, config);
                }
                else if (String.Compare(Custom_Filter_Factory_Node_Name, node.Name, true) == 0)
                {
                    ProcessFilterFactoryNode(node, config);
                }
                else if (String.Compare(Routing_Node_Name, node.Name, true) == 0)
                {
                    ProcessRoutingNode(node, config);
                }
                else if (String.Compare(Extensions_Node_Name, node.Name, true) == 0)
                {
                    ProcessExtensionsNode(node, config);
                }
            }

            Validate(config);

            return(config);
        }
 private void ConfigureWindsorIntegration(MonoRailConfiguration config)
 {
     config.CustomControllerFactory    = "Castle.MonoRail.WindsorExtension.WindsorControllerFactory, Castle.MonoRail.WindsorExtension";
     config.CustomFilterFactory        = "Castle.MonoRail.WindsorExtension.WindsorFilterFactory, Castle.MonoRail.WindsorExtension";
     config.CustomViewComponentFactory = "Castle.MonoRail.WindsorExtension.WindsorViewComponentFactory, Castle.MonoRail.WindsorExtension";
 }
        public void ShouldSetupBrail()
        {
            var config = new MonoRailConfiguration();
              app.Configure(config);

              Assert.That(config.ViewEngineConfig.ViewPathRoot.EndsWith("\\Views", StringComparison.OrdinalIgnoreCase));
              Assert.That(config.ViewEngineConfig.ViewEngines.Any(x => x.Engine == typeof(BooViewEngine)));
        }
		/// <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, MonoRailConfiguration configuration)
		{
			manager.AcquireSessionState += OnAdquireSessionState;
			manager.ReleaseSessionState += OnReleaseSessionState;

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

			if (customSessionAtt == null || customSessionAtt.Value.Length == 0)
			{
				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.Value);

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

			try
			{
				customSession = (ICustomSessionFactory) Activator.CreateInstance(customSessType);
			}
			catch(InvalidCastException)
			{
				String message = "The Type for the custom session must " + 
					"implement ICustomSessionFactory. " + customSessionAtt.Value;
				throw new ConfigurationErrorsException(message);
			}
		}
		/// <summary>
		/// Deserializes the config section.
		/// </summary>
		/// <param name="section">The section.</param>
		/// <param name="config">The config.</param>
		private void Deserialize(XmlNode section, MonoRailConfiguration config)
		{
			config.Deserialize(section);
		}
Beispiel #18
0
 /// <summary>
 /// Deserializes the config section.
 /// </summary>
 /// <param name="section">The section.</param>
 /// <param name="config">The config.</param>
 private void Deserialize(XmlNode section, MonoRailConfiguration config)
 {
     config.Deserialize(section);
 }