public static void RegisterRoutes(RouteCollection routes, bool OverrideRefresh)
{
try {
string sKeyPrefix = "CarrotCakeCMS_";
if (!HasRegisteredRoutes || OverrideRefresh)
{
List <string> listFiles = SiteNavHelper.GetSiteDirectoryPaths();
int iRoute = 0;
List <Route> lstRoute = new List <Route>();
//routes.Clear();
//only remove routes that are tagged as coming from the CMS
foreach (Route rr in routes)
{
if (rr.DataTokens != null && rr.DataTokens["RouteName"] != null && rr.DataTokens["RouteName"].ToString().StartsWith(sKeyPrefix))
{
lstRoute.Add(rr);
}
}
foreach (Route rr in lstRoute)
{
RouteTable.Routes.Remove(rr);
}
foreach (string fileName in listFiles)
{
string sKeyName = sKeyPrefix + iRoute.ToString();
VirtualDirectory vd = new VirtualDirectory(fileName);
Route r = new Route(fileName.Substring(1, fileName.LastIndexOf("/")), vd);
if (r.DataTokens == null)
{
r.DataTokens = new RouteValueDictionary();
}
r.DataTokens["RouteName"] = sKeyName;
routes.Add(sKeyName, r);
iRoute++;
}
HasRegisteredRoutes = true;
}
} catch (Exception ex) {
//assumption is database is probably empty / needs updating, so trigger the under construction view
if (DatabaseUpdate.SystemNeedsChecking(ex) || DatabaseUpdate.AreCMSTablesIncomplete())
{
routes.Clear();
HasRegisteredRoutes = false;
}
else
{
//something bad has gone down, toss back the error
throw;
}
}
}