mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-09 04:22:30 +01:00
added Nancy pipelines for error handling,
cleaned up container registrations.
This commit is contained in:
parent
acef97b79f
commit
c184595935
@ -1,27 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
using Autofac;
|
||||
using NLog;
|
||||
using Nancy.Bootstrapper;
|
||||
using Nancy.Bootstrappers.Autofac;
|
||||
using NzbDrone.Api.ErrorManagment;
|
||||
using NzbDrone.Api.QualityProfiles;
|
||||
using NzbDrone.Api.QualityType;
|
||||
using NzbDrone.Api.Resolvers;
|
||||
using NzbDrone.Core;
|
||||
using NzbDrone.Core.Repository.Quality;
|
||||
|
||||
namespace NzbDrone.Api
|
||||
{
|
||||
public static class Bootstrapper
|
||||
|
||||
public class Bootstrapper : AutofacNancyBootstrapper
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
|
||||
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
//QualityProfiles
|
||||
Mapper.CreateMap<QualityProfileModel, QualityProfile>()
|
||||
.ForMember(dest => dest.QualityProfileId, opt => opt.MapFrom(src => src.Id))
|
||||
.ForMember(dest => dest.Allowed, opt => opt.ResolveUsing<QualitiesToAllowedResolver>().FromMember(src => src.Qualities));
|
||||
.ForMember(dest => dest.Allowed,
|
||||
opt => opt.ResolveUsing<QualitiesToAllowedResolver>().FromMember(src => src.Qualities));
|
||||
|
||||
Mapper.CreateMap<QualityProfile, QualityProfileModel>()
|
||||
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.QualityProfileId))
|
||||
.ForMember(dest => dest.Qualities, opt => opt.ResolveUsing<AllowedToQualitiesResolver>().FromMember(src => src.Allowed));
|
||||
.ForMember(dest => dest.Qualities,
|
||||
opt => opt.ResolveUsing<AllowedToQualitiesResolver>().FromMember(src => src.Allowed));
|
||||
|
||||
Mapper.CreateMap<QualityTypes, QualityProfileType>()
|
||||
.ForMember(dest => dest.Allowed, opt => opt.Ignore());
|
||||
@ -33,5 +43,42 @@ public static void Initialize()
|
||||
Mapper.CreateMap<Core.Repository.Quality.QualityType, QualityTypeModel>()
|
||||
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.QualityTypeId));
|
||||
}
|
||||
|
||||
protected override ILifetimeScope GetApplicationContainer()
|
||||
{
|
||||
_logger.Info("Starting NzbDrone API");
|
||||
|
||||
|
||||
var builder = new ContainerBuilder();
|
||||
|
||||
builder.RegisterCoreServices();
|
||||
|
||||
builder.RegisterAssemblyTypes(typeof(Bootstrapper).Assembly)
|
||||
.AsImplementedInterfaces()
|
||||
.SingleInstance();
|
||||
|
||||
builder.RegisterType<ErrorPipeline>().AsSelf().SingleInstance();
|
||||
|
||||
|
||||
var container = builder.Build();
|
||||
|
||||
ApplicationPipelines.OnError.AddItemToEndOfPipeline(container.Resolve<ErrorPipeline>().HandleException);
|
||||
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
protected override NancyInternalConfiguration InternalConfiguration
|
||||
{
|
||||
get
|
||||
{
|
||||
var internalConfig = NancyInternalConfiguration.Default;
|
||||
|
||||
internalConfig.StatusCodeHandlers.Add(typeof(ErrorHandler));
|
||||
|
||||
|
||||
return internalConfig;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
41
NzbDrone.Api/ErrorManagment/ApiException.cs
Normal file
41
NzbDrone.Api/ErrorManagment/ApiException.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Nancy;
|
||||
using Nancy.Responses;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Api.QualityType;
|
||||
|
||||
namespace NzbDrone.Api.ErrorManagment
|
||||
{
|
||||
public abstract class ApiException : Exception
|
||||
{
|
||||
public object Content { get; private set; }
|
||||
|
||||
|
||||
public HttpStatusCode StatusCode { get; private set; }
|
||||
|
||||
protected ApiException(HttpStatusCode statusCode, object content = null)
|
||||
: base(GetMessage(statusCode, content))
|
||||
{
|
||||
StatusCode = statusCode;
|
||||
Content = content;
|
||||
}
|
||||
|
||||
public JsonResponse<ErrorModel> ToErrorResponse()
|
||||
{
|
||||
return new ErrorModel(this).AsResponse(StatusCode);
|
||||
}
|
||||
|
||||
private static string GetMessage(HttpStatusCode statusCode, object content)
|
||||
{
|
||||
var result = statusCode.ToString();
|
||||
|
||||
if (content != null)
|
||||
{
|
||||
result = result + " :" + JsonConvert.SerializeObject(content);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
33
NzbDrone.Api/ErrorManagment/ErrorHandler.cs
Normal file
33
NzbDrone.Api/ErrorManagment/ErrorHandler.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System.Linq;
|
||||
using Nancy;
|
||||
using Nancy.ErrorHandling;
|
||||
using NzbDrone.Api.QualityType;
|
||||
|
||||
namespace NzbDrone.Api.ErrorManagment
|
||||
{
|
||||
public class ErrorHandler : IStatusCodeHandler
|
||||
{
|
||||
public bool HandlesStatusCode(HttpStatusCode statusCode, NancyContext context)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Handle(HttpStatusCode statusCode, NancyContext context)
|
||||
{
|
||||
if (statusCode == HttpStatusCode.SeeOther || statusCode == HttpStatusCode.OK)
|
||||
return;
|
||||
|
||||
if (statusCode == HttpStatusCode.Continue)
|
||||
{
|
||||
context.Response = new Response { StatusCode = statusCode };
|
||||
return;
|
||||
}
|
||||
|
||||
if (context.Response.ContentType == "text/html" || context.Response.ContentType == "text/plain")
|
||||
context.Response = new ErrorModel
|
||||
{
|
||||
Message = statusCode.ToString()
|
||||
}.AsResponse(statusCode);
|
||||
}
|
||||
}
|
||||
}
|
21
NzbDrone.Api/ErrorManagment/ErrorModel.cs
Normal file
21
NzbDrone.Api/ErrorManagment/ErrorModel.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Api.ErrorManagment
|
||||
{
|
||||
public class ErrorModel
|
||||
{
|
||||
public string Message { get; set; }
|
||||
public string Description { get; set; }
|
||||
public object Content { get; set; }
|
||||
|
||||
public ErrorModel(ApiException exception)
|
||||
{
|
||||
Message = exception.Message;
|
||||
Content = exception.Content;
|
||||
}
|
||||
|
||||
public ErrorModel()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
28
NzbDrone.Api/ErrorManagment/ErrorPipeline.cs
Normal file
28
NzbDrone.Api/ErrorManagment/ErrorPipeline.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using Nancy;
|
||||
|
||||
namespace NzbDrone.Api.ErrorManagment
|
||||
{
|
||||
public class ErrorPipeline
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
|
||||
public ErrorPipeline(Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Response HandleException(NancyContext context, Exception exception)
|
||||
{
|
||||
if (exception is ApiException)
|
||||
{
|
||||
_logger.WarnException("API Error", exception);
|
||||
return ((ApiException)exception).ToErrorResponse();
|
||||
}
|
||||
_logger.ErrorException("Unexpected error", exception);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -72,6 +72,10 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
@ -81,7 +85,11 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ErrorManagment\ApiException.cs" />
|
||||
<Compile Include="Bootstrapper.cs" />
|
||||
<Compile Include="ErrorManagment\ErrorHandler.cs" />
|
||||
<Compile Include="ErrorManagment\ErrorModel.cs" />
|
||||
<Compile Include="ErrorManagment\ErrorPipeline.cs" />
|
||||
<Compile Include="Exceptions\InvalidApiKeyException.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="QualityProfiles\QualityProfileModel.cs" />
|
||||
|
@ -21,10 +21,10 @@ public static T FromJson<T>(this Stream body)
|
||||
});
|
||||
}
|
||||
|
||||
public static Response AsResponse<TModel>(this TModel model, HttpStatusCode statusCode = HttpStatusCode.OK)
|
||||
public static JsonResponse<TModel> AsResponse<TModel>(this TModel model, HttpStatusCode statusCode = HttpStatusCode.OK)
|
||||
{
|
||||
ISerializer serializer = new DefaultJsonSerializer();
|
||||
var jsonResponse = new JsonResponse<TModel>(model, serializer) {StatusCode = statusCode};
|
||||
var jsonResponse = new JsonResponse<TModel>(model, serializer) { StatusCode = statusCode };
|
||||
return jsonResponse;
|
||||
}
|
||||
}
|
||||
|
@ -6,4 +6,5 @@
|
||||
<package id="Nancy.Bootstrappers.Autofac" version="0.15.3" targetFramework="net40" />
|
||||
<package id="Nancy.Hosting.Aspnet" version="0.15.3" targetFramework="net40" />
|
||||
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net40" />
|
||||
<package id="NLog" version="2.0.0.2000" targetFramework="net40" />
|
||||
</packages>
|
@ -1,109 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Autofac;
|
||||
using Autofac.Core;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Instrumentation;
|
||||
using NzbDrone.Core.Jobs;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Providers.ExternalNotification;
|
||||
using NzbDrone.Core.Providers.Indexer;
|
||||
using NzbDrone.Core.Providers.Metadata;
|
||||
using NzbDrone.Core.Repository;
|
||||
using PetaPoco;
|
||||
using SignalR;
|
||||
using Connection = NzbDrone.Core.Datastore.Connection;
|
||||
|
||||
namespace NzbDrone.Core
|
||||
{
|
||||
public class CentralDispatch
|
||||
{
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
private readonly Logger _logger;
|
||||
private readonly EnvironmentProvider _environmentProvider;
|
||||
|
||||
public ContainerBuilder ContainerBuilder { get; private set; }
|
||||
|
||||
public CentralDispatch()
|
||||
{
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
_environmentProvider = new EnvironmentProvider();
|
||||
|
||||
logger.Debug("Initializing ContainerBuilder:");
|
||||
_logger.Debug("Initializing ContainerBuilder:");
|
||||
ContainerBuilder = new ContainerBuilder();
|
||||
|
||||
ContainerBuilder.RegisterAssemblyTypes(typeof(DiskProvider).Assembly).SingleInstance();
|
||||
ContainerBuilder.RegisterAssemblyTypes(typeof(CentralDispatch).Assembly).SingleInstance();
|
||||
ContainerBuilder.RegisterType<EnvironmentProvider>();
|
||||
|
||||
InitDatabase();
|
||||
RegisterExternalNotifications();
|
||||
RegisterMetadataProviders();
|
||||
RegisterIndexers();
|
||||
RegisterJobs();
|
||||
}
|
||||
|
||||
private void InitDatabase()
|
||||
{
|
||||
logger.Info("Registering Database...");
|
||||
|
||||
var appDataPath = _environmentProvider.GetAppDataPath();
|
||||
if (!Directory.Exists(appDataPath)) Directory.CreateDirectory(appDataPath);
|
||||
|
||||
ContainerBuilder.Register(c => c.Resolve<Connection>().GetMainPetaPocoDb())
|
||||
.As<IDatabase>();
|
||||
|
||||
ContainerBuilder.Register(c => c.Resolve<Connection>().GetLogPetaPocoDb(false))
|
||||
.SingleInstance()
|
||||
.Named<IDatabase>("DatabaseTarget");
|
||||
|
||||
ContainerBuilder.Register(c => c.Resolve<Connection>().GetLogPetaPocoDb())
|
||||
.Named<IDatabase>("LogProvider");
|
||||
|
||||
ContainerBuilder.RegisterType<DatabaseTarget>().WithParameter(ResolvedParameter.ForNamed<IDatabase>("DatabaseTarget"));
|
||||
ContainerBuilder.RegisterType<LogProvider>().WithParameter(ResolvedParameter.ForNamed<IDatabase>("LogProvider"));
|
||||
}
|
||||
|
||||
private void RegisterIndexers()
|
||||
{
|
||||
logger.Debug("Registering Indexers...");
|
||||
|
||||
ContainerBuilder.RegisterAssemblyTypes(typeof(CentralDispatch).Assembly)
|
||||
.Where(t => t.BaseType == typeof(IndexerBase))
|
||||
.As<IndexerBase>();
|
||||
}
|
||||
|
||||
private void RegisterJobs()
|
||||
{
|
||||
logger.Debug("Registering Background Jobs...");
|
||||
|
||||
ContainerBuilder.RegisterType<JobProvider>().SingleInstance();
|
||||
|
||||
ContainerBuilder.RegisterAssemblyTypes(typeof(CentralDispatch).Assembly)
|
||||
.Where(t => t.GetInterfaces().Contains(typeof(IJob)))
|
||||
.As<IJob>()
|
||||
.SingleInstance();
|
||||
}
|
||||
|
||||
private void RegisterExternalNotifications()
|
||||
{
|
||||
logger.Debug("Registering External Notifications...");
|
||||
|
||||
ContainerBuilder.RegisterAssemblyTypes(typeof(CentralDispatch).Assembly)
|
||||
.Where(t => t.BaseType == typeof(ExternalNotificationBase))
|
||||
.As<ExternalNotificationBase>();
|
||||
}
|
||||
|
||||
private void RegisterMetadataProviders()
|
||||
{
|
||||
logger.Debug("Registering Metadata Providers...");
|
||||
|
||||
ContainerBuilder.RegisterAssemblyTypes(typeof(CentralDispatch).Assembly)
|
||||
.Where(t => t.IsSubclassOf(typeof(MetadataBase)))
|
||||
.As<MetadataBase>();
|
||||
}
|
||||
|
||||
private void RegisterReporting(IContainer container)
|
||||
@ -113,12 +34,6 @@ private void RegisterReporting(IContainer container)
|
||||
ReportingService.SetupExceptronDriver();
|
||||
}
|
||||
|
||||
private void RegisterQuality(IContainer container)
|
||||
{
|
||||
logger.Debug("Initializing Quality...");
|
||||
container.Resolve<QualityProvider>().SetupDefaultProfiles();
|
||||
container.Resolve<QualityTypeProvider>().SetupDefault();
|
||||
}
|
||||
|
||||
public void DedicateToHost()
|
||||
{
|
||||
@ -126,67 +41,49 @@ public void DedicateToHost()
|
||||
{
|
||||
var pid = _environmentProvider.NzbDroneProcessIdFromEnviroment;
|
||||
|
||||
logger.Debug("Attaching to parent process ({0}) for automatic termination.", pid);
|
||||
_logger.Debug("Attaching to parent process ({0}) for automatic termination.", pid);
|
||||
|
||||
var hostProcess = Process.GetProcessById(Convert.ToInt32(pid));
|
||||
|
||||
hostProcess.EnableRaisingEvents = true;
|
||||
hostProcess.Exited += (delegate
|
||||
{
|
||||
logger.Info("Host has been terminated. Shutting down web server.");
|
||||
_logger.Info("Host has been terminated. Shutting down web server.");
|
||||
ShutDown();
|
||||
});
|
||||
|
||||
logger.Debug("Successfully Attached to host. Process [{0}]", hostProcess.ProcessName);
|
||||
_logger.Debug("Successfully Attached to host. Process [{0}]", hostProcess.ProcessName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.FatalException("An error has occurred while dedicating to host.", e);
|
||||
_logger.FatalException("An error has occurred while dedicating to host.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public IContainer BuildContainer()
|
||||
{
|
||||
var container = ContainerBuilder.Build();
|
||||
_logger.Debug("Initializing Components");
|
||||
|
||||
logger.Debug("Initializing Components");
|
||||
ContainerBuilder.RegisterCoreServices();
|
||||
|
||||
var container = ContainerBuilder.Build();
|
||||
|
||||
container.Resolve<DatabaseTarget>().Register();
|
||||
LogConfiguration.Reload();
|
||||
|
||||
RegisterReporting(container);
|
||||
RegisterQuality(container);
|
||||
|
||||
var indexers = container.Resolve<IEnumerable<IndexerBase>>();
|
||||
container.Resolve<IndexerProvider>().InitializeIndexers(indexers.ToList());
|
||||
|
||||
var newznabIndexers = new List<NewznabDefinition>
|
||||
{
|
||||
new NewznabDefinition { Enable = false, Name = "Nzbs.org", Url = "http://nzbs.org", BuiltIn = true },
|
||||
new NewznabDefinition { Enable = false, Name = "Nzb.su", Url = "https://nzb.su", BuiltIn = true },
|
||||
new NewznabDefinition { Enable = false, Name = "Dognzb.cr", Url = "https://dognzb.cr", BuiltIn = true }
|
||||
};
|
||||
|
||||
container.Resolve<NewznabProvider>().InitializeNewznabIndexers(newznabIndexers);
|
||||
|
||||
container.Resolve<JobProvider>().Initialize();
|
||||
container.Resolve<WebTimer>().StartTimer(30);
|
||||
|
||||
var notifiers = container.Resolve<IEnumerable<ExternalNotificationBase>>();
|
||||
container.Resolve<ExternalNotificationProvider>().InitializeNotifiers(notifiers.ToList());
|
||||
|
||||
var providers = container.Resolve<IEnumerable<MetadataBase>>();
|
||||
container.Resolve<MetadataProvider>().Initialize(providers.ToList());
|
||||
|
||||
//SignalR
|
||||
GlobalHost.DependencyResolver = new AutofacSignalrDependencyResolver(container.BeginLifetimeScope("SignalR"));
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
private static void ShutDown()
|
||||
private void ShutDown()
|
||||
{
|
||||
logger.Info("Shutting down application...");
|
||||
_logger.Info("Shutting down application...");
|
||||
WebTimer.Stop();
|
||||
Process.GetCurrentProcess().Kill();
|
||||
}
|
||||
|
86
NzbDrone.Core/ContainerExtentions.cs
Normal file
86
NzbDrone.Core/ContainerExtentions.cs
Normal file
@ -0,0 +1,86 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Autofac;
|
||||
using Autofac.Core;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Instrumentation;
|
||||
using NzbDrone.Core.Providers.ExternalNotification;
|
||||
using NzbDrone.Core.Providers.Indexer;
|
||||
using NzbDrone.Core.Providers.Metadata;
|
||||
using NzbDrone.Core.Providers.Search;
|
||||
using PetaPoco;
|
||||
|
||||
namespace NzbDrone.Core
|
||||
{
|
||||
public static class ContainerExtentions
|
||||
{
|
||||
|
||||
private static Logger _logger = LogManager.GetLogger("ServiceRegistration");
|
||||
|
||||
public static void RegisterCoreServices(this ContainerBuilder container)
|
||||
{
|
||||
var core = Assembly.Load("NzbDrone.Core");
|
||||
var common = Assembly.Load("NzbDrone.Common");
|
||||
|
||||
|
||||
container.RegisterAssembly(core);
|
||||
container.RegisterAssembly(common);
|
||||
|
||||
container.InitDatabase();
|
||||
}
|
||||
|
||||
|
||||
private static void RegisterAssembly(this ContainerBuilder container, Assembly assembly)
|
||||
{
|
||||
container.RegisterAssemblyTypes(assembly)
|
||||
.AsSelf()
|
||||
.SingleInstance();
|
||||
|
||||
container.RegisterAssemblyTypes(assembly)
|
||||
.AsImplementedInterfaces()
|
||||
.SingleInstance();
|
||||
|
||||
container.RegisterAssemblyTypes(assembly)
|
||||
.Where(t => t.BaseType == typeof(IndexerBase))
|
||||
.As<IndexerBase>().SingleInstance();
|
||||
|
||||
container.RegisterAssemblyTypes(assembly)
|
||||
.Where(t => t.BaseType == typeof(SearchBase))
|
||||
.As<SearchBase>().SingleInstance();
|
||||
|
||||
container.RegisterAssemblyTypes(assembly)
|
||||
.Where(t => t.BaseType == typeof(ExternalNotificationBase))
|
||||
.As<ExternalNotificationBase>().SingleInstance();
|
||||
|
||||
container.RegisterAssemblyTypes(assembly)
|
||||
.Where(t => t.BaseType == typeof(MetadataBase))
|
||||
.As<MetadataBase>().SingleInstance();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static void InitDatabase(this ContainerBuilder container)
|
||||
{
|
||||
_logger.Info("Registering Database...");
|
||||
|
||||
var appDataPath = new EnvironmentProvider().GetAppDataPath();
|
||||
if (!Directory.Exists(appDataPath)) Directory.CreateDirectory(appDataPath);
|
||||
|
||||
container.Register(c => c.Resolve<Connection>().GetMainPetaPocoDb())
|
||||
.As<IDatabase>();
|
||||
|
||||
container.Register(c => c.Resolve<Connection>().GetLogPetaPocoDb(false))
|
||||
.SingleInstance()
|
||||
.Named<IDatabase>("DatabaseTarget");
|
||||
|
||||
container.Register(c => c.Resolve<Connection>().GetLogPetaPocoDb())
|
||||
.Named<IDatabase>("LogProvider");
|
||||
|
||||
container.RegisterType<DatabaseTarget>().WithParameter(ResolvedParameter.ForNamed<IDatabase>("DatabaseTarget"));
|
||||
container.RegisterType<LogProvider>().WithParameter(ResolvedParameter.ForNamed<IDatabase>("LogProvider"));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
//https://github.com/kayone/NzbDrone/blob/master/NzbDrone.Core/Providers/Jobs/JobProvider.cs
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -29,7 +27,7 @@ public class JobProvider
|
||||
private Thread _jobThread;
|
||||
public Stopwatch StopWatch { get; private set; }
|
||||
|
||||
private readonly object executionLock = new object();
|
||||
private readonly object _executionLock = new object();
|
||||
private readonly List<JobQueueItem> _queue = new List<JobQueueItem>();
|
||||
|
||||
private ProgressNotification _notification;
|
||||
@ -42,6 +40,7 @@ public JobProvider(IDatabase database, NotificationProvider notificationProvider
|
||||
_notificationProvider = notificationProvider;
|
||||
_jobs = jobs;
|
||||
ResetThread();
|
||||
Initialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -67,7 +66,7 @@ public virtual List<JobDefinition> All()
|
||||
return _database.Fetch<JobDefinition>().ToList();
|
||||
}
|
||||
|
||||
public virtual void Initialize()
|
||||
private void Initialize()
|
||||
{
|
||||
var currentJobs = All();
|
||||
logger.Debug("Initializing jobs. Available: {0} Existing:{1}", _jobs.Count(), currentJobs.Count);
|
||||
@ -121,7 +120,7 @@ public virtual void SaveDefinition(JobDefinition definitions)
|
||||
|
||||
public virtual void QueueScheduled()
|
||||
{
|
||||
lock (executionLock)
|
||||
lock (_executionLock)
|
||||
{
|
||||
VerifyThreadTime();
|
||||
|
||||
@ -153,7 +152,7 @@ public virtual void QueueJob(Type jobType, dynamic options = null, JobQueueItem.
|
||||
|
||||
logger.Debug("Attempting to queue {0}", queueItem);
|
||||
|
||||
lock (executionLock)
|
||||
lock (_executionLock)
|
||||
{
|
||||
VerifyThreadTime();
|
||||
|
||||
@ -215,7 +214,7 @@ private void ProcessQueue()
|
||||
{
|
||||
if (Queue.Count != 0)
|
||||
{
|
||||
job = Queue.OrderBy(c=>c.Source).First();
|
||||
job = Queue.OrderBy(c => c.Source).First();
|
||||
logger.Trace("Popping {0} from the queue.", job);
|
||||
Queue.Remove(job);
|
||||
}
|
||||
|
@ -222,6 +222,7 @@
|
||||
<Link>Properties\SharedAssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Constants.cs" />
|
||||
<Compile Include="ContainerExtentions.cs" />
|
||||
<Compile Include="Datastore\Connection.cs" />
|
||||
<Compile Include="Datastore\MigrationLogger.cs" />
|
||||
<Compile Include="Datastore\MigrationsHelper.cs" />
|
||||
@ -613,6 +614,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="ClassDiagram1.cd" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="Properties\AnalysisRules.ruleset" />
|
||||
</ItemGroup>
|
||||
|
@ -18,4 +18,4 @@
|
||||
// by using the '*' as shown below:
|
||||
|
||||
[assembly: AssemblyVersion("1.0.0.*")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.*")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.*")]
|
||||
|
@ -14,12 +14,14 @@ public class ExternalNotificationProvider
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
private readonly IDatabase _database;
|
||||
|
||||
private IEnumerable<ExternalNotificationBase> _notifiers;
|
||||
private IList<ExternalNotificationBase> _notifiers;
|
||||
|
||||
public ExternalNotificationProvider(IDatabase database, IEnumerable<ExternalNotificationBase> notifiers)
|
||||
{
|
||||
_database = database;
|
||||
_notifiers = notifiers;
|
||||
_notifiers = notifiers.ToList();
|
||||
|
||||
InitializeNotifiers(_notifiers);
|
||||
}
|
||||
|
||||
public ExternalNotificationProvider()
|
||||
@ -58,7 +60,7 @@ public virtual IList<ExternalNotificationBase> GetEnabledExternalNotifiers()
|
||||
return _notifiers.Where(i => all.Exists(c => c.ExternalNotificationProviderType == i.GetType().ToString() && c.Enable)).ToList();
|
||||
}
|
||||
|
||||
public virtual void InitializeNotifiers(IList<ExternalNotificationBase> notifiers)
|
||||
private void InitializeNotifiers(IList<ExternalNotificationBase> notifiers)
|
||||
{
|
||||
Logger.Debug("Initializing notifiers. Count {0}", notifiers.Count);
|
||||
|
||||
|
@ -13,12 +13,14 @@ public class IndexerProvider
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
private readonly IDatabase _database;
|
||||
|
||||
private IEnumerable<IndexerBase> _indexers;
|
||||
private IList<IndexerBase> _indexers;
|
||||
|
||||
public IndexerProvider(IDatabase database, IEnumerable<IndexerBase> indexers)
|
||||
{
|
||||
_database = database;
|
||||
_indexers = indexers;
|
||||
_indexers = indexers.ToList();
|
||||
InitializeIndexers();
|
||||
|
||||
}
|
||||
|
||||
public IndexerProvider()
|
||||
@ -56,15 +58,14 @@ public virtual IndexerDefinition GetSettings(Type type)
|
||||
return _database.Single<IndexerDefinition>("WHERE IndexProviderType = @0", type.ToString());
|
||||
}
|
||||
|
||||
public virtual void InitializeIndexers(IList<IndexerBase> indexers)
|
||||
private void InitializeIndexers()
|
||||
{
|
||||
Logger.Debug("Initializing indexers. Count {0}", indexers.Count);
|
||||
Logger.Debug("Initializing indexers. Count {0}", _indexers.Count);
|
||||
|
||||
_indexers = indexers;
|
||||
|
||||
var currentIndexers = All();
|
||||
|
||||
foreach (var feedProvider in indexers)
|
||||
foreach (var feedProvider in _indexers)
|
||||
{
|
||||
IndexerBase indexerLocal = feedProvider;
|
||||
if (!currentIndexers.Exists(c => c.IndexProviderType == indexerLocal.GetType().ToString()))
|
||||
|
@ -16,15 +16,17 @@ public class MetadataProvider
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
private readonly IDatabase _database;
|
||||
|
||||
private IEnumerable<MetadataBase> _metadataProviders;
|
||||
private IList<MetadataBase> _metadataProviders;
|
||||
private readonly TvDbProvider _tvDbProvider;
|
||||
|
||||
public MetadataProvider(IDatabase database, IEnumerable<MetadataBase> metadataProviders,
|
||||
TvDbProvider tvDbProvider)
|
||||
{
|
||||
_database = database;
|
||||
_metadataProviders = metadataProviders;
|
||||
_metadataProviders = metadataProviders.ToList();
|
||||
_tvDbProvider = tvDbProvider;
|
||||
|
||||
Initialize(_metadataProviders);
|
||||
}
|
||||
|
||||
public MetadataProvider()
|
||||
@ -63,7 +65,7 @@ public virtual IList<MetadataBase> GetEnabledMetabaseProviders()
|
||||
return _metadataProviders.Where(i => all.Exists(c => c.MetadataProviderType == i.GetType().ToString() && c.Enable)).ToList();
|
||||
}
|
||||
|
||||
public virtual void Initialize(IList<MetadataBase> metabaseProviders)
|
||||
private void Initialize(IList<MetadataBase> metabaseProviders)
|
||||
{
|
||||
Logger.Debug("Initializing metabases. Count {0}", metabaseProviders.Count);
|
||||
|
||||
|
@ -17,6 +17,15 @@ public class NewznabProvider
|
||||
public NewznabProvider(IDatabase database)
|
||||
{
|
||||
_database = database;
|
||||
|
||||
var newznabIndexers = new List<NewznabDefinition>
|
||||
{
|
||||
new NewznabDefinition { Enable = false, Name = "Nzbs.org", Url = "http://nzbs.org", BuiltIn = true },
|
||||
new NewznabDefinition { Enable = false, Name = "Nzb.su", Url = "https://nzb.su", BuiltIn = true },
|
||||
new NewznabDefinition { Enable = false, Name = "Dognzb.cr", Url = "https://dognzb.cr", BuiltIn = true }
|
||||
};
|
||||
|
||||
InitializeNewznabIndexers(newznabIndexers);
|
||||
}
|
||||
|
||||
public NewznabProvider()
|
||||
@ -55,7 +64,7 @@ public virtual void SaveAll(IEnumerable<NewznabDefinition> definitions)
|
||||
var definitionsList = definitions.ToList();
|
||||
|
||||
//Cleanup the URL for each definition
|
||||
foreach(var newznabDefinition in definitionsList)
|
||||
foreach (var newznabDefinition in definitionsList)
|
||||
{
|
||||
CheckHostname(newznabDefinition.Url);
|
||||
//newznabDefinition.Url = new Uri(newznabDefinition.Url).ParentUriString();
|
||||
@ -64,7 +73,7 @@ public virtual void SaveAll(IEnumerable<NewznabDefinition> definitions)
|
||||
_database.UpdateMany(definitionsList);
|
||||
}
|
||||
|
||||
public virtual void InitializeNewznabIndexers(IList<NewznabDefinition> indexers)
|
||||
private void InitializeNewznabIndexers(IList<NewznabDefinition> indexers)
|
||||
{
|
||||
Logger.Debug("Initializing Newznab indexers. Count {0}", indexers.Count);
|
||||
|
||||
@ -78,7 +87,7 @@ public virtual void InitializeNewznabIndexers(IList<NewznabDefinition> indexers)
|
||||
|
||||
currentIndexers = All();
|
||||
|
||||
foreach(var feedProvider in indexers)
|
||||
foreach (var feedProvider in indexers)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -115,7 +124,7 @@ public virtual void InitializeNewznabIndexers(IList<NewznabDefinition> indexers)
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.ErrorException("An Error occurred while initializing Newznab Indexers", ex);
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ public QualityProvider()
|
||||
public QualityProvider(IDatabase database)
|
||||
{
|
||||
_database = database;
|
||||
SetupDefaultProfiles();
|
||||
}
|
||||
|
||||
public virtual int Add(QualityProfile profile)
|
||||
@ -54,7 +55,7 @@ public virtual QualityProfile Get(int profileId)
|
||||
return _database.Single<QualityProfile>(profileId);
|
||||
}
|
||||
|
||||
public virtual void SetupDefaultProfiles()
|
||||
private void SetupDefaultProfiles()
|
||||
{
|
||||
if (All().Count != 0)
|
||||
return;
|
||||
|
@ -17,11 +17,12 @@ public class QualityTypeProvider
|
||||
public QualityTypeProvider(IDatabase database)
|
||||
{
|
||||
_database = database;
|
||||
SetupDefault();
|
||||
}
|
||||
|
||||
public QualityTypeProvider()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public virtual void Update(QualityType qualityType)
|
||||
@ -52,13 +53,13 @@ public virtual List<QualityType> GetList(List<int> qualityTypeIds)
|
||||
return _database.Fetch<QualityType>(query);
|
||||
}
|
||||
|
||||
public virtual void SetupDefault()
|
||||
private void SetupDefault()
|
||||
{
|
||||
var inDb = All();
|
||||
|
||||
Logger.Debug("Setting up default quality types");
|
||||
|
||||
foreach(var qualityType in QualityTypes.All())
|
||||
foreach (var qualityType in QualityTypes.All())
|
||||
{
|
||||
//Skip UNKNOWN
|
||||
if (qualityType.Id == 0) continue;
|
||||
|
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
@ -9,16 +8,10 @@
|
||||
using Autofac;
|
||||
using Autofac.Integration.Mvc;
|
||||
using LowercaseRoutesMVC;
|
||||
using NLog.Config;
|
||||
using NLog;
|
||||
using NzbDrone.Api;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core;
|
||||
using ServiceStack.CacheAccess;
|
||||
using ServiceStack.CacheAccess.Providers;
|
||||
using NzbDrone.Core.Repository.Quality;
|
||||
using NzbDrone.Web.Helpers.Binders;
|
||||
using ServiceStack.ServiceInterface;
|
||||
using SignalR;
|
||||
|
||||
namespace NzbDrone.Web
|
||||
@ -82,9 +75,6 @@ private void InitContainer()
|
||||
//SignalR
|
||||
RouteTable.Routes.MapHubs();
|
||||
|
||||
//ServiceStack
|
||||
dispatch.ContainerBuilder.RegisterType<MemoryCacheClient>().As<ICacheClient>().SingleInstance();
|
||||
dispatch.ContainerBuilder.RegisterType<SessionFactory>().As<ISessionFactory>().SingleInstance();
|
||||
}
|
||||
|
||||
private static void MVCRegistration(ContainerBuilder builder)
|
||||
|
@ -107,38 +107,6 @@
|
||||
<Reference Include="NLog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ServiceStack, Version=3.9.25.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\ServiceStack.3.9.25\lib\net35\ServiceStack.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ServiceStack.Common, Version=3.9.25.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\ServiceStack.Common.3.9.25\lib\net35\ServiceStack.Common.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ServiceStack.FluentValidation.Mvc3, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\ServiceStack.Mvc.3.9.25\lib\net40\ServiceStack.FluentValidation.Mvc3.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ServiceStack.Interfaces, Version=3.9.25.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\ServiceStack.Common.3.9.25\lib\net35\ServiceStack.Interfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ServiceStack.OrmLite, Version=3.9.26.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\ServiceStack.OrmLite.SqlServer.3.9.26\lib\ServiceStack.OrmLite.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ServiceStack.OrmLite.SqlServer, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\ServiceStack.OrmLite.SqlServer.3.9.26\lib\ServiceStack.OrmLite.SqlServer.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ServiceStack.Redis, Version=3.9.25.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\ServiceStack.Redis.3.9.25\lib\net35\ServiceStack.Redis.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ServiceStack.ServiceInterface, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\ServiceStack.3.9.25\lib\net35\ServiceStack.ServiceInterface.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ServiceStack.Text, Version=3.9.27.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\ServiceStack.Text.3.9.27\lib\net35\ServiceStack.Text.dll</HintPath>
|
||||
|
@ -28,11 +28,6 @@
|
||||
<package id="MiniProfiler.MVC3" version="2.0.2" />
|
||||
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net40" />
|
||||
<package id="NLog" version="2.0.0.2000" />
|
||||
<package id="ServiceStack" version="3.9.25" targetFramework="net40" />
|
||||
<package id="ServiceStack.Common" version="3.9.25" targetFramework="net40" />
|
||||
<package id="ServiceStack.Mvc" version="3.9.25" targetFramework="net40" />
|
||||
<package id="ServiceStack.OrmLite.SqlServer" version="3.9.26" targetFramework="net40" />
|
||||
<package id="ServiceStack.Redis" version="3.9.25" targetFramework="net40" />
|
||||
<package id="ServiceStack.Text" version="3.9.27" targetFramework="net40" />
|
||||
<package id="SignalR.Hosting.AspNet" version="0.5.3" targetFramework="net40" />
|
||||
<package id="SignalR.Hosting.Common" version="0.5.3" targetFramework="net40" />
|
||||
|
Loading…
Reference in New Issue
Block a user