Пример #1
0
 private static void LoadRoutes(
     RoutingConfiguration config,
     XmlNode node
     )
 {
     RouteDefinition.LoadRoutes(config, node);
 }
Пример #2
0
        public static RoutingConfiguration GetConfig()
        {
            RoutingConfiguration config = new RoutingConfiguration();

            String configFolderName = "~/Setup/Routes/";

            string pathToConfigFolder = System.Web.Hosting.HostingEnvironment.MapPath(configFolderName);

            if (!Directory.Exists(pathToConfigFolder)) return config;

            DirectoryInfo directoryInfo
                = new DirectoryInfo(pathToConfigFolder);

            FileInfo[] routeFiles = directoryInfo.GetFiles("*.config");

            foreach (FileInfo fileInfo in routeFiles)
            {
                XmlDocument routeConfigFile = new XmlDocument();
                routeConfigFile.Load(fileInfo.FullName);
                LoadRoutes(config, routeConfigFile.DocumentElement);

            }

            return config;
        }
Пример #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);

                }

            }
        }