public static Lazy<AbstractEditorController, EditorMetadata> GetEditorDashboardAction( this DashboardItemModel dashboard, ComponentRegistrations components, out MethodInfo action) { //we need to get the controller by name var parts = dashboard.ViewName.Split('.'); if (parts.Length != 2) throw new FormatException("The string format for dashboard.ViewName for child actions must be: ControllerName.ActionName"); var controllerName = parts[0]; var controllerAction = parts[1]; var editorController = components.EditorControllers .Where(x => x.Metadata.ControllerName == controllerName).SingleOrDefault(); if (editorController == null) throw new ApplicationException("Could not find the Editor controller '" + controllerName); if (!editorController.Metadata.HasChildActionDashboards) throw new ApplicationException("The Editor controller '" + controllerName + "' is not advertising that it HasChildActionDashboards"); //now we need to get the controller's referenced child action var childAction = editorController.Metadata.ComponentType.GetMethods() .Where(x => x.Name == controllerAction && x.GetCustomAttributes(typeof(ChildActionOnlyAttribute), false).Any()) .SingleOrDefault(); if (childAction == null) throw new ApplicationException("The Editor controller '" + controllerName + "' with Action: '" + controllerAction + "' could not be found or was not attributed with a ChildActionOnlyAttribute"); action = childAction; return editorController; }
/// <summary> /// Gets the surface controller meta data and a reference to the MethodInfo object for the ChildAction to render based on the /// macro definition /// </summary> /// <param name="macro"></param> /// <param name="components"></param> /// <param name="action"></param> /// <returns></returns> public static Lazy<SurfaceController, SurfaceMetadata> GetSurfaceMacroChildAction( this MacroDefinition macro, ComponentRegistrations components, out MethodInfo action) { var parsedMacroName = MacroNameParser.ParseChildActionMacroName(macro.SelectedItem); //get the surface controller for the area/controller name var surfaceController = components.SurfaceControllers .Where(x => x.Metadata.ControllerName == parsedMacroName.ControllerName && (parsedMacroName.AreaName == "" || (x.Metadata.PluginDefinition != null && x.Metadata.PluginDefinition.PackageName == parsedMacroName.AreaName))) .SingleOrDefault(); if (surfaceController == null) throw new ApplicationException("Could not find the Surface controller '" + parsedMacroName.ControllerName); if (!surfaceController.Metadata.HasChildActionMacros) throw new ApplicationException("The Surface controller '" + parsedMacroName.ControllerName + "' is not advertising that it HasChildActionMacros"); //now we need to get the controller's referenced child action var childAction = surfaceController.Metadata.ComponentType.GetMethods() .Where(x => x.Name == parsedMacroName.ActionName && x.GetCustomAttributes(typeof(ChildActionOnlyAttribute), false).Any()) .SingleOrDefault(); if (childAction == null) throw new ApplicationException("The Surface controller '" + parsedMacroName.ControllerName + "' with Action: '" + parsedMacroName.ActionName + "' could not be found or was not attributed with a ChildActionOnlyAttribute"); action = childAction; return surfaceController; }
public RoutableRequestContext(IUmbracoApplicationContext applicationContext, ComponentRegistrations components, IRoutingEngine routingEngine) { Mandate.ParameterNotNull(applicationContext, "applicationContext"); Mandate.ParameterNotNull(components, "components"); Mandate.ParameterNotNull(routingEngine, "routingEngine"); Application = applicationContext; RegisteredComponents = components; RoutingEngine = routingEngine; }
/// <summary> /// Constructor using a specific UmbracoSettings object /// </summary> /// <param name="applicationContext"></param> /// <param name="componentRegistrar"></param> public UmbracoAreaRegistration( IUmbracoApplicationContext applicationContext, ComponentRegistrations componentRegistrar) { _applicationContext = applicationContext; _umbracoSettings = _applicationContext.Settings; _componentRegistrar = componentRegistrar; _treeControllers = _componentRegistrar.TreeControllers; _editorControllers = _componentRegistrar.EditorControllers; _surfaceControllers = _componentRegistrar.SurfaceControllers; }
public PackageAreaRegistration(DirectoryInfo packageFolder, IUmbracoApplicationContext applicationContext, ComponentRegistrations componentRegistrar) { //TODO: do we need to validate the package name?? _packageName = packageFolder.Name; _packageFolder = packageFolder; _applicationContext = applicationContext; _componentRegistrar = componentRegistrar; _treeControllers = _componentRegistrar.TreeControllers; _editorControllers = _componentRegistrar.EditorControllers; _surfaceControllers = componentRegistrar.SurfaceControllers; }
public DefaultBackOfficeRequestContext(IUmbracoApplicationContext applicationContext, HttpContextBase httpContext, ComponentRegistrations components, IPackageContext packageContext, IRoutingEngine routingEngine) : base(applicationContext, components, routingEngine) { //create the IO resolvers var urlHelper = new UrlHelper(httpContext.Request.RequestContext); DocumentTypeIconResolver = new DocumentTypeIconFileResolver(httpContext.Server, applicationContext.Settings, urlHelper); DocumentTypeThumbnailResolver = new DocumentTypeThumbnailFileResolver(httpContext.Server, applicationContext.Settings, urlHelper); ApplicationIconResolver = new ApplicationIconFileResolver(httpContext.Server, applicationContext.Settings, urlHelper); PackageContext = packageContext; }
public void InitTest() { Init(); RenderModelFactory = FakeRenderModelFactory.CreateWithApp(); var frontEndRouteHandler = new RenderRouteHandler(new TestControllerFactory(), UmbracoApplicationContext, RenderModelFactory); //register areas/routes... RouteTable.Routes.Clear(); var packageFolder = new DirectoryInfo(Path.Combine(Common.CurrentAssemblyDirectory, "App_Plugins", PluginManager.PackagesFolderName, "TestPackage")); Components = new ComponentRegistrations(new List<Lazy<MenuItem, MenuItemMetadata>>(), GetEditorMetadata(packageFolder), GetTreeMetadata(packageFolder), GetSurfaceMetadata(packageFolder), new List<Lazy<AbstractTask, TaskMetadata>>(), new List<Lazy<PropertyEditor, PropertyEditorMetadata>>(), new List<Lazy<AbstractParameterEditor, ParameterEditorMetadata>>(), new List<Lazy<DashboardMatchRule, DashboardRuleMetadata>>(), new List<Lazy<DashboardFilter, DashboardRuleMetadata>>(), new List<Lazy<Permission, PermissionMetadata>>(), new List<Lazy<AbstractMacroEngine, MacroEngineMetadata>>()); var componentRegistration = new PackageAreaRegistration(packageFolder, UmbracoApplicationContext, Components); var areaRegistration = new UmbracoAreaRegistration(UmbracoApplicationContext, Components); var installRegistration = new InstallAreaRegistration(UmbracoApplicationContext.Settings); var cmsBootstrapper = new CmsBootstrapper(UmbracoApplicationContext.Settings, areaRegistration, installRegistration, new[] {componentRegistration}, new DefaultAttributeTypeRegistry()); var renderBootstrapper = new RenderBootstrapper(UmbracoApplicationContext, frontEndRouteHandler, RenderModelFactory); //bootstrappers setup the routes cmsBootstrapper.Boot(RouteTable.Routes); renderBootstrapper.Boot(RouteTable.Routes); new UmbracoWebApplication(null, null, null).RegisterRoutes(RouteTable.Routes); }
/// <summary> /// Gets the surface controller meta data and a reference to the MethodInfo object for the ChildAction to render based on the /// macro definition /// </summary> /// <param name="macro"></param> /// <param name="components"></param> /// <param name="action"></param> /// <returns></returns> public static Lazy<SurfaceController, SurfaceMetadata> GetSurfaceMacroChildAction( this MacroDefinition macro, ComponentRegistrations components, out MethodInfo action) { //need to see if the surface controller is part of an area var areaParts = macro.SelectedItem.Split('-'); var areaName = areaParts.Length > 1 ? areaParts[0] : ""; //we need to get the surface controller by name var controllerParts = macro.SelectedItem.Split('.'); if (controllerParts.Length != 2) throw new FormatException("The string format for macro.SelectedItem for child actions must be: [AreaName-]ControllerName.ActionName"); var controllerName = controllerParts[0].Replace(areaName + "-", ""); //strip off area name and hyphen if present (will be for plug-in based surface controllers, won't be for local ones) var controllerAction = controllerParts[1]; //get the surface controller for the area/controller name var surfaceController = components.SurfaceControllers .Where(x => x.Metadata.ControllerName == controllerName && (areaName == "" || x.Metadata.PluginDefinition.PackageName == areaName)) .SingleOrDefault(); if (surfaceController == null) throw new ApplicationException("Could not find the Surface controller '" + controllerName); if (!surfaceController.Metadata.HasChildActionMacros) throw new ApplicationException("The Surface controller '" + controllerName + "' is not advertising that it HasChildActionMacros"); //now we need to get the controller's referenced child action var childAction = surfaceController.Metadata.ComponentType.GetMethods() .Where(x => x.Name == controllerAction && x.GetCustomAttributes(typeof(ChildActionOnlyAttribute), false).Any()) .SingleOrDefault(); if (childAction == null) throw new ApplicationException("The Surface controller '" + controllerName + "' with Action: '" + controllerAction + "' could not be found or was not attributed with a ChildActionOnlyAttribute"); action = childAction; return surfaceController; }
public MacroRenderer(ComponentRegistrations componentRegistrations, IRoutableRequestContext routableRequestContext) { _componentRegistrations = componentRegistrations; _routableRequestContext = routableRequestContext; _applicationContext = routableRequestContext.Application; }
public static string GetEditorUrl(this UrlHelper url, string action, Guid editorId, object actionParams, ComponentRegistrations preResolvedComponentRegistrations, UmbracoSettings preResovledSettings) { var editorMetaData = preResolvedComponentRegistrations .EditorControllers .Where(x => x.Metadata.Id == editorId) .SingleOrDefault(); if (editorMetaData == null) throw new InvalidOperationException("Could not find the editor controller with id " + editorId); var routeValDictionary = new RouteValueDictionary(actionParams); routeValDictionary["editorId"] = editorId.ToString("N"); var area = preResovledSettings.UmbracoPaths.BackOfficePath; //now, need to figure out what area this editor belongs too... var pluginDefinition = editorMetaData.Metadata.PluginDefinition; if (pluginDefinition.HasRoutablePackageArea()) { area = pluginDefinition.PackageName; } //add the plugin area to our collection routeValDictionary["area"] = area; var resolvedUrl = url.Action(action, editorMetaData.Metadata.ControllerName, routeValDictionary); return resolvedUrl; }
/// <summary> /// Returns the full unique url for an Editor /// </summary> /// <param name="url">The URL.</param> /// <param name="action">The action.</param> /// <param name="id">A HiveId object or null if no id is required</param> /// <param name="editorId">The editor id.</param> /// <param name="preResolvedComponentRegistrations">The pre resolved component registrations.</param> /// <param name="preResovledSettings"></param> /// <returns></returns> public static string GetEditorUrl(this UrlHelper url, string action, HiveId? id, Guid editorId, ComponentRegistrations preResolvedComponentRegistrations, UmbracoSettings preResovledSettings) { var idVal = GetIdVal(id); return url.GetEditorUrl(action, editorId, new { id = idVal }, preResolvedComponentRegistrations, preResovledSettings); }
/// <summary> /// Returns the editor url using the default action /// </summary> /// <param name="url">The URL.</param> /// <param name="id">The id.</param> /// <param name="editorId">The editor id.</param> /// <param name="preResolvedComponentRegistrations">The pre resolved component registrations.</param> /// <param name="preResovledSettings"></param> /// <returns></returns> public static string GetEditorUrl(this UrlHelper url, HiveId id, Guid editorId, ComponentRegistrations preResolvedComponentRegistrations, UmbracoSettings preResovledSettings) { return url.GetEditorUrl("Edit", id, editorId, preResolvedComponentRegistrations, preResovledSettings); }