public static void AddRoute(this BasePlugin plugin, IList<SiteRoute> routes, SiteRoute route)
 {
   routes.AddRoute(route, plugin.DefaultMerit);
 }
    public static void AddRoute(this IList<SiteRoute> routes, SiteRoute route, int merit)
    {
      var osr = routes.Where(r => r.Merit == merit).LastOrDefault();

      int insertAt = routes.Count;
      for (int i = 0; i < routes.Count; i++)
      {
        if (routes[i].Merit < route.Merit)
        {
          insertAt = i;
          break;
        }
      }
      routes.Insert(insertAt, route);
    }
 public static void AddRoute(this IList<SiteRoute> routes, SiteRoute route)
 {
   AddRoute(routes, route, (int)MeritLevel.Default);
 }
    protected virtual SiteRoute MapRoute(string routeName, string url, object defaults, object constraints, MapRouteModes modes, int merit)
    {
      var dataTokens = new RouteValueDictionary();
      var defaultsDict = defaults == null ? new RouteValueDictionary() : new RouteValueDictionary(defaults);
      var constraintsDict = defaults == null ? new RouteValueDictionary() : new RouteValueDictionary(constraints);

      if ((modes & MapRouteModes.Secure) == MapRouteModes.Secure)
        dataTokens.Add("Secure", true);

      if ((modes & MapRouteModes.NeedsBase) == MapRouteModes.NeedsBase)
        url = BasePath + url;

      //allow collection plugin routes to be constrained to just the collections they are activated for
      if (url.Contains("{collection}") && !constraintsDict.ContainsKey("collectionIds"))
      {
        constraintsDict.Add("collectionIds",
          (modes & MapRouteModes.Dated) == MapRouteModes.Dated ? GetDatedCollectionConstraint() :
          (modes & MapRouteModes.NonDated) == MapRouteModes.NonDated ? GetNonDatedCollectionConstraint() :
          GetCollectionConstraint()
          );
      }

      //add restricted path keywords to constraint 
      //HACK: this is currently a hack needed due to inability to
      //insert routes
      //TODO: we can now insert routes, go back and fix this hack
      if (url.Contains("{path}") && !constraintsDict.ContainsKey("path"))
      {
        constraintsDict.Add("path", new PathRouteConstraint()); 
      }

      SetDataTokens(dataTokens);
      System.Web.Routing.Route r = new System.Web.Routing.Route(url, defaultsDict, constraintsDict, dataTokens, new MvcRouteHandler());
      var siteRoute = new SiteRoute() { Merit = merit, Name = routeName, Route = r };
      Routes.AddRoute(siteRoute, merit);
      return siteRoute;
    }