1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-01 16:32:56 +01:00
Sonarr/NzbDrone.Web/Global.asax.cs

97 lines
2.9 KiB
C#
Raw Normal View History

2010-10-15 09:10:44 +02:00
using System;
using System.Data.Common;
using System.Linq;
2011-03-30 08:18:35 +02:00
using System.Reflection;
using System.Threading;
2010-10-15 09:10:44 +02:00
using System.Web;
using System.Web.Mvc;
2010-09-23 05:19:47 +02:00
using System.Web.Routing;
2012-10-15 02:53:34 +02:00
using LowercaseRoutesMVC;
using NLog.Config;
2010-09-23 05:19:47 +02:00
using Ninject;
using Ninject.Web.Mvc;
2010-10-15 09:10:44 +02:00
using NLog;
using NzbDrone.Common;
2010-09-23 05:19:47 +02:00
using NzbDrone.Core;
namespace NzbDrone.Web
{
public class MvcApplication : NinjectHttpApplication
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
2010-09-23 05:19:47 +02: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 05:19:47 +02:00
2012-10-15 02:53:34 +02:00
routes.MapRouteLowercase(
2011-04-10 04:44:01 +02:00
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Series", action = "Index", id = UrlParameter.Optional } // Parameter defaults
2011-04-10 04:44:01 +02:00
);
2010-09-23 05:19:47 +02:00
}
protected override void OnApplicationStarted()
{
2011-03-30 08:18:35 +02:00
base.OnApplicationStarted();
2010-09-23 05:19:47 +02:00
RegisterRoutes(RouteTable.Routes);
2011-03-30 08:18:35 +02:00
AreaRegistration.RegisterAllAreas();
2011-11-22 07:55:09 +01:00
var razor = ViewEngines.Engines.Single(e => e is RazorViewEngine);
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(razor);
2011-03-30 08:18:35 +02:00
RegisterGlobalFilters(GlobalFilters.Filters);
2011-10-24 07:54:09 +02:00
Logger.Info("Fully initialized and ready.");
2010-09-29 19:19:18 +02:00
}
2010-09-23 05:19:47 +02:00
protected override IKernel CreateKernel()
{
2011-11-08 18:48:34 +01:00
Logger.Info("NzbDrone Starting up.");
2012-01-23 03:24:16 +01:00
var dispatch = new CentralDispatch();
2011-11-08 21:12:54 +01:00
dispatch.DedicateToHost();
2011-11-08 21:12:54 +01:00
dispatch.Kernel.Load(Assembly.GetExecutingAssembly());
return dispatch.Kernel;
2010-10-15 09:10:44 +02:00
}
2010-10-10 21:00:07 +02:00
2011-03-30 08:18:35 +02:00
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
2010-10-15 09:10:44 +02: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 07:50:18 +02: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 = "WEB_THREAD";
2011-06-14 03:35:44 +02:00
}
protected void Application_EndRequest()
{
2010-09-23 05:19:47 +02:00
}
}
}