public void Ensure_Same_Area2()
		{
			var area = new PluginControllerArea(new PluginControllerMetadata[]
				{
					PluginController.GetMetadata(typeof(Controller1)),
					PluginController.GetMetadata(typeof(Controller2))
				});
			Assert.Pass();
		}
예제 #2
0
		/// <summary>
		/// Creates the routes
		/// </summary>
		protected internal void CreateRoutes()
		{
			var umbracoPath = GlobalSettings.UmbracoMvcArea;

			//Create the front-end route
			var defaultRoute = RouteTable.Routes.MapRoute(
				"Umbraco_default",
				"Umbraco/RenderMvc/{action}/{id}",
				new { controller = "RenderMvc", action = "Index", id = UrlParameter.Optional }
				);
			defaultRoute.RouteHandler = new RenderRouteHandler(ControllerBuilder.Current.GetControllerFactory());

			//Create the install routes
			var installPackageRoute = RouteTable.Routes.MapRoute(
				"Umbraco_install_packages",
				"Install/PackageInstaller/{action}/{id}",
				new { controller = "InstallPackage", action = "Index", id = UrlParameter.Optional }
				);
			installPackageRoute.DataTokens.Add("area", umbracoPath);

			//we need to find the surface controllers and route them
			var surfaceControllers = SurfaceControllerResolver.Current.RegisteredSurfaceControllers.ToArray();

			//local surface controllers do not contain the attribute 			
			var localSurfaceControlleres = surfaceControllers.Where(x => PluginController.GetMetadata(x).AreaName.IsNullOrWhiteSpace());
			foreach (var s in localSurfaceControlleres)
			{
				var meta = PluginController.GetMetadata(s);
				var route = RouteTable.Routes.MapRoute(
					string.Format("umbraco-{0}-{1}", "surface", meta.ControllerName),
					umbracoPath + "/Surface/" + meta.ControllerName + "/{action}/{id}",//url to match
					new { controller = meta.ControllerName, action = "Index", id = UrlParameter.Optional },
					new[] { meta.ControllerNamespace }); //only match this namespace
				route.DataTokens.Add("umbraco", "surface"); //ensure the umbraco token is set
			}
			
			//need to get the plugin controllers that are unique to each area (group by)
			//TODO: One day when we have more plugin controllers, we will need to do a group by on ALL of them to pass into the ctor of PluginControllerArea
			var pluginSurfaceControlleres = surfaceControllers.Where(x => !PluginController.GetMetadata(x).AreaName.IsNullOrWhiteSpace());
			var groupedAreas = pluginSurfaceControlleres.GroupBy(controller => PluginController.GetMetadata(controller).AreaName);
			//loop through each area defined amongst the controllers
			foreach(var g in groupedAreas)
			{
				//create an area for the controllers (this will throw an exception if all controllers are not in the same area)
				var pluginControllerArea = new PluginControllerArea(g.Select(PluginController.GetMetadata));
				//register it
				RouteTable.Routes.RegisterArea(pluginControllerArea);
			}
		}
예제 #3
0
        private void RoutePluginControllers()
        {
            var umbracoPath = GlobalSettings.UmbracoMvcArea;

            //we need to find the plugin controllers and route them
            var pluginControllers =
                SurfaceControllerResolver.Current.RegisteredSurfaceControllers.Concat(
                    UmbracoApiControllerResolver.Current.RegisteredUmbracoApiControllers).ToArray();

            //local controllers do not contain the attribute
            var localControllers = pluginControllers.Where(x => PluginController.GetMetadata(x).AreaName.IsNullOrWhiteSpace());
            foreach (var s in localControllers)
            {
                if (TypeHelper.IsTypeAssignableFrom<SurfaceController>(s))
                {
                    RouteLocalSurfaceController(s, umbracoPath);
                }
                else if (TypeHelper.IsTypeAssignableFrom<UmbracoApiController>(s))
                {
                    RouteLocalApiController(s, umbracoPath);
                }
            }

            //need to get the plugin controllers that are unique to each area (group by)
            var pluginSurfaceControlleres = pluginControllers.Where(x => !PluginController.GetMetadata(x).AreaName.IsNullOrWhiteSpace());
            var groupedAreas = pluginSurfaceControlleres.GroupBy(controller => PluginController.GetMetadata(controller).AreaName);
            //loop through each area defined amongst the controllers
            foreach (var g in groupedAreas)
            {
                //create an area for the controllers (this will throw an exception if all controllers are not in the same area)
                var pluginControllerArea = new PluginControllerArea(g.Select(PluginController.GetMetadata));
                //register it
                RouteTable.Routes.RegisterArea(pluginControllerArea);
            }
        }