2013-02-09 10:04:18 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2012-11-04 01:39:29 +00:00
|
|
|
|
using AutoMapper;
|
2013-01-19 04:46:43 +00:00
|
|
|
|
using Autofac;
|
|
|
|
|
using NLog;
|
|
|
|
|
using Nancy.Bootstrapper;
|
|
|
|
|
using Nancy.Bootstrappers.Autofac;
|
2013-02-18 02:10:21 +00:00
|
|
|
|
using Nancy.Conventions;
|
|
|
|
|
using Nancy.Diagnostics;
|
2013-01-19 04:46:43 +00:00
|
|
|
|
using NzbDrone.Api.ErrorManagment;
|
2013-01-25 19:03:28 +00:00
|
|
|
|
using NzbDrone.Api.Extentions;
|
2012-11-04 01:39:29 +00:00
|
|
|
|
using NzbDrone.Api.QualityProfiles;
|
2013-01-02 02:06:55 +00:00
|
|
|
|
using NzbDrone.Api.QualityType;
|
2012-11-09 16:28:59 +00:00
|
|
|
|
using NzbDrone.Api.Resolvers;
|
2013-02-09 10:04:18 +00:00
|
|
|
|
using NzbDrone.Api.Series;
|
2013-01-19 04:46:43 +00:00
|
|
|
|
using NzbDrone.Core;
|
2013-02-09 10:04:18 +00:00
|
|
|
|
using NzbDrone.Core.Helpers;
|
2012-11-04 01:39:29 +00:00
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2013-02-18 02:10:21 +00:00
|
|
|
|
using ErrorPipeline = NzbDrone.Api.ErrorManagment.ErrorPipeline;
|
2012-11-04 01:39:29 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api
|
|
|
|
|
{
|
2013-01-19 04:46:43 +00:00
|
|
|
|
|
|
|
|
|
public class Bootstrapper : AutofacNancyBootstrapper
|
2012-11-04 01:39:29 +00:00
|
|
|
|
{
|
2013-01-19 04:46:43 +00:00
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
2013-01-20 00:19:27 +00:00
|
|
|
|
public Bootstrapper()
|
|
|
|
|
{
|
|
|
|
|
_logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
}
|
2013-01-19 04:46:43 +00:00
|
|
|
|
|
2013-02-18 02:10:21 +00:00
|
|
|
|
protected override Nancy.IRootPathProvider RootPathProvider
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return new RootPathProvider();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-20 01:00:20 +00:00
|
|
|
|
protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
|
|
|
|
|
{
|
|
|
|
|
InitializeAutomapper();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void InitializeAutomapper()
|
2012-11-04 01:39:29 +00:00
|
|
|
|
{
|
2013-01-02 02:06:55 +00:00
|
|
|
|
//QualityProfiles
|
2012-12-03 03:08:26 +00:00
|
|
|
|
Mapper.CreateMap<QualityProfile, QualityProfileModel>()
|
|
|
|
|
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.QualityProfileId))
|
2013-01-19 04:46:43 +00:00
|
|
|
|
.ForMember(dest => dest.Qualities,
|
|
|
|
|
opt => opt.ResolveUsing<AllowedToQualitiesResolver>().FromMember(src => src.Allowed));
|
2012-11-24 08:03:38 +00:00
|
|
|
|
|
2013-02-09 10:04:18 +00:00
|
|
|
|
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));
|
|
|
|
|
|
2012-11-24 08:03:38 +00:00
|
|
|
|
Mapper.CreateMap<QualityTypes, QualityProfileType>()
|
|
|
|
|
.ForMember(dest => dest.Allowed, opt => opt.Ignore());
|
2013-01-02 02:06:55 +00:00
|
|
|
|
|
|
|
|
|
//QualityTypes
|
2013-02-09 10:04:18 +00:00
|
|
|
|
Mapper.CreateMap<Core.Repository.Quality.QualityType, QualityTypeModel>()
|
|
|
|
|
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.QualityTypeId));
|
|
|
|
|
|
2013-01-02 02:06:55 +00:00
|
|
|
|
Mapper.CreateMap<QualityTypeModel, Core.Repository.Quality.QualityType>()
|
|
|
|
|
.ForMember(dest => dest.QualityTypeId, opt => opt.MapFrom(src => src.Id));
|
|
|
|
|
|
2013-02-09 10:04:18 +00:00
|
|
|
|
//Series
|
2013-02-13 06:32:17 +00:00
|
|
|
|
Mapper.CreateMap<Core.Repository.Series, SeriesResource>()
|
2013-02-10 10:28:56 +00:00
|
|
|
|
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.SeriesId))
|
2013-02-12 05:13:41 +00:00
|
|
|
|
.ForMember(dest => dest.CustomStartDate, opt => opt.ResolveUsing<NullableDatetimeToString>().FromMember(src => src.CustomStartDate))
|
2013-02-14 03:56:06 +00:00
|
|
|
|
.ForMember(dest => dest.BacklogSetting, opt => opt.MapFrom(src => (Int32)src.BacklogSetting))
|
|
|
|
|
.ForMember(dest => dest.NextAiring, opt => opt.ResolveUsing<NextAiringResolver>());
|
2012-11-04 01:39:29 +00:00
|
|
|
|
}
|
2013-01-19 04:46:43 +00:00
|
|
|
|
|
|
|
|
|
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));
|
2013-01-25 19:03:28 +00:00
|
|
|
|
internalConfig.Serializers.Add(typeof(NancyJsonSerializer));
|
2013-01-19 04:46:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return internalConfig;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-18 02:10:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override DiagnosticsConfiguration DiagnosticsConfiguration
|
|
|
|
|
{
|
|
|
|
|
get { return new DiagnosticsConfiguration { Password = @"password" }; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void ConfigureConventions(Nancy.Conventions.NancyConventions nancyConventions)
|
|
|
|
|
{
|
|
|
|
|
base.ConfigureConventions(nancyConventions);
|
|
|
|
|
Conventions.StaticContentsConventions.Add(StaticContentConventionBuilder.AddDirectory("static", @"NzbDrone.Backbone",new string[]{".css",".js",".html",".htm",".jpg",".jpeg",".icon",".gif",".png",".woff",".ttf"}));
|
|
|
|
|
}
|
2012-11-04 01:39:29 +00:00
|
|
|
|
}
|
2013-01-19 04:46:43 +00:00
|
|
|
|
}
|