2010-10-15 10:10:44 +03:00
|
|
|
using System;
|
2011-04-10 05:28:54 +03:00
|
|
|
using System.Data.SQLite;
|
2011-03-30 09:18:35 +03:00
|
|
|
using System.Reflection;
|
2010-10-17 20:22:48 +03:00
|
|
|
using System.Threading;
|
2010-10-15 10:10:44 +03:00
|
|
|
using System.Web;
|
|
|
|
using System.Web.Mvc;
|
2010-09-23 06:19:47 +03:00
|
|
|
using System.Web.Routing;
|
|
|
|
using Ninject;
|
|
|
|
using Ninject.Web.Mvc;
|
2010-10-15 10:10:44 +03:00
|
|
|
using NLog;
|
2010-09-23 06:19:47 +03:00
|
|
|
using NzbDrone.Core;
|
2010-10-24 10:46:58 +03:00
|
|
|
using NzbDrone.Core.Instrumentation;
|
2010-09-23 06:19:47 +03:00
|
|
|
|
|
|
|
namespace NzbDrone.Web
|
|
|
|
{
|
|
|
|
public class MvcApplication : NinjectHttpApplication
|
|
|
|
{
|
2010-10-17 20:22:48 +03:00
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
2010-09-23 06:19:47 +03:00
|
|
|
|
|
|
|
public static void RegisterRoutes(RouteCollection routes)
|
|
|
|
{
|
|
|
|
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
|
2011-04-10 05:44:01 +03:00
|
|
|
routes.IgnoreRoute("{*robotstxt}", new {robotstxt = @"(.*/)?robots.txt(/.*)?"});
|
|
|
|
routes.IgnoreRoute("{*favicon}", new {favicon = @"(.*/)?favicon.ico(/.*)?"});
|
2010-09-23 06:19:47 +03:00
|
|
|
|
2011-03-31 04:42:27 +03:00
|
|
|
|
2010-09-23 06:19:47 +03:00
|
|
|
routes.MapRoute(
|
2011-04-10 05:44:01 +03:00
|
|
|
"Default", // Route name
|
|
|
|
"{controller}/{action}/{id}", // URL with parameters
|
|
|
|
new {controller = "Series", action = "Index", id = UrlParameter.Optional} // Parameter defaults
|
|
|
|
);
|
2010-09-23 06:19:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnApplicationStarted()
|
|
|
|
{
|
2011-03-30 09:18:35 +03:00
|
|
|
base.OnApplicationStarted();
|
|
|
|
|
2010-10-24 10:46:58 +03:00
|
|
|
LogConfiguration.Setup();
|
|
|
|
Logger.Info("NZBDrone Starting up.");
|
2010-10-17 20:22:48 +03:00
|
|
|
CentralDispatch.DedicateToHost();
|
2011-03-30 09:18:35 +03:00
|
|
|
|
2010-09-23 06:19:47 +03:00
|
|
|
RegisterRoutes(RouteTable.Routes);
|
2011-03-30 09:18:35 +03:00
|
|
|
//base.OnApplicationStarted();
|
|
|
|
AreaRegistration.RegisterAllAreas();
|
|
|
|
RegisterGlobalFilters(GlobalFilters.Filters);
|
|
|
|
//RegisterRoutes(RouteTable.Routes);
|
2010-09-29 20:19:18 +03:00
|
|
|
}
|
2010-09-23 06:19:47 +03:00
|
|
|
|
|
|
|
protected override IKernel CreateKernel()
|
|
|
|
{
|
2010-10-24 10:46:58 +03:00
|
|
|
var kernel = CentralDispatch.NinjectKernel;
|
|
|
|
|
2011-03-30 09:18:35 +03:00
|
|
|
// kernel.Bind<IRepository>().ToConstant(kernel.Get<IRepository>("LogDb"));
|
|
|
|
kernel.Load(Assembly.GetExecutingAssembly());
|
2010-10-24 10:46:58 +03:00
|
|
|
return kernel;
|
2010-10-15 10:10:44 +03:00
|
|
|
}
|
2010-10-10 22:00:07 +03:00
|
|
|
|
2011-03-30 09:18:35 +03:00
|
|
|
|
|
|
|
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
|
|
|
|
{
|
|
|
|
filters.Add(new HandleErrorAttribute());
|
|
|
|
}
|
|
|
|
|
2010-10-15 10:10:44 +03:00
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
protected void Application_Error(object sender, EventArgs e)
|
|
|
|
{
|
2010-10-17 20:22:48 +03:00
|
|
|
var lastError = Server.GetLastError();
|
|
|
|
if (lastError is HttpException)
|
|
|
|
{
|
2011-03-29 08:50:18 +03:00
|
|
|
Logger.WarnException(String.Format("{0}. URL[{1}]", lastError.Message, Request.Path), lastError);
|
2011-03-31 04:42:27 +03:00
|
|
|
if (Request.Path.EndsWith(".aspx", StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
{
|
|
|
|
Response.Redirect(Request.ApplicationPath);
|
|
|
|
}
|
2011-04-10 05:28:54 +03:00
|
|
|
return;
|
2010-10-17 20:22:48 +03:00
|
|
|
}
|
2011-04-10 05:28:54 +03:00
|
|
|
|
|
|
|
Logger.FatalException(lastError.Message, lastError);
|
|
|
|
|
|
|
|
if (lastError is SQLiteException)
|
2010-10-17 20:22:48 +03:00
|
|
|
{
|
2011-04-10 05:28:54 +03:00
|
|
|
Logger.Warn("Restarting application");
|
|
|
|
HttpRuntime.UnloadAppDomain();
|
2010-10-17 20:22:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void Application_BeginRequest()
|
|
|
|
{
|
|
|
|
Thread.CurrentThread.Name = "UI";
|
2010-09-23 06:19:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|