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); }
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()); }
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)); }
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); } }
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); }
public void AddRouter(TreeRoute router) { _SegmentRoutes.Add(router); }
public static TreeRoute ToAction(this TreeRoute router, string actionName) { router.Defaults.Add("action", actionName); return(router); }
public static TreeRoute Configure(this TreeRoute router, Action <TreeRoute> configureAction) { configureAction(router); return(router); }