2010-10-15 07:10:44 +00:00
|
|
|
|
using System;
|
2011-05-30 07:05:45 +00:00
|
|
|
|
using System.Data.Common;
|
2011-09-04 03:05:44 +00:00
|
|
|
|
using System.Linq;
|
2011-03-30 06:18:35 +00:00
|
|
|
|
using System.Reflection;
|
2010-10-17 17:22:48 +00:00
|
|
|
|
using System.Threading;
|
2010-10-15 07:10:44 +00:00
|
|
|
|
using System.Web;
|
|
|
|
|
using System.Web.Mvc;
|
2010-09-23 03:19:47 +00:00
|
|
|
|
using System.Web.Routing;
|
2011-11-14 00:22:18 +00:00
|
|
|
|
using NLog.Config;
|
2010-09-23 03:19:47 +00:00
|
|
|
|
using Ninject;
|
|
|
|
|
using Ninject.Web.Mvc;
|
2010-10-15 07:10:44 +00:00
|
|
|
|
using NLog;
|
2011-11-14 00:22:18 +00:00
|
|
|
|
using NzbDrone.Common;
|
2010-09-23 03:19:47 +00:00
|
|
|
|
using NzbDrone.Core;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Web
|
|
|
|
|
{
|
|
|
|
|
public class MvcApplication : NinjectHttpApplication
|
|
|
|
|
{
|
2010-10-17 17:22:48 +00:00
|
|
|
|
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}");
|
2011-04-19 00:12:06 +00:00
|
|
|
|
routes.IgnoreRoute("{*robotstxt}", new { robotstxt = @"(.*/)?robots.txt(/.*)?" });
|
|
|
|
|
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
|
2010-09-23 03:19:47 +00:00
|
|
|
|
|
2011-03-31 01:42:27 +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
|
2011-04-19 00:12:06 +00:00
|
|
|
|
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-11-23 05:58:26 +00:00
|
|
|
|
{
|
2011-03-30 06:18:35 +00:00
|
|
|
|
base.OnApplicationStarted();
|
2010-09-23 03:19:47 +00:00
|
|
|
|
RegisterRoutes(RouteTable.Routes);
|
2011-03-30 06:18:35 +00:00
|
|
|
|
AreaRegistration.RegisterAllAreas();
|
2011-07-04 00:19:05 +00:00
|
|
|
|
|
2011-11-22 06:55:09 +00:00
|
|
|
|
var razor = ViewEngines.Engines.Single(e => e is RazorViewEngine);
|
2011-07-04 00:19:05 +00:00
|
|
|
|
ViewEngines.Engines.Clear();
|
|
|
|
|
ViewEngines.Engines.Add(razor);
|
|
|
|
|
|
2011-03-30 06:18:35 +00:00
|
|
|
|
RegisterGlobalFilters(GlobalFilters.Filters);
|
2011-11-03 05:04:14 +00:00
|
|
|
|
|
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()
|
|
|
|
|
{
|
2011-11-08 17:48:34 +00:00
|
|
|
|
Logger.Info("NzbDrone Starting up.");
|
2012-01-23 02:24:16 +00:00
|
|
|
|
var dispatch = new CentralDispatch();
|
2011-11-08 20:12:54 +00:00
|
|
|
|
dispatch.DedicateToHost();
|
2010-10-24 07:46:58 +00:00
|
|
|
|
|
2011-11-08 20:12:54 +00:00
|
|
|
|
dispatch.Kernel.Load(Assembly.GetExecutingAssembly());
|
|
|
|
|
return dispatch.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)
|
|
|
|
|
{
|
2010-10-17 17:22:48 +00:00
|
|
|
|
var lastError = Server.GetLastError();
|
2011-04-22 02:23:31 +00:00
|
|
|
|
|
|
|
|
|
if (lastError is HttpException && lastError.InnerException == null)
|
2010-10-17 17:22:48 +00:00
|
|
|
|
{
|
2011-03-29 05:50:18 +00:00
|
|
|
|
Logger.WarnException(String.Format("{0}. URL[{1}]", lastError.Message, Request.Path), lastError);
|
2011-04-10 02:28:54 +00:00
|
|
|
|
return;
|
2010-10-17 17:22:48 +00:00
|
|
|
|
}
|
2011-04-10 02:28:54 +00:00
|
|
|
|
|
2011-04-19 00:12:06 +00:00
|
|
|
|
Logger.FatalException(lastError.Message + Environment.NewLine + Request.Url.PathAndQuery, lastError);
|
2011-04-10 02:28:54 +00:00
|
|
|
|
|
2011-05-30 07:05:45 +00:00
|
|
|
|
if (lastError is DbException)
|
2010-10-17 17:22:48 +00:00
|
|
|
|
{
|
2011-04-10 02:28:54 +00:00
|
|
|
|
Logger.Warn("Restarting application");
|
|
|
|
|
HttpRuntime.UnloadAppDomain();
|
2010-10-17 17:22:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void Application_BeginRequest()
|
|
|
|
|
{
|
2011-11-24 05:50:41 +00:00
|
|
|
|
Thread.CurrentThread.Name = "WEB_THREAD";
|
2011-06-14 01:35:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void Application_EndRequest()
|
|
|
|
|
{
|
2010-09-23 03:19:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|