/// <summary>Finds children based on the given url segments. The method supports convering the last segments into action and parameter.</summary> /// <param name="remainingUrl">The remaining url segments.</param> /// <returns>A path data object which can be empty (check using data.IsEmpty()).</returns> public virtual PathData FindPath(string remainingUrl) { if (remainingUrl == null) { return(PathDictionary.GetPath(this, string.Empty)); } remainingUrl = remainingUrl.TrimStart('/'); if (remainingUrl.Length == 0) { return(PathDictionary.GetPath(this, string.Empty)); } int slashIndex = remainingUrl.IndexOf('/'); string nameSegment = HttpUtility.UrlDecode(slashIndex < 0 ? remainingUrl : remainingUrl.Substring(0, slashIndex)); foreach (ContentItem child in GetChildren(new NullFilter())) { if (child.IsNamed(nameSegment)) { remainingUrl = slashIndex < 0 ? null : remainingUrl.Substring(slashIndex + 1); return(child.FindPath(remainingUrl)); } } return(PathDictionary.GetPath(this, remainingUrl)); }
/// <summary>Finds children based on the given url segments. The method supports convering the last segments into action and parameter.</summary> /// <param name="remainingUrl">The remaining url segments.</param> /// <returns>A path data object which can be empty (check using data.IsEmpty()).</returns> public virtual PathData FindPath(string remainingUrl) { if (remainingUrl == null) { return(PathDictionary.GetPath(this, string.Empty)); } remainingUrl = remainingUrl.TrimStart('/'); if (remainingUrl.Length == 0) { return(PathDictionary.GetPath(this, string.Empty)); } int slashIndex = remainingUrl.IndexOf('/'); string nameSegment = HttpUtility.UrlDecode(slashIndex < 0 ? remainingUrl : remainingUrl.Substring(0, slashIndex)); var child = Children.FindNamed(nameSegment); if (child != null) { remainingUrl = slashIndex < 0 ? null : remainingUrl.Substring(slashIndex + 1); return(child.FindPath(remainingUrl)); } return(PathDictionary.GetPath(this, remainingUrl)); }
public ControllerMapper(ITypeFinder typeFinder, IDefinitionManager definitionManager) { IList <ControlsAttribute> controllerDefinitions = FindControllers(typeFinder); foreach (ItemDefinition id in definitionManager.GetDefinitions()) { IAdapterDescriptor controllerDefinition = GetControllerFor(id, controllerDefinitions); if (controllerDefinition != null) { ControllerMap[id.ItemType] = controllerDefinition.ControllerName; // interacting with static context is tricky, here I made the assumtion that the last // finder is the most relevat and takes the place of previous ones, this makes a few // tests pass and doesn't seem to be called in production foreach (var finder in PathDictionary.GetFinders(id.ItemType).Where(f => f is ActionResolver)) { PathDictionary.RemoveFinder(id.ItemType, finder); } // Use MVC's ReflectedControllerDescriptor to find all actions on the Controller var methods = new ReflectedControllerDescriptor(controllerDefinition.AdapterType) .GetCanonicalActions() .Select(m => m.ActionName).ToArray(); var actionResolver = new ActionResolver(this, methods); _controllerActionMap[controllerDefinition.ControllerName] = methods; PathDictionary.PrependFinder(id.ItemType, actionResolver); } } }
/// <summary> /// get HttpResponse from the server for the specified path /// </summary> public virtual HttpResponse GetResponse(string path) { if (!string.IsNullOrEmpty(path)) { if (PathDictionary == null) { PathDictionary = new Dictionary <string, IotClientNode>(); BuildPathDictionary(PathDictionary, FullPath); } IotClientNode node; if (PathDictionary.TryGetValue(path, out node)) { return(node.GetResponse()); } else { string pathLowercase = path.ToLower(); foreach (string key in PathDictionary.Keys) { if (pathLowercase.StartsWith(key + "/")) { return(node.GetResponse()); } } } } return(GetResponse()); }
public void Refine(ItemDefinition currentDefinition, IList <ItemDefinition> allDefinitions) { inner.Refine(currentDefinition); if (inner is IPathFinder) { PathDictionary.PrependFinder(currentDefinition.ItemType, inner as IPathFinder); } }
public void MapperDoesNotMapProperties() { new ControllerMapper(typeFinder, definitions); var actionResolver = PathDictionary.GetFinders(typeof(RegularPage)).FirstOrDefault() as ActionResolver; Assert.That(actionResolver, Is.Not.Null); Assert.That(actionResolver.Methods.Length, Is.EqualTo(1)); }
public string GetPath(string key) { if (!PathDictionary.ContainsKey(key)) { return(string.Empty); } return(PathDictionary[key]); }
public bool SetPath(string key, string path) { if (PathDictionary.ContainsKey(key)) { return(false); } if (key.Is(RecordKey)) { CreateDefaultPaths(path); } PathDictionary.Add(key, path); return(true); }
public override PathData FindPath(string remainingUrl) { var path = base.FindPath(remainingUrl); if (path.IsEmpty() && !(this is LanguageRoot)) { var languageRoot = Find.ClosestOf <LanguageRoot>(this); if (languageRoot != null) { path = languageRoot.FindPath(remainingUrl); } } if (path.IsEmpty() && !(this is StartPage)) { var siteRoot = Find.ClosestOf <StartPage>(this); if (siteRoot != null) { path = siteRoot.FindPath(remainingUrl); } } if (path.IsEmpty() && !(this is LanguageIntersection)) { var languageIntersection = Find.ClosestOf <LanguageIntersection>(this); if (languageIntersection != null) { path = languageIntersection.FindPath(remainingUrl); } } if (path.IsEmpty() && remainingUrl == HttpContext.Current.Request.ApplicationPath) { return(PathDictionary.GetPath(CmsFinder.FindLanguageIntersection(), string.Empty)); } if (path.IsEmpty() && !(this is LanguageIntersection) && !(this is StartPage) && !(this is LanguageRoot)) // { path = base.FindPath("Index" + "/" + remainingUrl); } return(path); }