コード例 #1
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);
        }
コード例 #2
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") }));
        }
コード例 #3
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);
            }
        }
コード例 #4
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);
            }
        }
コード例 #5
0
        /// <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());
        }
コード例 #6
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 }));
        }
コード例 #7
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));
 }
コード例 #8
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);
        }
コード例 #9
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));
        }
コード例 #10
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());
        }
コード例 #11
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
            }));
        }
コード例 #12
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);
        }
コード例 #13
0
        /// <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);
            }
        }
コード例 #14
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());
        }
コード例 #15
0
 /// <summary>
 /// Ensures the create wizard view bag data.
 /// </summary>
 protected virtual void EnsureCreateWizardViewBagData()
 {
     ViewBag.Title        = CreateNewTitle;
     ViewBag.ControllerId = RebelController.GetControllerId <EditorAttribute>(GetType());
 }