示例#1
0
 public static void Load(
     RouteDefinition route,
     XmlNode defaultsNode)
 {
     foreach (XmlNode node in defaultsNode.ChildNodes)
     {
         if (node.Name == "add")
         {
             if (
                 (node.Attributes["parameterName"] != null) &&
                 (node.Attributes["restriction"] != null)
                 )
             {
                 RouteRestriction r = new RouteRestriction();
                 r.parameterName = node.Attributes["parameterName"].Value;
                 r.restriction   = node.Attributes["restriction"].Value;
                 route.RouteRestrictions.Add(r);
             }
         }
     }
 }
示例#2
0
        public static void Load(
            RouteDefinition route,
            XmlNode defaultsNode)
        {
            foreach (XmlNode node in defaultsNode.ChildNodes)
            {
                if (node.Name == "add")
                {
                    if (
                        (node.Attributes["parameterName"] != null)
                        && (node.Attributes["restriction"] != null)
                        )
                    {
                        RouteRestriction r = new RouteRestriction();
                        r.parameterName = node.Attributes["parameterName"].Value;
                        r.restriction = node.Attributes["restriction"].Value;
                        route.RouteRestrictions.Add(r);
                    }

                }

            }
        }
示例#3
0
        public static void LoadRoutes(
            RoutingConfiguration config,
            XmlNode documentElement)
        {
            if (HttpContext.Current == null)
            {
                return;
            }
            if (documentElement.Name != "Routes")
            {
                return;
            }

            foreach (XmlNode node in documentElement.ChildNodes)
            {
                if (node.Name == "Route")
                {
                    RouteDefinition routeDef = new RouteDefinition();

                    XmlAttributeCollection attributeCollection
                        = node.Attributes;

                    if (attributeCollection["name"] != null)
                    {
                        routeDef.name = attributeCollection["name"].Value;
                    }

                    if (attributeCollection["routeUrl"] != null)
                    {
                        routeDef.routeUrl = attributeCollection["routeUrl"].Value;
                    }

                    if (attributeCollection["virtualPath"] != null)
                    {
                        routeDef.virtualPath = attributeCollection["virtualPath"].Value;
                    }

                    if (attributeCollection["routeHandler"] != null && typeof(IRouteHandler).IsAssignableFrom(Type.GetType(attributeCollection["routeHandler"].Value)))
                    {
                        routeDef.routeHandler = Activator.CreateInstance(Type.GetType(attributeCollection["routeHandler"].Value)) as IRouteHandler;
                    }


                    foreach (XmlNode child in node.ChildNodes)
                    {
                        if (child.Name == "Defaults")
                        {
                            RouteDefault.Load(
                                routeDef,
                                child);
                        }

                        if (child.Name == "Restrictions")
                        {
                            RouteRestriction.Load(
                                routeDef,
                                child);
                        }
                    }

                    config.RouteDefinitions.Add(routeDef);
                }
            }
        }