1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-23 16:26:02 +00:00
Sonarr/NzbDrone.Web/Global.asax.cs

103 lines
3.2 KiB
C#
Raw Normal View History

2010-10-15 07:10:44 +00:00
using System;
using System.Data.Common;
using System.Linq;
2011-03-30 06:18:35 +00:00
using System.Reflection;
using System.Threading;
2010-10-15 07:10:44 +00:00
using System.Web;
using System.Web.Caching;
2010-10-15 07:10:44 +00:00
using System.Web.Mvc;
2010-09-23 03:19:47 +00:00
using System.Web.Routing;
2011-06-14 01:35:44 +00:00
using MvcMiniProfiler;
2010-09-23 03:19:47 +00:00
using Ninject;
using Ninject.Web.Mvc;
2010-10-15 07:10:44 +00:00
using NLog;
2010-09-23 03:19:47 +00:00
using NzbDrone.Core;
using NzbDrone.Core.Instrumentation;
2011-06-23 06:56:17 +00:00
using Telerik.Web.Mvc;
2010-09-23 03:19:47 +00:00
namespace NzbDrone.Web
{
public class MvcApplication : NinjectHttpApplication
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
2010-09-23 03:19:47 +00:00
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*robotstxt}", new { robotstxt = @"(.*/)?robots.txt(/.*)?" });
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
2010-09-23 03:19:47 +00:00
2010-09-23 03:19:47 +00:00
routes.MapRoute(
2011-04-10 02:44:01 +00:00
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Series", action = "Index", id = UrlParameter.Optional } // Parameter defaults
2011-04-10 02:44:01 +00:00
);
2010-09-23 03:19:47 +00:00
}
protected override void OnApplicationStarted()
{
2011-03-30 06:18:35 +00:00
base.OnApplicationStarted();
//WebAssetDefaultSettings.UseTelerikContentDeliveryNetwork = true;
2010-09-23 03:19:47 +00:00
RegisterRoutes(RouteTable.Routes);
2011-03-30 06:18:35 +00:00
//base.OnApplicationStarted();
AreaRegistration.RegisterAllAreas();
var razor = ViewEngines.Engines.Where(e => e.GetType() == typeof(RazorViewEngine)).Single();
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(razor);
2011-03-30 06:18:35 +00:00
RegisterGlobalFilters(GlobalFilters.Filters);
2011-10-24 05:54:09 +00:00
Logger.Info("Fully initialized and ready.");
2010-09-29 17:19:18 +00:00
}
2010-09-23 03:19:47 +00:00
protected override IKernel CreateKernel()
{
var kernel = CentralDispatch.NinjectKernel;
Logger.Info("NZBDrone Starting up.");
CentralDispatch.DedicateToHost();
2011-03-30 06:18:35 +00:00
kernel.Load(Assembly.GetExecutingAssembly());
return kernel;
2010-10-15 07:10:44 +00:00
}
2010-10-10 19:00:07 +00:00
2011-03-30 06:18:35 +00:00
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
2010-10-15 07:10:44 +00:00
// ReSharper disable InconsistentNaming
protected void Application_Error(object sender, EventArgs e)
{
var lastError = Server.GetLastError();
if (lastError is HttpException && lastError.InnerException == null)
{
2011-03-29 05:50:18 +00:00
Logger.WarnException(String.Format("{0}. URL[{1}]", lastError.Message, Request.Path), lastError);
return;
}
Logger.FatalException(lastError.Message + Environment.NewLine + Request.Url.PathAndQuery, lastError);
if (lastError is DbException)
{
Logger.Warn("Restarting application");
HttpRuntime.UnloadAppDomain();
}
}
protected void Application_BeginRequest()
{
Thread.CurrentThread.Name = "UI";
2011-06-14 01:35:44 +00:00
var miniprofiler = MiniProfiler.Start();
}
protected void Application_EndRequest()
{
MiniProfiler.Stop();
2010-09-23 03:19:47 +00:00
}
}
}