-
Notifications
You must be signed in to change notification settings - Fork 0
/
Startup.cs
109 lines (97 loc) · 4.52 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using Refit;
using ConversionProxy.Services;
using Hangfire;
using Hangfire.MemoryStorage;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using ConversionProxy.Proxies;
using Microsoft.OpenApi.Models;
using Sonarr.Models;
using Radarr.Models;
using ConversionProxy.Filters;
using Hangfire.LiteDB;
using Microsoft.Extensions.Logging;
using Hangfire.Console;
using Converter.Web.Proxy.Models;
using Converter.Web.Proxy.Services;
namespace ConversionProxy
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
GlobalConfiguration.Configuration.UseLiteDbStorage(Configuration[key: "ConnectionStrings:Database"]);
services.AddMvc();
// If using Kestrel:
services.Configure<KestrelServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
services.AddSingleton<ISettingsService, SettingsService>();
var sp = services.BuildServiceProvider();
var settings = sp.GetService<ISettingsService>();
services.AddRefitClient<IPlexAutoscanProxy>().ConfigureHttpClient(c => c.BaseAddress = new Uri(settings.Settings.PlexAutoscanUrl));
services.AddRefitClient<IRadarrProxy>().ConfigureHttpClient(c => c.BaseAddress = new Uri(settings.Settings.RadarrUrl));
services.AddRefitClient<ISonarrProxy>().ConfigureHttpClient(c => c.BaseAddress = new Uri(settings.Settings.SonarrUrl));
services.AddSingleton<IFolderMappingService, FolderMappingService>();
services.AddScoped<INotificationService<SonarrWebhookPayload>, SonarrService>();
services.AddScoped<INotificationService<RadarrWebhookPayload>, RadarrService>();
services.AddScoped<IDownloadProcesserService<RadarrWebhookPayload>, RadarrProcessorService>();
services.AddScoped<IDownloadProcesserService<SonarrWebhookPayload>, SonarrProcessorService>();
services.AddScoped<IDownloadProcesserService<ManualPayload>, ManualProcessorService>();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "ConversionProxy", Version = "v1" });
});
this.ConfigureHangfire(services);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, ISettingsService settingsService)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "ConversionProxy V1");
});
}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
loggerFactory.AddLog4Net();
app.UseMvc();
var options = new BackgroundJobServerOptions {
WorkerCount = settingsService.Settings.MaxConcurrentConversions
};
app.UseHangfireDashboard("/jobs", new DashboardOptions
{
Authorization = new [] { new AnonymousDashboardFilter() }
});
app.UseHangfireServer(options);
}
private void ConfigureHangfire(IServiceCollection services)
{
// Add Hangfire services.
services.AddHangfire(configuration => configuration
.SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseConsole()
.UseLiteDbStorage(Configuration[key: "ConnectionStrings:Database"])
);
}
}
}