Ejemplo n.º 1
0
        public static TreeRoute AddWithPath(this TreeRoute router, string path, Action <TreeRoute> configure)
        {
            if (path.StartsWith("/"))
            {
                path = path.Remove(0, 1);
            }
            var segments      = path.Split('/');
            var currentRouter = router;

            foreach (var segment in segments)
            {
                var childRouter = currentRouter.ChildRouters.FirstOrDefault(r => r.SegmentTemplate == segment);
                if (childRouter != null)
                {
                    currentRouter = childRouter;
                }
                else
                {
                    var newRouter = new TreeRoute(segment);

                    currentRouter.AddChildRoute(newRouter);
                    currentRouter = newRouter;
                }
            }
            configure(currentRouter);
            return(router);
        }
Ejemplo n.º 2
0
        public static Uri GetUrlForController(this TreeRoute router, Type type, string instance = null)
        {
            var leafRouter = router.FindControllerRouter(type, instance);

            if (leafRouter == null)
            {
                return(null);
            }

            return(leafRouter.GetUrl());
        }
Ejemplo n.º 3
0
        public static Uri GetUrl(this TreeRoute router)
        {
            string url = router.SegmentTemplate;

            while (router.ParentRouter != null)
            {
                router = router.ParentRouter;
                url    = router.SegmentTemplate + @"/" + url;
            }
            return(new Uri(url, UriKind.Relative));
        }
Ejemplo n.º 4
0
 public void AddChildRoute(TreeRoute treeRoute)
 {
     treeRoute.ParentRouter = this;
     if (!treeRoute.UseRegex)  // Place static matches first before wildcard matches
     {
         _childRouters.Insert(0, treeRoute);
     }
     else
     {
         _childRouters.Add(treeRoute);
     }
 }
Ejemplo n.º 5
0
        public static TreeRoute GetAtPath(this TreeRoute router, string path)
        {
            var segments      = path.Split('/');
            var currentRouter = router;

            foreach (var segment in segments)
            {
                var childRouter = currentRouter.ChildRouters.FirstOrDefault(r => r.SegmentTemplate == segment);
                if (childRouter != null)
                {
                    currentRouter = childRouter;
                }
                else
                {
                    return(null);
                }
            }
            return(currentRouter);
        }
Ejemplo n.º 6
0
 public void AddRouter(TreeRoute router)
 {
     _SegmentRoutes.Add(router);
 }
Ejemplo n.º 7
0
 public static TreeRoute ToAction(this TreeRoute router, string actionName)
 {
     router.Defaults.Add("action", actionName);
     return(router);
 }
Ejemplo n.º 8
0
 public static TreeRoute Configure(this TreeRoute router, Action <TreeRoute> configureAction)
 {
     configureAction(router);
     return(router);
 }