1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00
Radarr/NzbDrone.Web/Global.asax.cs
Keivan 6f2dcbf838 Revered back to subsonic
Added indexer configuration back-end
2011-04-18 17:12:06 -07:00

92 lines
2.9 KiB
C#

using System;
using System.Data.SQLite;
using System.Reflection;
using System.Threading;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Ninject;
using Ninject.Web.Mvc;
using NLog;
using NzbDrone.Core;
using NzbDrone.Core.Instrumentation;
namespace NzbDrone.Web
{
public class MvcApplication : NinjectHttpApplication
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
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(/.*)?" });
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Series", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
protected override void OnApplicationStarted()
{
base.OnApplicationStarted();
LogConfiguration.Setup();
Logger.Info("NZBDrone Starting up.");
CentralDispatch.DedicateToHost();
RegisterRoutes(RouteTable.Routes);
//base.OnApplicationStarted();
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
//RegisterRoutes(RouteTable.Routes);
}
protected override IKernel CreateKernel()
{
var kernel = CentralDispatch.NinjectKernel;
// kernel.Bind<IRepository>().ToConstant(kernel.Get<IRepository>("LogDb"));
kernel.Load(Assembly.GetExecutingAssembly());
return kernel;
}
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
// ReSharper disable InconsistentNaming
protected void Application_Error(object sender, EventArgs e)
{
var lastError = Server.GetLastError();
if (lastError is HttpException)
{
Logger.WarnException(String.Format("{0}. URL[{1}]", lastError.Message, Request.Path), lastError);
if (Request.Path.EndsWith(".aspx", StringComparison.InvariantCultureIgnoreCase))
{
Response.Redirect(Request.ApplicationPath);
}
return;
}
Logger.FatalException(lastError.Message + Environment.NewLine + Request.Url.PathAndQuery, lastError);
if (lastError is SQLiteException)
{
Logger.Warn("Restarting application");
HttpRuntime.UnloadAppDomain();
}
}
protected void Application_BeginRequest()
{
Thread.CurrentThread.Name = "UI";
}
}
}