/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System;
using System.Linq;
using System.Configuration;
using System.Web.Routing;
using System.Web.Mvc;
using System.Collections.Generic;
using Everest.Library.Providers.Caching;
namespace Everest.Library.Mvc.Routing{
/// <summary>
///
/// </summary>
public static class RouteTableManager
{
/// <summary>
///
/// </summary>
public static string RouteTableConfigFile = AppDomain.CurrentDomain.BaseDirectory + "\\routes.config";
/// <summary>
///
/// </summary>
static object lockHelper = new object();
/// <summary>
/// Registers the routes.
/// </summary>
/// <param name="routes">The routes.</param>
public static void RegisterRoutes(System.Web.Routing.RouteCollection routes)
{
lock (lockHelper)
{
if (!System.IO.File.Exists(RouteTableConfigFile))
{
throw new ArgumentException("Routes config file not found,must have the routes.config in the base directory.", RouteTableConfigFile);
}
//register default configuration
RouteTableRegister.RegisterRoutes(routes, RouteTableConfigFile);
//if the routing file has changed,the routing cache will be lost in 3s.
//IList<ICacheItemExpiration> dependencies = new List<ICacheItemExpiration>() { new FileDependency(RouteTableConfigFile) };
//if (Assemblies.AssemblyResolver.Packages.GetConfigFiles() != null)
//{
// //register Packages assembly configurations
// foreach (string file in Assemblies.AssemblyResolver.Packages.GetConfigFiles())
// {
// RegisterRoutes(routes, file);
// }
// dependencies.Add(new DirectoryDependency(Assemblies.AssemblyResolver.Packages.DirectoryPath));
//}
//add a temp cache,purpose to monitor the routetables going to change.
//CacheManager.Add("CacheItem-RouteTable-RefreshTrigger", "TriggerValue", CacheItemPriority.High, new RouteTableRefreshed(),
// dependencies.ToArray());
}
}
}
}
|