Exemplo n.º 1
0
        /// <summary>
        /// Create the routes to handle tree requests
        /// </summary>
        /// <param name="routes"></param>
        /// <param name="treeControllers"></param>
        private void MapRouteTrees(RouteCollection routes, IEnumerable <TreeMetadata> treeControllers)
        {
            //get the core ubmraco trees
            var defaultTreeTypes = treeControllers.Where(x => x.IsInternalRebelTree);

            //First, register the special default route for the ApplicationTreeController, this is required
            //because this special tree doesn't take a HiveId as a parameter but an application name (string)
            //in order for it to render all trees in the application routed
            var applicationTreeControllerName = RebelController.GetControllerName(typeof(ApplicationTreeController));
            var applicationTreeControllerId   = RebelController.GetControllerId <TreeAttribute>(typeof(ApplicationTreeController));
            var route = routes.MapRoute(
                ApplicationTreeRouteName,                                                      //name
                AreaName + "/Trees/" + applicationTreeControllerName + "/{action}/{appAlias}", //url to match
                new { controller = applicationTreeControllerName, action = "Index", appAlias = "content", treeId = applicationTreeControllerId.ToString("N") },
                new { backOffice = new BackOfficeRouteConstraint(_applicationContext) },
                new[] { typeof(ApplicationTreeController).Namespace }); //only match this namespace

            route.DataTokens.Add("area", AreaName);                     //only match this area
            route.DataTokens.Add("rebel", "backoffice");                //ensure the rebel token is set

            //Register routes for the default trees
            foreach (var t in defaultTreeTypes)
            {
                this.RouteControllerPlugin(t.Id, t.ControllerName, t.ComponentType, routes, "treeId", "Tree", "Trees", "Index", HiveId.Empty, true, _applicationContext);
            }

            //now, we need to get the 'internal' trees, these could be not part of a package and just exist in the 'bin' if someone just developed their
            //trees in VS in their local Rebel project
            var localTrees = treeControllers.Where(x => x.PluginDefinition == null && x.Id != applicationTreeControllerId);

            foreach (var t in localTrees)
            {
                this.RouteControllerPlugin(t.Id, t.ControllerName, t.ComponentType, routes, "treeId", "Tree", "Trees", "Index", HiveId.Empty, true, _applicationContext);
            }
        }
        /// <summary>
        /// This adds some required elements to the ViewBag so that the Create view renders correctly
        /// </summary>
        /// <param name="model"></param>
        protected virtual void EnsureViewData(CreateFileModel model)
        {
            var controllerName = RebelController.GetControllerName(this.GetType());

            // Update thumbnails
            var thumbnailFolder = Url.Content(BackOfficeRequestContext.Application.Settings.RebelFolders.DocTypeThumbnailFolder);

            model.AvailableFileExtensions = AllowedFileExtensions;
            model.FileThumbnail           = thumbnailFolder + "/doc.png";
            model.FolderThumbnail         = thumbnailFolder + "/folder.png";

            // Populate avilable stubs
            var stubDirHiveId = new HiveId(new Uri("storage://stubs"), "stubs", new HiveIdValue(controllerName));
            var stubHive      = BackOfficeRequestContext.Application.Hive.GetReader <IFileStore>(stubDirHiveId.ToUri());

            using (var uow = stubHive.CreateReadonly())
            {
                var stubFileRelations = uow.Repositories.GetChildRelations(stubDirHiveId, FixedRelationTypes.DefaultRelationType);
                if (stubFileRelations.Any())
                {
                    var stubFiles = uow.Repositories.Get <File>(true, stubFileRelations.Select(x => x.DestinationId).ToArray());
                    if (stubFiles.Any())
                    {
                        model.AvailableStubs = stubFiles.Select(x => new SelectListItem {
                            Text = x.Name, Value = x.Id.ToString()
                        });
                    }
                }
            }

            // Populate viewbag
            ViewBag.Title        = CreateNewTitle;
            ViewBag.ControllerId = RebelController.GetControllerId <EditorAttribute>(GetType());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Return the tree url for a specified application
        /// </summary>
        /// <param name="url"></param>
        /// <param name="applicationAlias"></param>
        /// <returns></returns>
        public static string GetTreeUrl(this UrlHelper url, string applicationAlias)
        {
            var appTreeControllerName = RebelController.GetControllerName(typeof(ApplicationTreeController));
            var appTreeControllerId   =
                RebelController.GetControllerId <TreeAttribute>(typeof(ApplicationTreeController));

            return(url.Action("Index", appTreeControllerName,
                              new { area = url.GetBackOfficeArea(), appAlias = applicationAlias, treeId = appTreeControllerId.ToString("N") }));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns a RouteDefinition object based on the current renderModel
        /// </summary>
        /// <param name="requestContext"></param>
        /// <param name="renderModel"></param>
        /// <returns></returns>
        protected virtual RouteDefinition GetRebelRouteDefinition(RequestContext requestContext, IRebelRenderModel renderModel)
        {
            //creates the default route definition which maps to the 'RebelController' controller
            var def = new RouteDefinition
            {
                ControllerName = RebelController.GetControllerName <RebelController>(),
                Controller     = new RebelController(),
                RenderModel    = renderModel,
                ActionName     = ((Route)requestContext.RouteData.Route).Defaults["action"].ToString()
            };

            //check that a template is defined)
            if (renderModel.CurrentNode != null && renderModel.CurrentNode.CurrentTemplate != null)
            {
                using (var uow = _applicationContext.Hive.OpenReader <IFileStore>(new Uri("storage://templates")))
                {
                    var template = uow.Repositories.Get <File>(renderModel.CurrentNode.CurrentTemplate.Id);

                    //check if there's a custom controller assigned, base on the document type alias.
                    var controller = _controllerFactory.CreateController(requestContext, renderModel.CurrentNode.ContentType.Alias);

                    //check if that controller exists
                    if (controller != null)
                    {
                        //ensure the controller is of type 'RebelController'
                        if (controller is RebelController)
                        {
                            //set the controller and name to the custom one
                            def.Controller     = (ControllerBase)controller;
                            def.ControllerName = RebelController.GetControllerName(controller.GetType());
                        }
                        else
                        {
                            LogHelper.Warn <RenderRouteHandler>("The current Document Type {0} matches a locally declared controller of type {1}. Custom Controllers for Rebel routing must inherit from '{2}'.", renderModel.CurrentNode.ContentType.Alias, controller.GetType().FullName, typeof(RebelController).FullName);
                            //exit as we cannnot route to the custom controller, just route to the standard one.
                            return(def);
                        }

                        // Template might be null if none is assigned to the node
                        if (template != null)
                        {
                            //check if the custom controller has an action with the same name as the template name (we convert ToRebelAlias since the template name might have invalid chars).
                            //NOTE: This also means that all custom actions MUST be PascalCase.. but that should be standard.
                            var templateName = template.Name.Split('.')[0].ToRebelAlias(StringAliasCaseType.PascalCase);
                            var action       = controller.GetType().GetMethod(templateName);
                            if (action != null)
                            {
                                def.ActionName = templateName;
                            }
                            //otherwise it will continue to route to Index since thats teh default route
                        }
                    }
                }
            }

            return(def);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns the default dashboard url
        /// </summary>
        /// <param name="url"></param>
        /// <param name="appAlias">The application (i.e. content) to render the dashboard for</param>
        /// <returns></returns>
        public static string GetDashboardUrl(this UrlHelper url, string appAlias)
        {
            var dashboardControllerName = RebelController.GetControllerName(typeof(DashboardEditorController));
            var dashboardControllerId   =
                RebelController.GetControllerId <EditorAttribute>(typeof(DashboardEditorController));

            return(url.Action("Dashboard",
                              dashboardControllerName,
                              new { editorId = dashboardControllerId.ToString("N"), appAlias = appAlias }));
        }
Exemplo n.º 6
0
        public void BackOfficeRouting_Ensure_Plugin_Tree_Url_Structures()
        {
            //Arrange

            var context = new FakeHttpContextFactory("~/empty", new RouteData());

            var contentTree           = new Stubs.Trees.ContentTreeController(new FakeBackOfficeRequestContext());
            var contentControllerName = RebelController.GetControllerName(contentTree.GetType());
            var contentControllerId   = RebelController.GetControllerId <TreeAttribute>(contentTree.GetType());

            var mediaTree = new Stubs.Trees.MediaTreeController(new FakeBackOfficeRequestContext());
            var mediaTreeControllerName = RebelController.GetControllerName(mediaTree.GetType());
            var mediaTreeControllerId   = RebelController.GetControllerId <TreeAttribute>(mediaTree.GetType());

            const string action    = "Index";
            var          defaultId = HiveId.Empty;
            const int    customId  = 123;
            const string area      = "TestPackage";

            //Act

            //ensure the area is passed in because we're matchin a URL in an area, otherwise it will not work

            var contentTreeDefaultUrl = UrlHelper.GenerateUrl(null, action, contentControllerName,
                                                              new RouteValueDictionary(new { area, id = defaultId, treeId = contentControllerId.ToString("N") }),
                                                              RouteTable.Routes, context.RequestContext, true);

            var mediaTreeDefaultUrl = UrlHelper.GenerateUrl(null, action, mediaTreeControllerName,
                                                            new RouteValueDictionary(new { area, id = defaultId, treeId = mediaTreeControllerId.ToString("N") }),
                                                            RouteTable.Routes, context.RequestContext, true);

            var contentTreeCustomUrl = UrlHelper.GenerateUrl(null, action, contentControllerName,
                                                             new RouteValueDictionary(new { area, id = customId, treeId = contentControllerId.ToString("N") }),
                                                             RouteTable.Routes, context.RequestContext, true);

            var mediaTreeCustomUrl = UrlHelper.GenerateUrl(null, action, mediaTreeControllerName,
                                                           new RouteValueDictionary(new { area, id = customId, treeId = mediaTreeControllerId.ToString("N") }),
                                                           RouteTable.Routes, context.RequestContext, true);

            //Assert

            //Assert.AreEqual(string.Format("/Rebel/TestPackage/Trees/{0}/{1}", contentControllerId.ToString("N"), contentControllerName), contentTreeDefaultUrl);
            //Assert.AreEqual(string.Format("/Rebel/TestPackage/Trees/{0}/{1}", mediaTreeControllerId.ToString("N"), mediaTreeControllerName), mediaTreeDefaultUrl);
            //Assert.AreEqual(string.Format("/Rebel/TestPackage/Trees/{0}/{1}/{2}/{3}", contentControllerId.ToString("N"), contentControllerName, action, customId), contentTreeCustomUrl);
            //Assert.AreEqual(string.Format("/Rebel/TestPackage/Trees/{0}/{1}/{2}/{3}", mediaTreeControllerId.ToString("N"), mediaTreeControllerName, action, customId), mediaTreeCustomUrl);

            Assert.AreEqual(string.Format("/Rebel/TestPackage/{0}", contentControllerName), contentTreeDefaultUrl);
            Assert.AreEqual(string.Format("/Rebel/TestPackage/{0}", mediaTreeControllerName), mediaTreeDefaultUrl);
            Assert.AreEqual(string.Format("/Rebel/TestPackage/{0}/{1}/{2}", contentControllerName, action, customId), contentTreeCustomUrl);
            Assert.AreEqual(string.Format("/Rebel/TestPackage/{0}/{1}/{2}", mediaTreeControllerName, action, customId), mediaTreeCustomUrl);
        }
Exemplo n.º 7
0
        public void BackOfficeRouting_Ensure_Plugin_Editor_Url_Structures()
        {
            //Arrange

            var context = new FakeHttpContextFactory("~/empty", new RouteData());

            var contentEditor         = new Stubs.Editors.ContentEditorController(new FakeBackOfficeRequestContext());
            var contentControllerName = RebelController.GetControllerName(contentEditor.GetType());
            var contentControllerId   = RebelController.GetControllerId <EditorAttribute>(contentEditor.GetType());

            var mediaEditorController = new Stubs.Editors.MediaEditorController(new FakeBackOfficeRequestContext());
            var mediaControllerName   = RebelController.GetControllerName(mediaEditorController.GetType());
            var mediaControllerId     = RebelController.GetControllerId <EditorAttribute>(mediaEditorController.GetType());

            const string customAction  = "Index";
            const string defaultAction = "Dashboard";
            const int    id            = -1;
            const string area          = "TestPackage";

            //Act

            //ensure the area is passed in because we're matchin a URL in an area, otherwise it will not work

            var contentEditorDefaultUrl = UrlHelper.GenerateUrl(null, defaultAction, contentControllerName,
                                                                new RouteValueDictionary(new { area, id = UrlParameter.Optional, editorId = contentControllerId.ToString("N") }),
                                                                RouteTable.Routes, context.RequestContext, true);

            var dataTypeEditorDefaulturl = UrlHelper.GenerateUrl(null, defaultAction, mediaControllerName,
                                                                 new RouteValueDictionary(new { area, id = UrlParameter.Optional, editorId = mediaControllerId.ToString("N") }),
                                                                 RouteTable.Routes, context.RequestContext, true);

            var contentEditorCustomUrl = UrlHelper.GenerateUrl(null, customAction, contentControllerName,
                                                               new RouteValueDictionary(new { area, id, editorId = contentControllerId.ToString("N") }),
                                                               RouteTable.Routes, context.RequestContext, true);

            var dataTypeEditorCustomurl = UrlHelper.GenerateUrl(null, customAction, mediaControllerName,
                                                                new RouteValueDictionary(new { area, id, editorId = mediaControllerId.ToString("N") }),
                                                                RouteTable.Routes, context.RequestContext, true);

            //Assert

            //Assert.AreEqual(string.Format("/Rebel/TestPackage/Editors/{0}/{1}", contentControllerId.ToString("N"), contentControllerName), contentEditorDefaultUrl);
            //Assert.AreEqual(string.Format("/Rebel/TestPackage/Editors/{0}/{1}", mediaControllerId.ToString("N"), mediaControllerName), dataTypeEditorDefaulturl);
            //Assert.AreEqual(string.Format("/Rebel/TestPackage/Editors/{0}/{1}/{2}/{3}", contentControllerId.ToString("N"), contentControllerName, customAction, id), contentEditorCustomUrl);
            //Assert.AreEqual(string.Format("/Rebel/TestPackage/Editors/{0}/{1}/{2}/{3}", mediaControllerId.ToString("N"), mediaControllerName, customAction, id), dataTypeEditorCustomurl);

            Assert.AreEqual(string.Format("/Rebel/TestPackage/{0}", contentControllerName), contentEditorDefaultUrl);
            Assert.AreEqual(string.Format("/Rebel/TestPackage/{0}", mediaControllerName), dataTypeEditorDefaulturl);
            Assert.AreEqual(string.Format("/Rebel/TestPackage/{0}/{1}/{2}", contentControllerName, customAction, id), contentEditorCustomUrl);
            Assert.AreEqual(string.Format("/Rebel/TestPackage/{0}/{1}/{2}", mediaControllerName, customAction, id), dataTypeEditorCustomurl);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Returns the dashboard Url for a specified controller
        /// </summary>
        /// <param name="url"></param>
        /// <param name="controllerType"></param>
        /// <param name="appAlias">The application (i.e. content) to render the dashboard for</param>
        /// <returns></returns>
        public static string GetDashboardUrl(this UrlHelper url, Type controllerType, string appAlias)
        {
            Mandate.ParameterNotNull(controllerType, "controllerType");

            if (!controllerType.GetCustomAttributes(typeof(EditorAttribute), false).Any())
            {
                throw new InvalidCastException("The controller type specified is not of type BaseEditorController");
            }
            return(url.Action("Dashboard",
                              RebelController.GetControllerName(controllerType),
                              new
            {
                editorId = RebelController.GetControllerId <EditorAttribute>(controllerType).ToString("N"),
                appAlias = appAlias
            }));
        }
Exemplo n.º 9
0
        public void BackOfficeRouting_Ensure_Default_Tree_Url_Structures()
        {
            //Arrange

            var context = new FakeHttpContextFactory("~/empty", new RouteData());

            var contentTree           = new ContentTreeController(new FakeBackOfficeRequestContext());
            var contentControllerName = RebelController.GetControllerName(contentTree.GetType());
            var contentControllerId   = RebelController.GetControllerId <TreeAttribute>(contentTree.GetType());

            var dataTypeTree           = new DataTypeTreeController(new FakeBackOfficeRequestContext());
            var dataTypeControllerName = RebelController.GetControllerName(dataTypeTree.GetType());
            var dataTypeControllerId   = RebelController.GetControllerId <TreeAttribute>(dataTypeTree.GetType());

            const string action   = "Index";
            var          customId = HiveId.ConvertIntToGuid(123);
            const string area     = "Rebel";

            //Act

            //ensure the area is passed in because we're matchin a URL in an area, otherwise it will not work

            var contentTreeDefaultUrl = UrlHelper.GenerateUrl(null, action, contentControllerName,
                                                              new RouteValueDictionary(new { area, id = HiveId.Empty, treeId = contentControllerId.ToString("N") }),
                                                              RouteTable.Routes, context.RequestContext, true);

            var dataTypeTreeDefaultUrl = UrlHelper.GenerateUrl(null, action, dataTypeControllerName,
                                                               new RouteValueDictionary(new { area, id = HiveId.Empty, treeId = dataTypeControllerId.ToString("N") }),
                                                               RouteTable.Routes, context.RequestContext, true);

            var contentTreeCustomUrl = UrlHelper.GenerateUrl(null, action, contentControllerName,
                                                             new RouteValueDictionary(new { area, id = customId, treeId = contentControllerId.ToString("N") }),
                                                             RouteTable.Routes, context.RequestContext, true);

            var dataTypeTreeCustomUrl = UrlHelper.GenerateUrl(null, action, dataTypeControllerName,
                                                              new RouteValueDictionary(new { area, id = customId, treeId = dataTypeControllerId.ToString("N") }),
                                                              RouteTable.Routes, context.RequestContext, true);

            //Assert

            Assert.AreEqual(string.Format("/Rebel/Trees/{0}", contentControllerName), contentTreeDefaultUrl);
            Assert.AreEqual(string.Format("/Rebel/Trees/{0}", dataTypeControllerName), dataTypeTreeDefaultUrl);
            Assert.AreEqual(string.Format("/Rebel/Trees/{0}/{1}/{2}", contentControllerName, action, HttpUtility.UrlEncode(customId.ToString())), contentTreeCustomUrl);
            Assert.AreEqual(string.Format("/Rebel/Trees/{0}/{1}/{2}", dataTypeControllerName, action, HttpUtility.UrlEncode(customId.ToString())), dataTypeTreeCustomUrl);
        }
Exemplo n.º 10
0
        public static IEnumerable <Lazy <SurfaceController, SurfaceMetadata> > GetSurfaceMetadata(DirectoryInfo packageFolder)
        {
            var surfaceTypes = new List <Type>
            {
                //standard editors
                typeof(CustomSurfaceController),
                typeof(BlahSurfaceController)
            };

            //now we need to create the meta data for each
            return((from t in surfaceTypes
                    let a = t.GetCustomAttributes(typeof(SurfaceAttribute), false).Cast <SurfaceAttribute>().First()
                            select new Lazy <SurfaceController, SurfaceMetadata>(
                        new SurfaceMetadata(new Dictionary <string, object>())
            {
                Id = a.Id,
                ComponentType = t,
                ControllerName = RebelController.GetControllerName(t),
                PluginDefinition = new PluginDefinition(
                    new FileInfo(Path.Combine(packageFolder.FullName, "lib", "hello.dll")),
                    packageFolder.FullName,
                    null, false)
            })).ToList());
        }
Exemplo n.º 11
0
        /// <summary>
        /// Register the tree controllers
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="typeFinder"></param>
        public virtual void RegisterTreeControllers(IContainerBuilder builder, TypeFinder typeFinder)
        {
            if (_treeControllersRegistered)
            {
                return;
            }

            using (DisposableTimer.Start(timer =>
            {
                LogHelper.TraceIfEnabled <RebelComponentRegistrar>("RegisterTreeControllers start took {0}ms", () => timer);
                _treeControllersRegistered = true;
            }))
            {
                //now register each type in the container and also add it to our collection
                foreach (var t in FindTypesInRequiredAssemblies <TreeController>(typeFinder))
                {
                    var treeType = t;

                    RegisterComponent <TreeController, TreeAttribute, TreeMetadata>(t, builder, true,
                                                                                    (pluginDef, attribute, registrar) =>
                                                                                    registrar
                                                                                    .WithMetadata <EditorMetadata, string>(am => am.ControllerName, RebelController.GetControllerName(treeType))
                                                                                    .WithMetadata <TreeMetadata, string>(am => am.TreeTitle, attribute.TreeTitle)
                                                                                    .WithMetadata <TreeMetadata, bool>(am => am.IsInternalRebelTree,
                                                                                                                       treeType.GetCustomAttributes(typeof(RebelTreeAttribute), false).Any()));
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Finds & Registers the Surface controllers
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="typeFinder"></param>
        public virtual void RegisterSurfaceControllers(IContainerBuilder builder, TypeFinder typeFinder)
        {
            if (_surfaceControllersRegistered)
            {
                return;
            }

            using (DisposableTimer.Start(timer =>
            {
                LogHelper.TraceIfEnabled <RebelComponentRegistrar>("RegisterSurfaceControllers start took {0}ms", () => timer);
                _surfaceControllersRegistered = true;
            }))
            {
                //now register each type in the container and also add it to our collection);
                foreach (var t in FindTypesInRequiredAssemblies <SurfaceController>(typeFinder))
                {
                    var surfaceType = t;

                    RegisterComponent <SurfaceController, SurfaceAttribute, SurfaceMetadata>(
                        t, builder, false,
                        (pluginDef, attribute, registrar) =>
                        registrar
                        .WithMetadata <SurfaceMetadata, string>(am => am.ControllerName, RebelController.GetControllerName(surfaceType))
                        .WithMetadata <SurfaceMetadata, bool>(am => am.HasChildActionMacros,
                                                              surfaceType.GetMethods().Any(a => a.GetCustomAttributes(typeof(ChildActionOnlyAttribute), false).Any())));
                }
            }
        }