Exemplo n.º 1
0
        /// <summary>
        /// Creates the routing rules for the editors
        /// </summary>
        /// <param name="routes"></param>
        /// <param name="editorControllers"></param>
        private void MapRouteEditors(RouteCollection routes, IEnumerable <EditorMetadata> editorControllers)
        {
            //first, register the internal/default Rebel editor routes (so they work without the IDs)
            //but the constraint will ONLY allow built in Rebel editors to work like this, 3rd party
            //editors will only be accessible by using an ID.
            var defaultEditorMetadata = editorControllers.Where(x => x.IsInternalRebelEditor);

            //first register the special DashboardEditorController as the default
            var dashboardControllerName = RebelController.GetControllerName(typeof(DashboardEditorController));
            var dashboardControllerId   = RebelController.GetControllerId <EditorAttribute>(typeof(DashboardEditorController));
            var route = routes.MapRoute(
                DashboardRouteName,                                                        //name
                AreaName + "/Editors/" + dashboardControllerName + "/{action}/{appAlias}", //url to match
                new { controller = dashboardControllerName, action = "Dashboard", appAlias = "content", editorId = dashboardControllerId.ToString("N") },
                new { backOffice = new BackOfficeRouteConstraint(_applicationContext) },
                new[] { typeof(DashboardEditorController).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 the default (built-in) editors
            foreach (var t in defaultEditorMetadata)
            {
                this.RouteControllerPlugin(t.Id, t.ControllerName, t.ComponentType, routes, "editorId", "Editor", "Editors", "Dashboard", UrlParameter.Optional, true, _applicationContext);
            }

            //now, we need to get the 'internal' editors, 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 localEditors = editorControllers.Where(x => x.PluginDefinition == null && x.Id != dashboardControllerId);

            foreach (var t in localEditors)
            {
                this.RouteControllerPlugin(t.Id, t.ControllerName, t.ComponentType, routes, "editorId", "Editor", "Editors", "Dashboard", UrlParameter.Optional, true, _applicationContext);
            }
        }
Exemplo n.º 2
0
        public static IEnumerable <Lazy <TreeController, TreeMetadata> > GetTreeMetadata(DirectoryInfo packageFolder)
        {
            //create the list of trees
            var treeControllerTypes = new List <Type>
            {
                //standard trees
                typeof(ContentTreeController),
                typeof(MediaTreeController),
                typeof(DataTypeTreeController),
                typeof(DocumentTypeTreeController),
                //duplicate named controllers
                typeof(ApplicationTreeController),
                typeof(Stubs.Trees.ContentTreeController),
                typeof(Stubs.Trees.MediaTreeController)
            };

            //now we need to create the meta data for each
            return((from t in treeControllerTypes
                    let a = t.GetCustomAttributes(typeof(TreeAttribute), false).Cast <TreeAttribute>().First()
                            let defaultTree = t.GetCustomAttributes(typeof(RebelTreeAttribute), false).Any()
                                              select new Lazy <TreeController, TreeMetadata>(
                        new TreeMetadata(new Dictionary <string, object>())
            {
                Id = a.Id,
                TreeTitle = a.TreeTitle,
                ComponentType = t,
                IsInternalRebelTree = defaultTree,
                ControllerName = RebelController.GetControllerName(t),
                PluginDefinition = new PluginDefinition(
                    new FileInfo(Path.Combine(packageFolder.FullName, "lib", "hello.dll")),
                    packageFolder.FullName,
                    null, false)
            })).ToList());
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// The standard routes for the back office main pages
        /// </summary>
        /// <param name="routes"></param>
        private void MapRouteBackOffice(RouteCollection routes)
        {
            //url to match deep linked apps (i.e. /Rebel or /Rebel/Media)
            var defaultControllerName = RebelController.GetControllerName(typeof(DefaultController));
            var appRoute = routes.MapRoute(
                ApplicationRouteName,
                AreaName + "/{appAlias}",
                new { controller = defaultControllerName, action = "App", appAlias = "content" },
                new { backOffice = new BackOfficeRouteConstraint(_applicationContext) },
                new[] { typeof(DefaultController).Namespace }); //match controllers in these namespaces

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

            //url to match normal controller routes for the back office
            var standardRoute = routes.MapRoute(
                DefaultRouteName,
                AreaName + "/{controller}/{action}/{id}",
                new { controller = defaultControllerName, action = "Index", id = UrlParameter.Optional },
                new { backOffice = new BackOfficeRouteConstraint(_applicationContext) },
                new[] { typeof(DefaultController).Namespace });  //match controllers in these namespaces

            standardRoute.DataTokens.Add("area", AreaName);      //only match this area
            standardRoute.DataTokens.Add("rebel", "backoffice"); //ensure the rebel token is set
        }
Exemplo n.º 5
0
        public void BackOfficeRouting_Ensure_Default_Editor_Url_Structures()
        {
            //Arrange

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

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

            var dataTypeEditor         = new DataTypeEditorController(new FakeBackOfficeRequestContext());
            var dataTypeControllerName = RebelController.GetControllerName(dataTypeEditor.GetType());
            var dataTypeControllerId   = RebelController.GetControllerId <EditorAttribute>(dataTypeEditor.GetType());

            var docTypeEditor         = new DocumentTypeEditorController(new FakeBackOfficeRequestContext());
            var docTypeControllerName = RebelController.GetControllerName(docTypeEditor.GetType());
            var docTypeControllerId   = RebelController.GetControllerId <EditorAttribute>(docTypeEditor.GetType());

            const string customAction  = "Index";
            const string defaultAction = "Dashboard";
            const int    id            = -1;
            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 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, dataTypeControllerName,
                                                                 new RouteValueDictionary(new { area, id = UrlParameter.Optional, editorId = dataTypeControllerId.ToString("N") }),
                                                                 RouteTable.Routes, context.RequestContext, true);

            var docTypeEditorDefaultUrl = UrlHelper.GenerateUrl(null, defaultAction, docTypeControllerName,
                                                                new RouteValueDictionary(new { area, id = UrlParameter.Optional, editorId = docTypeControllerId.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, dataTypeControllerName,
                                                                new RouteValueDictionary(new { area, id, editorId = dataTypeControllerId.ToString("N") }),
                                                                RouteTable.Routes, context.RequestContext, true);

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

            //Assert

            Assert.AreEqual(string.Format("/Rebel/Editors/{0}", contentControllerName), contentEditorDefaultUrl);
            Assert.AreEqual(string.Format("/Rebel/Editors/{0}", dataTypeControllerName), dataTypeEditorDefaultUrl);
            Assert.AreEqual(string.Format("/Rebel/Editors/{0}", docTypeControllerName), docTypeEditorDefaultUrl);
            Assert.AreEqual(string.Format("/Rebel/Editors/{0}/{1}/{2}", contentControllerName, customAction, id), contentEditorCustomUrl);
            Assert.AreEqual(string.Format("/Rebel/Editors/{0}/{1}/{2}", dataTypeControllerName, customAction, id), dataTypeEditorCustomUrl);
            Assert.AreEqual(string.Format("/Rebel/Editors/{0}/{1}/{2}", docTypeControllerName, customAction, id), docTypeEditorCustomUrl);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Returns the url for searching using JSON
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string GetTreeSearchUrl(this UrlHelper url)
        {
            var appTreeControllerName = RebelController.GetControllerName(typeof(ApplicationTreeController));
            var appTreeControllerId   = RebelController.GetControllerId <TreeAttribute>(typeof(ApplicationTreeController));

            return(url.Action("Search", appTreeControllerName, new { area = url.GetBackOfficeArea(), treeId = appTreeControllerId.ToString("N") }));
        }
Exemplo n.º 7
0
        public static IEnumerable <Lazy <AbstractEditorController, EditorMetadata> > GetEditorMetadata(DirectoryInfo packageFolder)
        {
            var editorTypes = new List <Type>
            {
                //standard editors
                typeof(ContentEditorController),
                typeof(DataTypeEditorController),
                typeof(DocumentTypeEditorController),
                //duplicate named editors
                typeof(Stubs.Editors.ContentEditorController),
                typeof(Stubs.Editors.MediaEditorController)
            };

            //now we need to create the meta data for each
            return((from t in editorTypes
                    let a = t.GetCustomAttributes(typeof(EditorAttribute), false).Cast <EditorAttribute>().First()
                            let defaultEditor = t.GetCustomAttributes(typeof(RebelEditorAttribute), false).Any()
                                                select new Lazy <AbstractEditorController, EditorMetadata>(
                        new EditorMetadata(new Dictionary <string, object>())
            {
                Id = a.Id,
                ComponentType = t,
                IsInternalRebelEditor = defaultEditor,
                ControllerName = RebelController.GetControllerName(t),
                PluginDefinition = new PluginDefinition(
                    new FileInfo(Path.Combine(packageFolder.FullName, "lib", "hello.dll")),
                    packageFolder.FullName,
                    null, false)
            })).ToList());
        }
        /// <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.º 9
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.º 10
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.º 11
0
 /// <summary>
 /// Returns the full unique url for a Tree based on it's type
 /// </summary>
 /// <param name="url"></param>
 /// <param name="action"></param>
 /// <param name="treeType"></param>
 /// <param name="id"></param>
 /// <param name="queryStrings"></param>
 /// <returns></returns>
 public static string GetTreeUrl(this UrlHelper url, string action, Type treeType, HiveId id, FormCollection queryStrings)
 {
     if (!treeType.GetCustomAttributes(typeof(TreeAttribute), false).Any())
     {
         throw new InvalidCastException("The controller type specified is not of type TreeController");
     }
     return(url.GetTreeUrl(action,
                           id,
                           RebelController.GetControllerId <TreeAttribute>(treeType), queryStrings));
 }
Exemplo n.º 12
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.º 13
0
        /// <summary>
        /// This adds some required elements to the ViewBag so that the Create view renders correctly
        /// </summary>
        protected virtual void EnsureCreateWizardViewBagData(IEnumerable <EntitySchema> docTypesData)
        {
            var docTypesInfo = docTypesData.Where(x => !x.IsAbstract)
                               .Select(BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map <EntitySchema, DocumentTypeInfo>);

            //add the available doc types to the view bag
            ViewBag.AvailableDocumentTypes = docTypesInfo;

            //add the thumbnail path to the view bag
            ViewBag.DocTypeThumbnailBaseUrl = Url.Content(BackOfficeRequestContext.Application.Settings.RebelFolders.DocTypeThumbnailFolder);

            ViewBag.Title = CreateNewTitle;

            ViewBag.ControllerId = RebelController.GetControllerId <EditorAttribute>(GetType());
        }
Exemplo n.º 14
0
        //public static string GetEditorUrl(this UrlHelper url, Type controllerType, object id)
        //{
        //    return url.GetEditorUrl("Edit", controllerType, id);
        //}

        /// <summary>
        /// Returns the full unique url for an Editor based on it's type
        /// </summary>
        public static string GetEditorUrl(this UrlHelper url, string action, Type controllerType, HiveId?id)
        {
            if (!controllerType.GetCustomAttributes(typeof(EditorAttribute), false).Any())
            {
                throw new InvalidCastException("The controller type specified is not decorated with an EditorAttribute");
            }
            var componentRegistrations = DependencyResolver.Current.GetService <ComponentRegistrations>();
            var settings = DependencyResolver.Current.GetService <RebelSettings>();

            return(url.GetEditorUrl(action,
                                    id,
                                    RebelController.GetControllerId <EditorAttribute>(controllerType),
                                    componentRegistrations,
                                    settings));
        }
Exemplo n.º 15
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.º 16
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);
        }
        /// <summary>
        /// This adds some required elements to the ViewBag so that the Create view renders correctly
        /// </summary>
        protected virtual void EnsureCreateWizardViewBagData(HiveId parentId)
        {
            ViewBag.ControllerId = RebelController.GetControllerId <EditorAttribute>(GetType());
            ViewBag.Title        = CreateNewTitle;

            using (var uow = Hive.Create <IContentStore>())
            {
                //get all the document types under the specified parent
                var schemas      = uow.Repositories.Schemas.GetChildren <EntitySchema>(FixedRelationTypes.DefaultRelationType, parentId);
                var docTypesInfo = schemas.Select(BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map <EntitySchema, DocumentTypeInfo>);

                ViewBag.AvailableDocumentTypes =
                    new[] { new DocumentTypeInfo()
                            {
                                Id = parentId, Name = "[None]"
                            } }.Concat(docTypesInfo);
                //add the thumbnail path to the view bag
                ViewBag.DocTypeThumbnailBaseUrl = Url.Content(BackOfficeRequestContext.Application.Settings.RebelFolders.DocTypeThumbnailFolder);
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// This checks for the parent controller type and validates it, then sets the appropriate properties
        /// </summary>
        /// <param name="requestContext"></param>
        protected override void Initialize(global::System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);

            var parentContext = RouteData.GetControllerExtenderParentContext();

            if (parentContext == null)
            {
                throw new NotSupportedException(this.GetType().Name + " cannot be instantiated unless it is created as a Controller Extender");
            }
            var baseType = parentContext.Controller.GetType().BaseType;

            if (baseType == null || !baseType.Name.StartsWith(typeof(AbstractRevisionalContentEditorController <>).Name))
            {
                throw new NotSupportedException(this.GetType().Name + " cannot be instantiated unless it is created as a Controller Extender for type " + typeof(AbstractRevisionalContentEditorController <>).Name);
            }
            ContentController = (dynamic)parentContext.Controller;

            //now that we have a reference to the parent content controller, assign the ViewBag values which are normally required for creating forms in views
            ViewBag.ControllerId = RebelController.GetControllerId <EditorAttribute>(ContentController.GetType());
        }
Exemplo n.º 19
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.º 20
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.º 21
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())));
                }
            }
        }
Exemplo n.º 22
0
 /// <summary>
 /// Ensures the create wizard view bag data.
 /// </summary>
 protected virtual void EnsureCreateWizardViewBagData()
 {
     ViewBag.Title        = CreateNewTitle;
     ViewBag.ControllerId = RebelController.GetControllerId <EditorAttribute>(GetType());
 }