public string GetUrl(ContentAddress ca) { RouteValueDictionary rvs = new RouteValueDictionary(); rvs.Add("controller", ca.Controller); rvs.Add("action", ca.Action); ControllerInfo cInfo = GetController((string)rvs["controller"]);; if (cInfo == null) { throw new MissingControllerException("Can't find controller " + ca.Controller); } for (int i = 0; i < Math.Min(cInfo.SignificantRouteKeys.Count, ca.Subindexes.Count); i++) { rvs.Add(cInfo.SignificantRouteKeys[i], ca.Subindexes[i]); } UrlPattern patt = cInfo.UrlPatterns.FirstOrDefault(up => up.Matches(rvs)); if (patt == null) { throw new StructureException("No matching pattern found on controller " + ca.Controller); } return(patt.BuildUrl(rvs)); }
public void AddController(string url, RouteValueDictionary defaults) { if (url.Contains("{controller}")) { AddPatternToAll(url, defaults); } else if (defaults.ContainsKey("controller")) { Type controllerType = AllControllers.FirstOrDefault(t => t.Name.UpTo("Controller") == (string)defaults["controller"]); if (controllerType == null) { throw new MissingControllerException("Attempt to add route to missing controller " + (string)defaults["controller"]); } ControllerInfo existing = GetController((string)defaults["controller"]); if (existing == null) { Controllers.Add(new ControllerInfo(controllerType, url, defaults)); } else { existing.TryAddPattern(url, defaults); } } else { throw new Exception("No controller specified"); } }
public ControllerInfo this[string controllerName] { get { ControllerInfo controllerInfo = GetController(controllerName); if (controllerInfo == null) { throw new MissingControllerException("Can't find controller " + controllerName); } return(controllerInfo); } }
public string GetUrl(RouteValueDictionary rvs) { if (!rvs.ContainsKey("controller")) { throw new ArgumentException("Route values for GetUrl missing controller entry"); } ControllerInfo cInfo = GetController((string)rvs["controller"]); if (cInfo == null) { throw new MissingControllerException("Can't find controller " + (string)rvs["controller"]); } UrlPattern patt = cInfo.UrlPatterns.FirstOrDefault(up => up.Matches(rvs)); if (patt == null) { throw new StructureException("No matching pattern found on controller " + cInfo.Controller.Name); } return(patt.BuildUrl(rvs)); }
public override RouteData GetRouteData(System.Web.HttpContextBase httpContext) { RouteData rd = base.GetRouteData(httpContext); if (rd == null) { return(null); } string action = rd.Values["action"] as string; RequestDataSpecification rds; try { rds = new RequestDataSpecification(rd, httpContext.Request); } catch (StructureException sEx) { if (sEx is MissingControllerException) // if controller is missing, its not a content controller, process as normal { rds = new RequestDataSpecification(rd, httpContext.Request, false); RequestDataSpecification.Current = rds; return(rd); } else { return(null); } } RequestDataSpecification.Current = rds; if (!SiteStructure.Current.HasController(rds.Controller)) { return(null); } ControllerInfo ci = SiteStructure.Current[rds.Controller]; ContentAddress ca = new ContentAddress(rds, ci.SignificantRouteKeys); ContentItem content = CollatorBuilder.Factory.Create(rd).GetContent(ca); if (content == null && action != "create") { return(null); } else { if (content != null) { RequestContent = content; } //string mode = httpContext.Request.QueryString["-mode"]; //if (mode != null) mode = mode.ToLower(); //if (!isDiverted && mode != "view" && Roles.IsUserInRole(User.EditorRole)) //{ // rd.Values["originalAction"] = rd.Values["action"]; // rd.Values["action"] = "DualWindow"; //} return(rd); } }