private RouteResolveResult getRouteForUrl(string path, string method, RouteRole role) { RouteResolveResult result = new RouteResolveResult() { Url = path, ControllerName = role.DefaultController, ActionName = role.DefalutAction }; List <RouteSegment> segments = role.Segments; var urlSegments = path.GetUrlSegments(); for (int index = 0; index < urlSegments.Count; index++) { if (index < segments.Count) { switch (segments[index].SegmentType) { case SegmentType.Directory: if (segments[index].Segment != urlSegments[index] || segments[index].Index != index) { result = null; } break; case SegmentType.Role: if (segments [index].Index == index) { var controllerOrAction = segments [index].GetSegmentValue(urlSegments [index]); if (segments [index].RouteNames [0] == "controller") { result.ControllerName = controllerOrAction; } else //"action" { result.ActionName = controllerOrAction; } } break; case SegmentType.Parameter: var segmentValue = urlSegments[index]; result.RouteValues.Add(segments[index].RouteNames[0], segmentValue); break; } } else { int i = index - segments.Count; result.RouteValues.Add("p" + i, urlSegments[index]); } if (result == null) { break; } } if (result != null && (string.IsNullOrEmpty(result.ActionName) || string.IsNullOrEmpty(result.ControllerName))) { return(null); } return(result); }
public IRouteBuilder Map(RouteRole role) { routeRoles.Add(role); return(this); }