Go to the documentation of this file.00001 using System;
00002 using System.Collections.Generic;
00003 using System.Linq;
00004 using System.Text;
00005 using N2.Engine;
00006 using System.Web.Mvc;
00007 using System.Web.Routing;
00008
00009 namespace N2.Web.Mvc
00010 {
00011 public class AreaRegistrationState
00012 {
00013 public AreaRegistrationState(IEngine engine)
00014 {
00015 Engine = engine;
00016 Values = new Dictionary<string, object>();
00017 }
00018
00019 public IEngine Engine { get; set; }
00020 public IDictionary<string, object> Values { get; set; }
00021 }
00022
00023 public static class AreaRegistrationExtensions
00024 {
00030 public static ContentRoute MapContentRoute<T>(this AreaRegistrationContext arc)
00031 where T: ContentItem
00032 {
00033 var state = arc.State as AreaRegistrationState;
00034 if (state == null) throw new ArgumentException("The area registration context didn't contain an AreaRegistrationState.", "arc");
00035 if (state.Engine == null) throw new ArgumentException("The area registration state an IEngine.", "arc");
00036
00037 var routeHandler = new MvcRouteHandler();
00038 var controllerMapper = state.Engine.Resolve<IControllerMapper>();
00039 var innerRoute = new Route("{area}/{controller}/{action}",
00040 new RouteValueDictionary(new { action = "Index" }),
00041 new RouteValueDictionary(),
00042 new RouteValueDictionary(new { engine = state.Engine, area = arc.AreaName }),
00043 routeHandler);
00044
00045 var cr = new ContentRoute<T>(state.Engine, routeHandler, controllerMapper, innerRoute);
00046 arc.Routes.Add(arc.AreaName + "_" + typeof(T).FullName, cr);
00047 return cr;
00048 }
00049 }
00050 }