Example #1
0
 static string AttValue(string name, XmlNode node)
 {
     return(HandlersUtil.ExtractAttributeValue(name, node, true));
 }
Example #2
0
        public virtual object Create(object parent, object configContext, XmlNode section)
        {
            HandlerFactoryConfiguration mapper;

            if (parent is HandlerFactoryConfiguration)
            {
                mapper = new HandlerFactoryConfiguration((HandlerFactoryConfiguration)parent);
            }
            else
            {
                mapper = new HandlerFactoryConfiguration(null);
            }

            if (section.Attributes != null && section.Attributes.Count != 0)
            {
                HandlersUtil.ThrowException("Unrecognized attribute", section);
            }

            XmlNodeList httpHandlers = section.ChildNodes;

            foreach (XmlNode child in httpHandlers)
            {
                XmlNodeType ntype = child.NodeType;
                if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment)
                {
                    continue;
                }

                if (ntype != XmlNodeType.Element)
                {
                    HandlersUtil.ThrowException("Only elements allowed", child);
                }

                string name = child.Name;
                if (name == "clear")
                {
                    if (child.Attributes != null && child.Attributes.Count != 0)
                    {
                        HandlersUtil.ThrowException("Unrecognized attribute", child);
                    }

                    mapper.Clear();
                    continue;
                }

                string verb        = HandlersUtil.ExtractAttributeValue("verb", child);
                string path        = HandlersUtil.ExtractAttributeValue("path", child);
                string validateStr = HandlersUtil.ExtractAttributeValue("validate", child, true);
                bool   validate;
                if (validateStr == null)
                {
                    validate = true;
                }
                else
                {
#if NET_2_0
                    validate = "true" == validateStr.ToLower(CultureInfo.InvariantCulture);
                    if (!validate && "false" != validateStr.ToLower(CultureInfo.InvariantCulture))
#else
                    validate = validateStr == "true";
                    if (!validate && validateStr != "false")
#endif
                    { HandlersUtil.ThrowException(
                          "Invalid value for validate attribute.", child); }
                }

                if (name == "add")
                {
                    string type = HandlersUtil.ExtractAttributeValue("type", child);
                    if (child.Attributes != null && child.Attributes.Count != 0)
                    {
                        HandlersUtil.ThrowException("Unrecognized attribute", child);
                    }

                    mapper.Add(verb, path, type, validate);
                    continue;
                }

                if (name == "remove")
                {
                    if (child.Attributes != null && child.Attributes.Count != 0)
                    {
                        HandlersUtil.ThrowException("Unrecognized attribute", child);
                    }

                    if (validate && false == mapper.Remove(verb, path))
                    {
                        HandlersUtil.ThrowException("There's no mapping to remove", child);
                    }

                    continue;
                }
                HandlersUtil.ThrowException("Unexpected element", child);
            }

            return(mapper);
        }
Example #3
0
 // A few methods to save some typing
 static string AttValue(string name, XmlNode node, bool optional)
 {
     return(HandlersUtil.ExtractAttributeValue(name, node, optional));
 }
Example #4
0
        public virtual object Create(object parent, object configContext, XmlNode section)
        {
            ModulesConfiguration mapper;

            if (parent is ModulesConfiguration)
            {
                mapper = new ModulesConfiguration((ModulesConfiguration)parent);
            }
            else
            {
                mapper = new ModulesConfiguration(null);
            }

            if (section.Attributes != null && section.Attributes.Count != 0)
            {
                HandlersUtil.ThrowException("Unrecognized attribute", section);
            }

            XmlNodeList httpModules = section.ChildNodes;

            foreach (XmlNode child in httpModules)
            {
                XmlNodeType ntype = child.NodeType;
                if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment)
                {
                    continue;
                }

                if (ntype != XmlNodeType.Element)
                {
                    HandlersUtil.ThrowException("Only elements allowed", child);
                }

                string name = child.Name;
                if (name == "clear")
                {
                    if (child.Attributes.Count != 0)
                    {
                        HandlersUtil.ThrowException("Unrecognized attribute", child);
                    }

                    mapper.Clear();
                    continue;
                }

                string name_attr = HandlersUtil.ExtractAttributeValue("name", child);
                if (name == "add")
                {
                    string type = HandlersUtil.ExtractAttributeValue("type", child);
                    if (child.Attributes.Count != 0)
                    {
                        HandlersUtil.ThrowException("Unrecognized attribute", child);
                    }

                    // FIXME: gotta remove this. Just here to make it work with my local config
                    if (type.StartsWith("System.Web.Mobile"))
                    {
                        continue;
                    }

                    mapper.Add(name_attr, type);
                    continue;
                }

                if (name == "remove")
                {
                    if (child.Attributes.Count != 0)
                    {
                        HandlersUtil.ThrowException("Unrecognized attribute", child);
                    }

                    if (mapper.Remove(name_attr) == null)
                    {
                        HandlersUtil.ThrowException("Module not loaded", child);
                    }
                    continue;
                }

                HandlersUtil.ThrowException("Unrecognized element", child);
            }

            mapper.Add("DefaultAuthentication", typeof(DefaultAuthenticationModule));

            return(mapper);
        }