using System.Linq;
using System.Web.Mvc;
using System.Web.Routing;
namespace Neo.Afx.Mvc
{
///
/// An optional global class that can be inheritted from the MVC global class,
/// this will assist in configuring the global asax without having to re-write code
///
public abstract class GlobalViewEngine : System.Web.HttpApplication
{
#region Properties
///
/// Gets the afx admin virtual paths.
///
///
/// The afx admin virtual paths.
///
public abstract string[] AfxAdminVirtualPaths
{
get;
}
///
/// Gets the custom virtual paths.
///
///
/// The custom virtual paths.
///
public abstract string[] CustomVirtualPaths
{
get;
}
///
/// Gets the external route ignores.
///
///
/// The external route ignores.
///
public abstract string ExternalRouteIgnores
{
get;
}
#endregion
#region Application_Start
///
/// Application_s the start.
///
protected virtual void Application_Start()
{
GlobalFilters.Filters.Add(new HandleErrorAttribute());
ModelBinders.Binders.Add(typeof(decimal), new DecimalModelBinder());
ModelBinders.Binders.Add(typeof(decimal?), new DecimalModelBinder());
ViewEngines.Engines.Add(GetRazorViewEngine());
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
}
#endregion
#region GetRazorViewEngine
///
/// Gets the razor view engine.
///
///
private RazorViewEngine GetRazorViewEngine()
{
var engine = new RazorViewEngine();
engine.PartialViewLocationFormats = engine.PartialViewLocationFormats
.Union(AfxAdminVirtualPaths)
.Union(CustomVirtualPaths)
.ToArray();
engine.ViewLocationFormats = engine.ViewLocationFormats
.Union(AfxAdminVirtualPaths)
.Union(CustomVirtualPaths)
.ToArray();
return engine;
}
#endregion
#region RegisterRoutes
///
/// Registers the routes.
///
/// The routes.
public virtual void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{*favicon}", new
{
favicon = @"(.*/)?favicon.([iI][cC][oO]|[gG][iI][fF])(/.*)?"
});
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
var ignorePaths = ExternalRouteIgnores;
if(!string.IsNullOrEmpty(ignorePaths))
{
foreach(var s in ExternalRouteIgnores.Split(',').Where(s => !string.IsNullOrEmpty(s)))
{
routes.IgnoreRoute(s);
}
}
}
#endregion
}
}