-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
151 lines (128 loc) · 6.27 KB
/
Program.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System.Configuration;
using LivestreamRecorderService.DependencyInjection;
using LivestreamRecorderService.Enums;
using LivestreamRecorderService.Interfaces;
using LivestreamRecorderService.Models.Options;
using LivestreamRecorderService.ScopedServices;
using LivestreamRecorderService.ScopedServices.PlatformService;
using LivestreamRecorderService.SingletonServices;
using LivestreamRecorderService.SingletonServices.Downloader;
using LivestreamRecorderService.Workers;
using Microsoft.Extensions.Options;
using Serilog;
// ReSharper disable SwitchStatementHandlesSomeKnownEnumValuesWithDefault
#if !RELEASE
using Serilog.Debugging;
SelfLog.Enable(Console.WriteLine);
#endif
IConfiguration configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
#if !RELEASE
.AddJsonFile("appsettings.Development.json", optional: true, reloadOnChange: true)
.AddUserSecrets<Program>(optional: true, reloadOnChange: true)
#endif
.AddEnvironmentVariables()
.Build();
Log.Logger = new LoggerConfiguration().ReadFrom.Configuration(configuration)
.Enrich.WithMachineName()
.Enrich.FromLogContext()
.CreateLogger();
Log.Information("Starting up...");
try
{
IHostBuilder hostBuilder =
Host.CreateDefaultBuilder(args)
.UseSerilog()
.ConfigureServices((context, services) =>
{
configuration = context.Configuration;
services.AddHttpClient();
services.AddOptions<AzureOption>()
.Bind(configuration.GetSection(AzureOption.ConfigurationSectionName))
.ValidateDataAnnotations()
.ValidateOnStart();
services.AddOptions<S3Option>()
.Bind(configuration.GetSection(S3Option.ConfigurationSectionName))
.ValidateDataAnnotations()
.ValidateOnStart();
services.AddOptions<ServiceOption>()
.Bind(configuration.GetSection(ServiceOption.ConfigurationSectionName))
.ValidateDataAnnotations()
.ValidateOnStart();
services.AddOptions<CouchDbOption>()
.Bind(configuration.GetSection(CouchDbOption.ConfigurationSectionName))
.ValidateDataAnnotations()
.ValidateOnStart();
ServiceOption serviceOptions = services.BuildServiceProvider()
.GetRequiredService<IOptions<ServiceOption>>()
.Value;
switch (serviceOptions.JobService)
{
case ServiceName.AzureContainerInstance:
services.AddAzureContainerInstanceService();
break;
case ServiceName.Kubernetes:
services.AddKubernetesService(configuration);
break;
default:
Log.Fatal("Job Service is limited to Azure Container Instance, Kubernetes.");
throw new ConfigurationErrorsException(
"Job Service is limited to Azure Container Instance, Kubernetes.");
}
switch (serviceOptions.StorageService)
{
case ServiceName.AzureBlobStorage:
services.AddAzureBlobStorageService();
break;
case ServiceName.S3:
services.AddS3StorageService();
break;
default:
Log.Fatal("Storage Service is limited to Azure Blob Storage or S3.");
throw new ConfigurationErrorsException("Storage Service is limited to Azure Blob Storage or S3.");
}
switch (serviceOptions.DatabaseService)
{
case ServiceName.AzureCosmosDB:
services.AddCosmosDb(configuration);
break;
case ServiceName.ApacheCouchDB:
services.AddCouchDb(configuration);
break;
default:
Log.Fatal("Database Service is limited to Azure CosmosDB or Apache CouchDB.");
throw new ConfigurationErrorsException("Database Service is limited to Azure CosmosDB or Apache CouchDB.");
}
services.AddDiscordService(configuration);
services.AddSingleton<IYtarchiveService, YtarchiveService>();
services.AddSingleton<IYtdlpService, YtdlpService>();
services.AddSingleton<IStreamlinkService, StreamlinkService>();
services.AddSingleton<ITwitcastingRecorderService, TwitcastingRecorderService>();
services.AddSingleton<IFc2LiveDLService, Fc2LiveDLService>();
services.AddSingleton<IUploaderService, UploaderService>();
services.AddHostedService<MonitorWorker>();
services.AddHostedService<RecordWorker>();
services.AddSingleton<RecordService>();
services.AddHostedService<UpdateChannelInfoWorker>();
services.AddHostedService<UpdateVideoStatusWorker>();
services.AddHeartbeatWorker(configuration);
services.AddScoped<VideoService>();
services.AddScoped<ChannelService>();
services.AddScoped<RssService>();
services.AddScoped<YoutubeService>();
services.AddScoped<TwitcastingService>();
services.AddTwitchService(configuration);
services.AddScoped<Fc2Service>();
});
IHost host = hostBuilder.Build();
host.Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Unhandled exception");
}
finally
{
Log.Information("Shut down complete");
Log.CloseAndFlush();
}