private Action <RouteValueDictionary> GetSetNodeRouteData(string nodeRoute, TreeNode node) => CacheHelper.Cache <Action <RouteValueDictionary> >(cacheSettings => { node.MakeComplete(true); var controllerType = pageTreeControllers .FirstOrDefault(pageTreeController => pageTreeController.PageType == node.NodeClassName || (pageTreeController.PageTreePattern?.IsMatch(nodeRoute) ?? false))? .GetType(); var modelType = controllerType?.BaseType.GetGenericArguments()[0]; if (cacheSettings.Cached) { cacheSettings.CacheDependency = CacheHelper.GetCacheDependency($"cms.node|{node.NodeID}"); } return((RouteValueDictionary values) => { if (controllerType != null) { values["controller"] = controllerType.Name.Replace("Controller", string.Empty); } values["page"] = new Page(node); if (modelType != null && modelType != typeof(Page)) { values["page"] = pageTreeModelService.GetModel(modelType, values); } }); }, new CacheSettings(60 * 24, $"{typeof(PageTreeRoutesRepository).FullName}|{nameof(RoutesDictionary)}|{node.NodeSiteID}|{nodeRoute}") );
public ActionResult Index(Page page, string path) { var searchLocations = new[] { $"~/Views{page.NodeAliasPath}/Index.cshtml", $"~/Views/{page.NodeClassName}/Index.cshtml" }; ViewEngineResult pageTreeViewResult = null; foreach (var searchLocation in searchLocations) { if (pageTreeViewResult?.View == null) { pageTreeViewResult = ViewEngines.Engines.FindView(ControllerContext, searchLocation, null); } } if (pageTreeViewResult.View == null) { if (page.GetValue(nameof(DocumentCultureDataInfo.DocumentPageTemplateConfiguration)) != null) { return(new TemplateResult(page.DocumentID)); } throw new PageTreeRoutingException( $"View for path '{path}' not found. Searched locations: {string.Join(", ", searchLocations.Select(searchLocation => $"'{searchLocation}'"))}." ); } var view = pageTreeViewResult.View as RazorView ?? TryGetFromGlimpseWrapper(pageTreeViewResult); if (view == null) { throw new PageTreeRoutingException($"View at '{pageTreeViewResult.SearchedLocations.FirstOrDefault()}' is not a '{nameof(RazorView)}'."); } HttpContext.Kentico().PageBuilder().Initialize(page.DocumentID); var viewModelType = BuildManager.GetCompiledType(view.ViewPath).BaseType.GetGenericArguments()[0]; if (viewModelType == null) { return(View(view)); } return(View(view, viewModelType == typeof(TreeNode) ? page : pageTreeModelService.GetModel(viewModelType, RouteData.Values))); }