00001 using System; 00002 using System.Collections.Generic; 00003 using System.Linq; 00004 using System.Text; 00005 using System.Web.Routing; 00006 using N2.Engine; 00007 using System.Web.Mvc; 00008 00009 namespace N2.Web.Mvc 00010 { 00014 public static class RouteCollectionExtensions 00015 { 00021 public static ContentRoute MapContentRoute(this RouteCollection routes, string name, IEngine engine) 00022 { 00023 var cr = new ContentRoute(engine); 00024 routes.Add(name, cr); 00025 return cr; 00026 } 00027 00035 [Obsolete("TODO: support custom url")] 00036 private static ContentRoute MapContentRoute(this RouteCollection routes, string name, IEngine engine, string url, object defaults) 00037 { 00038 return routes.MapContentRoute(name, engine, url, defaults, null, null); 00039 } 00040 00050 [Obsolete("TODO: support custom url")] 00051 private static ContentRoute MapContentRoute(this RouteCollection routes, string name, IEngine engine, string url, object defaults, object constraints, string[] namespaces) 00052 { 00053 var rh = new MvcRouteHandler(); 00054 Route innerRoute = new Route(url, rh); 00055 innerRoute.Defaults = new RouteValueDictionary(defaults); 00056 innerRoute.Constraints = new RouteValueDictionary(constraints); 00057 innerRoute.DataTokens = new RouteValueDictionary(); 00058 if ((namespaces != null) && (namespaces.Length > 0)) 00059 { 00060 innerRoute.DataTokens["Namespaces"] = namespaces; 00061 } 00062 00063 var cr = new ContentRoute(engine, rh, null, innerRoute); 00064 routes.Add(name, cr); 00065 return cr; 00066 } 00067 00068 00069 00076 public static ContentRoute MapContentRoute<T>(this RouteCollection routes, string name, IEngine engine) 00077 where T : ContentItem 00078 { 00079 var cr = new ContentRoute<T>(engine); 00080 routes.Add(name, cr); 00081 return cr; 00082 } 00083 00092 [Obsolete("TODO: support custom url")] 00093 private static ContentRoute MapContentRoute<T>(this RouteCollection routes, string name, IEngine engine, string url, object defaults) 00094 where T : ContentItem 00095 { 00096 return routes.MapContentRoute<T>(name, engine, url, defaults, null, null); 00097 } 00098 00109 [Obsolete("TODO: support custom url")] 00110 private static ContentRoute MapContentRoute<T>(this RouteCollection routes, string name, IEngine engine, string url, object defaults, object constraints, string[] namespaces) 00111 where T : ContentItem 00112 { 00113 var rh = new MvcRouteHandler(); 00114 00115 Route innerRoute = new Route(url, rh); 00116 innerRoute.Defaults = new RouteValueDictionary(defaults); 00117 innerRoute.Constraints = new RouteValueDictionary(constraints); 00118 innerRoute.DataTokens = new RouteValueDictionary(); 00119 if ((namespaces != null) && (namespaces.Length > 0)) 00120 { 00121 innerRoute.DataTokens["Namespaces"] = namespaces; 00122 } 00123 00124 var cr = new ContentRoute<T>(engine, rh, null, innerRoute); 00125 routes.Add(name, cr); 00126 return cr; 00127 } 00128 } 00129 }