Ejemplo n.º 1
0
        //hello/{name}
        public static void RegisterRoute(string name, Action<RouteResult> routeResult)
        {
            Route route = Routes.Where(r => r.Name == name).FirstOrDefault();
            if (route == null)
            {
                route = new Route();
                route.Segments = new List<RouteSegment>();
                route.Name = name;

                foreach (string strSegment in name.Split('/'))
                {
                    RouteSegment segment = new RouteSegment();
                    segment.Name = strSegment.Replace("{", "").Replace("}","");
                    segment.IsProperty = strSegment.StartsWith("{");
                    route.Segments.Add(segment);
                }

                Routes.Add(route);
            }

            route.Results.Add(routeResult);
        }
Ejemplo n.º 2
0
        public static List<Route> GetMatchingRoutes(string routePath)
        {
            List<Route> results = new List<Route>();

            Route temporaryRoute = new Route(); //create a route and compare it to every other route.
            temporaryRoute.Name = routePath;
            temporaryRoute.Segments = new List<RouteSegment>();
            foreach (string strSegment in routePath.Split('/'))
            {
                RouteSegment segment = new RouteSegment();
                segment.Name = strSegment.Replace("{", "").Replace("}", "");
                segment.IsProperty = strSegment.StartsWith("{");
                temporaryRoute.Segments.Add(segment);
            }

            foreach (Route route in Routes.ToList())
            {
                if (route.Equals(temporaryRoute))
                {
                    results.Add(route);
                }
            }

            return results;
        }