2010-10-15 09:10:44 +02:00
|
|
|
|
using System;
|
2011-05-30 09:05:45 +02:00
|
|
|
|
using System.Data.Common;
|
2011-03-30 08:18:35 +02:00
|
|
|
|
using System.Reflection;
|
2010-10-17 19:22:48 +02:00
|
|
|
|
using System.Threading;
|
2010-10-15 09:10:44 +02:00
|
|
|
|
using System.Web;
|
2011-04-22 04:23:31 +02:00
|
|
|
|
using System.Web.Caching;
|
2010-10-15 09:10:44 +02:00
|
|
|
|
using System.Web.Mvc;
|
2010-09-23 05:19:47 +02:00
|
|
|
|
using System.Web.Routing;
|
2011-06-14 03:35:44 +02:00
|
|
|
|
using MvcMiniProfiler;
|
2010-09-23 05:19:47 +02:00
|
|
|
|
using Ninject;
|
|
|
|
|
using Ninject.Web.Mvc;
|
2010-10-15 09:10:44 +02:00
|
|
|
|
using NLog;
|
2010-09-23 05:19:47 +02:00
|
|
|
|
using NzbDrone.Core;
|
2010-10-24 09:46:58 +02:00
|
|
|
|
using NzbDrone.Core.Instrumentation;
|
2010-09-23 05:19:47 +02:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Web
|
|
|
|
|
{
|
|
|
|
|
public class MvcApplication : NinjectHttpApplication
|
|
|
|
|
{
|
2010-10-17 19:22:48 +02:00
|
|
|
|
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}");
|
2011-04-19 02:12:06 +02:00
|
|
|
|
routes.IgnoreRoute("{*robotstxt}", new { robotstxt = @"(.*/)?robots.txt(/.*)?" });
|
|
|
|
|
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
|
2010-09-23 05:19:47 +02:00
|
|
|
|
|
2011-03-31 03:42:27 +02:00
|
|
|
|
|
2010-09-23 05:19:47 +02:00
|
|
|
|
routes.MapRoute(
|
2011-04-10 04:44:01 +02:00
|
|
|
|
"Default", // Route name
|
|
|
|
|
"{controller}/{action}/{id}", // URL with parameters
|
2011-04-19 02:12:06 +02:00
|
|
|
|
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
|
|
|
|
//base.OnApplicationStarted();
|
|
|
|
|
AreaRegistration.RegisterAllAreas();
|
|
|
|
|
RegisterGlobalFilters(GlobalFilters.Filters);
|
2011-06-18 19:58:52 +02:00
|
|
|
|
|
|
|
|
|
Logger.Debug("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-06-13 05:45:22 +02:00
|
|
|
|
LogConfiguration.Setup();
|
|
|
|
|
Logger.Info("NZBDrone Starting up.");
|
|
|
|
|
CentralDispatch.DedicateToHost();
|
|
|
|
|
|
2010-10-24 09:46:58 +02:00
|
|
|
|
var kernel = CentralDispatch.NinjectKernel;
|
|
|
|
|
|
2011-03-30 08:18:35 +02:00
|
|
|
|
// kernel.Bind<IRepository>().ToConstant(kernel.Get<IRepository>("LogDb"));
|
|
|
|
|
kernel.Load(Assembly.GetExecutingAssembly());
|
2010-10-24 09:46:58 +02:00
|
|
|
|
return 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)
|
|
|
|
|
{
|
2010-10-17 19:22:48 +02:00
|
|
|
|
var lastError = Server.GetLastError();
|
2011-04-22 04:23:31 +02:00
|
|
|
|
|
|
|
|
|
if (lastError is HttpException && lastError.InnerException == null)
|
2010-10-17 19:22:48 +02:00
|
|
|
|
{
|
2011-03-29 07:50:18 +02:00
|
|
|
|
Logger.WarnException(String.Format("{0}. URL[{1}]", lastError.Message, Request.Path), lastError);
|
2011-04-10 04:28:54 +02:00
|
|
|
|
return;
|
2010-10-17 19:22:48 +02:00
|
|
|
|
}
|
2011-04-10 04:28:54 +02:00
|
|
|
|
|
2011-04-19 02:12:06 +02:00
|
|
|
|
Logger.FatalException(lastError.Message + Environment.NewLine + Request.Url.PathAndQuery, lastError);
|
2011-04-10 04:28:54 +02:00
|
|
|
|
|
2011-05-30 09:05:45 +02:00
|
|
|
|
if (lastError is DbException)
|
2010-10-17 19:22:48 +02:00
|
|
|
|
{
|
2011-04-10 04:28:54 +02:00
|
|
|
|
Logger.Warn("Restarting application");
|
|
|
|
|
HttpRuntime.UnloadAppDomain();
|
2010-10-17 19:22:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void Application_BeginRequest()
|
|
|
|
|
{
|
|
|
|
|
Thread.CurrentThread.Name = "UI";
|
2011-06-14 03:35:44 +02:00
|
|
|
|
var miniprofiler = MiniProfiler.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void Application_EndRequest()
|
|
|
|
|
{
|
|
|
|
|
MiniProfiler.Stop();
|
2010-09-23 05:19:47 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|