2010-10-15 10:10:44 +03:00
|
|
|
using System;
|
2011-05-30 10:05:45 +03:00
|
|
|
using System.Data.Common;
|
2011-09-04 06:05:44 +03:00
|
|
|
using System.Linq;
|
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;
|
2012-10-15 03:53:34 +03:00
|
|
|
using LowercaseRoutesMVC;
|
2011-11-14 03:22:18 +03:00
|
|
|
using NLog.Config;
|
2010-09-23 06:19:47 +03:00
|
|
|
using Ninject;
|
2012-11-03 21:23:47 +03:00
|
|
|
using Ninject.Web.Common;
|
2010-10-15 10:10:44 +03:00
|
|
|
using NLog;
|
2012-11-03 21:23:47 +03:00
|
|
|
using NzbDrone.Api;
|
2011-11-14 03:22:18 +03:00
|
|
|
using NzbDrone.Common;
|
2010-09-23 06:19:47 +03:00
|
|
|
using NzbDrone.Core;
|
2012-11-02 10:35:49 +03:00
|
|
|
using ServiceStack.CacheAccess;
|
|
|
|
using ServiceStack.CacheAccess.Providers;
|
2012-11-13 19:27:48 +03:00
|
|
|
using NzbDrone.Core.Repository.Quality;
|
|
|
|
using NzbDrone.Web.Helpers.Binders;
|
2012-11-02 10:35:49 +03:00
|
|
|
using ServiceStack.ServiceInterface;
|
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)
|
|
|
|
{
|
2012-11-02 10:35:49 +03:00
|
|
|
routes.IgnoreRoute("api/{*pathInfo}");
|
2010-09-23 06:19:47 +03:00
|
|
|
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
|
2011-04-19 03:12:06 +03:00
|
|
|
routes.IgnoreRoute("{*robotstxt}", new { robotstxt = @"(.*/)?robots.txt(/.*)?" });
|
|
|
|
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
|
2012-11-02 10:35:49 +03:00
|
|
|
|
2012-10-22 10:05:27 +03:00
|
|
|
routes.MapRouteLowercase(
|
|
|
|
name: "WithSeasonNumber",
|
2012-10-26 07:20:50 +03:00
|
|
|
url: "{controller}/{action}/{seriesId}/{seasonNumber}"
|
2012-10-22 10:05:27 +03:00
|
|
|
);
|
2011-03-31 04:42:27 +03:00
|
|
|
|
2012-10-15 03:53:34 +03:00
|
|
|
routes.MapRouteLowercase(
|
2012-10-22 10:05:27 +03:00
|
|
|
name: "SeriesId",
|
|
|
|
url: "{controller}/{action}/{seriesId}",
|
|
|
|
defaults: new { controller = "Series", action = "Index", seriesId = UrlParameter.Optional }
|
|
|
|
);
|
2010-09-23 06:19:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnApplicationStarted()
|
2012-11-03 21:23:47 +03:00
|
|
|
{
|
2011-03-30 09:18:35 +03:00
|
|
|
base.OnApplicationStarted();
|
2012-11-03 21:23:47 +03:00
|
|
|
|
2010-09-23 06:19:47 +03:00
|
|
|
RegisterRoutes(RouteTable.Routes);
|
2011-03-30 09:18:35 +03:00
|
|
|
AreaRegistration.RegisterAllAreas();
|
2011-07-04 03:19:05 +03:00
|
|
|
|
2011-11-22 09:55:09 +03:00
|
|
|
var razor = ViewEngines.Engines.Single(e => e is RazorViewEngine);
|
2011-07-04 03:19:05 +03:00
|
|
|
ViewEngines.Engines.Clear();
|
|
|
|
ViewEngines.Engines.Add(razor);
|
|
|
|
|
2012-11-13 19:27:48 +03:00
|
|
|
ModelBinders.Binders.Add(typeof(QualityTypes), new QualityTypesBinder());
|
|
|
|
|
2011-03-30 09:18:35 +03:00
|
|
|
RegisterGlobalFilters(GlobalFilters.Filters);
|
2011-11-03 08:04:14 +03:00
|
|
|
|
2011-10-24 08:54:09 +03:00
|
|
|
Logger.Info("Fully initialized and ready.");
|
2010-09-29 20:19:18 +03:00
|
|
|
}
|
2010-09-23 06:19:47 +03:00
|
|
|
|
|
|
|
protected override IKernel CreateKernel()
|
|
|
|
{
|
2011-11-08 20:48:34 +03:00
|
|
|
Logger.Info("NzbDrone Starting up.");
|
2012-01-23 05:24:16 +03:00
|
|
|
var dispatch = new CentralDispatch();
|
2011-11-08 23:12:54 +03:00
|
|
|
dispatch.DedicateToHost();
|
2010-10-24 10:46:58 +03:00
|
|
|
|
2011-11-08 23:12:54 +03:00
|
|
|
dispatch.Kernel.Load(Assembly.GetExecutingAssembly());
|
2012-11-02 10:35:49 +03:00
|
|
|
|
|
|
|
//ServiceStack
|
|
|
|
dispatch.Kernel.Bind<ICacheClient>().To<MemoryCacheClient>().InSingletonScope();
|
|
|
|
dispatch.Kernel.Bind<ISessionFactory>().To<SessionFactory>().InSingletonScope();
|
2012-11-03 21:23:47 +03:00
|
|
|
new AppHost(dispatch.Kernel).Init();
|
2012-11-02 10:35:49 +03:00
|
|
|
|
2011-11-08 23:12:54 +03:00
|
|
|
return dispatch.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();
|
2011-04-22 05:23:31 +03:00
|
|
|
|
|
|
|
if (lastError is HttpException && lastError.InnerException == null)
|
2010-10-17 20:22:48 +03:00
|
|
|
{
|
2011-03-29 08:50:18 +03:00
|
|
|
Logger.WarnException(String.Format("{0}. URL[{1}]", lastError.Message, Request.Path), lastError);
|
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
|
|
|
|
2011-04-19 03:12:06 +03:00
|
|
|
Logger.FatalException(lastError.Message + Environment.NewLine + Request.Url.PathAndQuery, lastError);
|
2011-04-10 05:28:54 +03:00
|
|
|
|
2011-05-30 10:05:45 +03:00
|
|
|
if (lastError is DbException)
|
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()
|
|
|
|
{
|
2011-11-24 08:50:41 +03:00
|
|
|
Thread.CurrentThread.Name = "WEB_THREAD";
|
2011-06-14 04:35:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void Application_EndRequest()
|
|
|
|
{
|
2010-09-23 06:19:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|