Skip to content

Commit d199e5b

Browse files
committed
refactor: refactoring with Resharper
Signed-off-by: 陳鈞 <[email protected]>
1 parent c99ca02 commit d199e5b

File tree

74 files changed

+1833
-1608
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1833
-1608
lines changed

.editorconfig

Lines changed: 20 additions & 55 deletions
Large diffs are not rendered by default.

DependencyInjection/AddAzureBlobStorageService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static IServiceCollection AddAzureBlobStorageService(this IServiceCollect
1414
{
1515
try
1616
{
17-
var azureOptions = services.BuildServiceProvider().GetRequiredService<IOptions<AzureOption>>().Value;
17+
AzureOption azureOptions = services.BuildServiceProvider().GetRequiredService<IOptions<AzureOption>>().Value;
1818
if (null == azureOptions.BlobStorage
1919
|| string.IsNullOrEmpty(azureOptions.BlobStorage.StorageAccountName)
2020
|| string.IsNullOrEmpty(azureOptions.BlobStorage.StorageAccountKey)
@@ -25,7 +25,7 @@ public static IServiceCollection AddAzureBlobStorageService(this IServiceCollect
2525
services.AddAzureClients(clientsBuilder
2626
=> clientsBuilder.AddBlobServiceClient(azureOptions.BlobStorage.ConnectionString));
2727

28-
services.AddSingleton<IStorageService, ABSService>();
28+
services.AddSingleton<IStorageService, AbsService>();
2929

3030
return services;
3131
}

DependencyInjection/AddAzureContainerInstanceService.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,28 @@ public static IServiceCollection AddAzureContainerInstanceService(this IServiceC
2020
{
2121
try
2222
{
23-
var azureOptions = services.BuildServiceProvider().GetRequiredService<IOptions<AzureOption>>().Value;
23+
AzureOption azureOptions = services.BuildServiceProvider().GetRequiredService<IOptions<AzureOption>>().Value;
2424
if (null == azureOptions.ContainerInstance
2525
|| string.IsNullOrEmpty(azureOptions.ContainerInstance.ClientSecret.ClientID)
2626
|| string.IsNullOrEmpty(azureOptions.ContainerInstance.ClientSecret.ClientSecret))
2727
throw new ConfigurationErrorsException();
2828

2929
services.AddAzureClients(clientsBuilder
30-
=> clientsBuilder.UseCredential((options)
31-
=> new ClientSecretCredential(tenantId: azureOptions.ContainerInstance.ClientSecret.TenantID,
32-
clientId: azureOptions.ContainerInstance.ClientSecret.ClientID,
33-
clientSecret: azureOptions.ContainerInstance.ClientSecret.ClientSecret))
34-
.AddClient<ArmClient, ArmClientOptions>((options, token) => new ArmClient(token)));
30+
=> clientsBuilder.UseCredential((_)
31+
=> new ClientSecretCredential(
32+
tenantId: azureOptions.ContainerInstance.ClientSecret.TenantID,
33+
clientId: azureOptions.ContainerInstance.ClientSecret.ClientID,
34+
clientSecret: azureOptions.ContainerInstance.ClientSecret
35+
.ClientSecret))
36+
.AddClient<ArmClient, ArmClientOptions>((_, token) => new ArmClient(token)));
3537

36-
services.AddSingleton<IJobService, ACIService>();
38+
services.AddSingleton<IJobService, AciService>();
3739

3840
services.AddSingleton<IYtarchiveService, YtarchiveService>();
3941
services.AddSingleton<IYtdlpService, YtdlpService>();
4042
services.AddSingleton<IStreamlinkService, StreamlinkService>();
4143
services.AddSingleton<ITwitcastingRecorderService, TwitcastingRecorderService>();
42-
services.AddSingleton<IFC2LiveDLService, FC2LiveDLService>();
44+
services.AddSingleton<IFc2LiveDLService, Fc2LiveDLService>();
4345

4446
services.AddSingleton<IAzureUploaderService, AzureUploaderService>();
4547
services.AddSingleton<IS3UploaderService, S3UploaderService>();

DependencyInjection/AddCosmosDb.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace LivestreamRecorderService.DependencyInjection;
1313

1414
public static partial class Extensions
1515
{
16-
public static IServiceCollection AddCosmosDB(this IServiceCollection services, IConfiguration configuration)
16+
public static IServiceCollection AddCosmosDb(this IServiceCollection services, IConfiguration configuration)
1717
{
1818
#if !COSMOSDB
1919
Log.Fatal("This is a CouchDB build. Please use the CosmosDB build for Azure CosmosDB support.");
@@ -36,18 +36,19 @@ public static IServiceCollection AddCosmosDB(this IServiceCollection services, I
3636
.EnableSensitiveDataLogging()
3737
#endif
3838
.UseCosmos(connectionString: azureOptions.CosmosDB.Public.ConnectionStrings,
39-
databaseName: azureOptions.CosmosDB.Public.DatabaseName,
40-
cosmosOptionsAction: option => option.GatewayModeMaxConnectionLimit(380));
39+
databaseName: azureOptions.CosmosDB.Public.DatabaseName,
40+
cosmosOptionsAction: option => option.GatewayModeMaxConnectionLimit(380));
4141
});
42+
4243
services.AddDbContext<PrivateContext>((options) =>
4344
{
4445
options
4546
#if !RELEASE
4647
.EnableSensitiveDataLogging()
4748
#endif
4849
.UseCosmos(connectionString: azureOptions.CosmosDB.Private.ConnectionStrings,
49-
databaseName: azureOptions.CosmosDB.Private.DatabaseName,
50-
cosmosOptionsAction: option => option.GatewayModeMaxConnectionLimit(380));
50+
databaseName: azureOptions.CosmosDB.Private.DatabaseName,
51+
cosmosOptionsAction: option => option.GatewayModeMaxConnectionLimit(380));
5152
});
5253

5354
services.AddScoped<UnitOfWork_Public>();

DependencyInjection/AddCouchDb.cs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,55 +7,60 @@
77
using LivestreamRecorderService.Models.Options;
88
using Microsoft.Extensions.Options;
99
using System.Configuration;
10+
using Flurl.Http.Configuration;
1011
#endif
1112
using Serilog;
12-
using Flurl.Http.Configuration;
1313

1414
namespace LivestreamRecorderService.DependencyInjection;
1515

1616
public static partial class Extensions
1717
{
18-
public static IServiceCollection AddCouchDB(this IServiceCollection services, IConfiguration configuration)
18+
public static IServiceCollection AddCouchDb(this IServiceCollection services, IConfiguration configuration)
1919
{
2020
#if !COUCHDB
2121
Log.Fatal("This is a CosmosDB build. Please use the CouchDB build for Apache CouchDB support.");
2222
throw new InvalidOperationException("This is a CosmosDB build. Please use the CouchDB build for Apache CouchDB support.");
2323
#else
2424
try
2525
{
26-
var couchDBOptions = services.BuildServiceProvider().GetRequiredService<IOptions<CouchDBOption>>().Value;
26+
CouchDbOption? couchDbOptions = services.BuildServiceProvider().GetRequiredService<IOptions<CouchDbOption>>().Value;
2727

28-
if (null == couchDBOptions
29-
|| string.IsNullOrEmpty(couchDBOptions.Endpoint)
30-
|| string.IsNullOrEmpty(couchDBOptions.Username)
31-
|| string.IsNullOrEmpty(couchDBOptions.Password))
28+
if (null == couchDbOptions
29+
|| string.IsNullOrEmpty(couchDbOptions.Endpoint)
30+
|| string.IsNullOrEmpty(couchDbOptions.Username)
31+
|| string.IsNullOrEmpty(couchDbOptions.Password))
3232
throw new ConfigurationErrorsException();
3333

34-
services.AddSingleton<CouchDBHttpClientFactory>();
34+
services.AddSingleton<CouchDbHttpClientFactory>();
3535

3636
// https://github.com/matteobortolazzo/couchdb-net#dependency-injection
3737
services.AddCouchContext<CouchDBContext>((options) =>
3838
{
3939
options
40-
.UseEndpoint(couchDBOptions.Endpoint)
41-
.UseCookieAuthentication(username: couchDBOptions.Username, password: couchDBOptions.Password)
40+
.UseEndpoint(couchDbOptions.Endpoint)
41+
.UseCookieAuthentication(username: couchDbOptions.Username, password: couchDbOptions.Password)
4242
.ConfigureFlurlClient(setting =>
4343
{
4444
// Always use the same HttpClient instance to optimize resource usage and performance.
45-
setting.HttpClientFactory = services.BuildServiceProvider().GetRequiredService<CouchDBHttpClientFactory>();
45+
setting.HttpClientFactory = services.BuildServiceProvider().GetRequiredService<CouchDbHttpClientFactory>();
4646
#if !RELEASE
4747
setting.BeforeCall = call
4848
=> Log.Debug("Sending request to couch: {request} {body}", call, call.RequestBody);
49+
4950
setting.AfterCallAsync = call => Task.Run(() =>
5051
{
5152
if (call.Succeeded)
5253
{
53-
Log.Debug("Received response from couch: {response} {body}", call, call.Response.ResponseMessage.Content.ReadAsStringAsync().Result);
54+
Log.Debug("Received response from couch: {response} {body}",
55+
call,
56+
call.Response.ResponseMessage.Content.ReadAsStringAsync().Result);
5457
}
5558
});
5659
#endif
5760
setting.OnErrorAsync = call => Task.Run(()
58-
=> Log.Error("Request Failed: {request} {body}", call, call?.RequestBody ?? string.Empty));
61+
=> Log.Error("Request Failed: {request} {body}",
62+
call,
63+
call?.RequestBody ?? string.Empty));
5964
})
6065
.SetPropertyCase(PropertyCaseType.None);
6166
});
@@ -73,22 +78,25 @@ public static IServiceCollection AddCouchDB(this IServiceCollection services, IC
7378
catch (ConfigurationErrorsException)
7479
{
7580
Log.Fatal("Missing CouchDB Settings. Please set CouchDB:Endpoint CouchDB:Username CouchDB:Password in appsettings.json.");
76-
throw new ConfigurationErrorsException("Missing CouchDB Settings. Please set CouchDB:Endpoint CouchDB:Username CouchDB:Password in appsettings.json.");
81+
throw new ConfigurationErrorsException(
82+
"Missing CouchDB Settings. Please set CouchDB:Endpoint CouchDB:Username CouchDB:Password in appsettings.json.");
7783
}
7884
#endif
7985
}
8086

87+
#if COUCHDB
8188
/// <summary>
8289
/// Custom HTTP client factory for CouchDB interactions.
8390
/// </summary>
8491
/// <remarks>
8592
/// This factory provides a globally shared instance of HttpClient to optimize resource usage and performance.
8693
/// </remarks>
87-
private class CouchDBHttpClientFactory : DefaultHttpClientFactory
94+
private class CouchDbHttpClientFactory : DefaultHttpClientFactory
8895
{
8996
private static HttpClient? _httpClient;
9097

9198
public override HttpClient CreateHttpClient(HttpMessageHandler handler)
9299
=> _httpClient ??= base.CreateHttpClient(handler);
93100
}
101+
#endif
94102
}

DependencyInjection/AddDiscordService.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using LivestreamRecorderService.Models.OptionDiscords;
2-
using LivestreamRecorderService.SingletonServices;
1+
using LivestreamRecorderService.SingletonServices;
32
using Serilog;
43
using System.Configuration;
4+
using LivestreamRecorderService.Models.Options;
55

66
namespace LivestreamRecorderService.DependencyInjection;
77

@@ -12,7 +12,7 @@ public static IServiceCollection AddDiscordService(this IServiceCollection servi
1212
try
1313
{
1414
IConfigurationSection config = configuration.GetSection(DiscordOption.ConfigurationSectionName);
15-
var discordOptions = config.Get<DiscordOption>();
15+
DiscordOption? discordOptions = config.Get<DiscordOption>();
1616
if (null == discordOptions) throw new ConfigurationErrorsException();
1717

1818
services.AddOptions<DiscordOption>()
@@ -31,15 +31,18 @@ public static IServiceCollection AddDiscordService(this IServiceCollection servi
3131
|| string.IsNullOrEmpty(discordOptions.FrontEndHost)
3232
|| null == discordOptions.Mention
3333
|| null == discordOptions.Emotes
34-
) throw new ConfigurationErrorsException();
34+
) throw new ConfigurationErrorsException();
3535

3636
services.AddSingleton<DiscordService>();
3737
return services;
3838
}
3939
catch (ConfigurationErrorsException)
4040
{
41-
Log.Fatal("Missing Discord Settings. Please set Discord:Enabled Discord:Webhook, Discord:WebhookWarning, Discord:WebhookAdmin, Discord:FrontEndHost, Discord:Mention and Discord:Emotes in appsettings.json.");
42-
throw new ConfigurationErrorsException("Missing Discord Settings. Please set Discord:Enabled Discord:Webhook, Discord:WebhookWarning, Discord:WebhookAdmin, Discord:FrontEndHost, Discord:Mention and Discord:Emotes in appsettings.json.");
41+
Log.Fatal(
42+
"Missing Discord Settings. Please set Discord:Enabled Discord:Webhook, Discord:WebhookWarning, Discord:WebhookAdmin, Discord:FrontEndHost, Discord:Mention and Discord:Emotes in appsettings.json.");
43+
44+
throw new ConfigurationErrorsException(
45+
"Missing Discord Settings. Please set Discord:Enabled Discord:Webhook, Discord:WebhookWarning, Discord:WebhookAdmin, Discord:FrontEndHost, Discord:Mention and Discord:Emotes in appsettings.json.");
4346
}
4447
}
4548
}

DependencyInjection/AddHeartbeatWorker.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static IServiceCollection AddHeartbeatWorker(this IServiceCollection serv
1212
try
1313
{
1414
IConfigurationSection config = configuration.GetSection(HeartbeatOption.ConfigurationSectionName);
15-
var heartbeatOptions = config.Get<HeartbeatOption>();
15+
HeartbeatOption? heartbeatOptions = config.Get<HeartbeatOption>();
1616
if (null == heartbeatOptions) throw new ConfigurationErrorsException();
1717

1818
services.AddOptions<HeartbeatOption>()
@@ -31,7 +31,8 @@ public static IServiceCollection AddHeartbeatWorker(this IServiceCollection serv
3131
catch (ConfigurationErrorsException)
3232
{
3333
Log.Fatal("Missing Twitch ClientId or ClientSecret. Please set Twitch:ClientId and Twitch:ClientSecret in appsettings.json.");
34-
throw new ConfigurationErrorsException("Missing Twitch ClientId or ClientSecret. Please set Twitch:ClientId and Twitch:ClientSecret in appsettings.json.");
34+
throw new ConfigurationErrorsException(
35+
"Missing Twitch ClientId or ClientSecret. Please set Twitch:ClientId and Twitch:ClientSecret in appsettings.json.");
3536
}
3637
}
3738
}

DependencyInjection/AddKubernetesService.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,44 @@ public static IServiceCollection AddKubernetesService(this IServiceCollection se
1919
{
2020
try
2121
{
22-
var serviceOptions = services.BuildServiceProvider().GetRequiredService<IOptions<ServiceOption>>().Value;
22+
ServiceOption serviceOptions = services.BuildServiceProvider().GetRequiredService<IOptions<ServiceOption>>().Value;
2323

2424
if (serviceOptions.JobService != ServiceName.Kubernetes)
2525
{
2626
return services;
2727
}
2828

2929
IConfigurationSection config = configuration.GetSection(KubernetesOption.ConfigurationSectionName);
30-
var kubernetesOptions = config.Get<KubernetesOption>();
30+
KubernetesOption? kubernetesOptions = config.Get<KubernetesOption>();
3131
if (null == kubernetesOptions) throw new ConfigurationErrorsException();
3232

3333
services.AddOptions<KubernetesOption>()
3434
.Bind(config)
3535
.ValidateDataAnnotations()
3636
.ValidateOnStart();
3737

38-
KubernetesClientConfiguration k8sConfig =
38+
KubernetesClientConfiguration k8SConfig =
3939
// skipcq: CS-R1114
4040
kubernetesOptions.UseTheSameCluster
41-
? KubernetesClientConfiguration.InClusterConfig()
42-
: !string.IsNullOrWhiteSpace(kubernetesOptions.ConfigFile)
43-
? KubernetesClientConfiguration.BuildConfigFromConfigFile(kubernetesOptions.ConfigFile)
44-
: KubernetesClientConfiguration.BuildDefaultConfig();
45-
var client = new Kubernetes(k8sConfig);
46-
services.AddSingleton<Kubernetes>(client);
41+
? KubernetesClientConfiguration.InClusterConfig()
42+
: !string.IsNullOrWhiteSpace(kubernetesOptions.ConfigFile)
43+
? KubernetesClientConfiguration.BuildConfigFromConfigFile(kubernetesOptions.ConfigFile)
44+
: KubernetesClientConfiguration.BuildDefaultConfig();
45+
46+
var client = new Kubernetes(k8SConfig);
47+
services.AddSingleton(client);
4748

4849
services.AddSingleton<IJobService, KubernetesService>();
4950

5051
KubernetesService.KubernetesNamespace = string.IsNullOrWhiteSpace(kubernetesOptions.Namespace)
51-
? "recordermoe"
52-
: kubernetesOptions.Namespace;
52+
? "recordermoe"
53+
: kubernetesOptions.Namespace;
5354

5455
services.AddSingleton<IYtarchiveService, YtarchiveService>();
5556
services.AddSingleton<IYtdlpService, YtdlpService>();
5657
services.AddSingleton<IStreamlinkService, StreamlinkService>();
5758
services.AddSingleton<ITwitcastingRecorderService, TwitcastingRecorderService>();
58-
services.AddSingleton<IFC2LiveDLService, FC2LiveDLService>();
59+
services.AddSingleton<IFc2LiveDLService, Fc2LiveDLService>();
5960

6061
services.AddSingleton<IAzureUploaderService, AzureUploaderService>();
6162
services.AddSingleton<IS3UploaderService, S3UploaderService>();

DependencyInjection/AddS3StorageService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ public static IServiceCollection AddS3StorageService(this IServiceCollection ser
1414
{
1515
try
1616
{
17-
var s3Options = services.BuildServiceProvider().GetRequiredService<IOptions<S3Option>>().Value;
17+
S3Option s3Options = services.BuildServiceProvider().GetRequiredService<IOptions<S3Option>>().Value;
1818
if (string.IsNullOrEmpty(s3Options.Endpoint)
1919
|| string.IsNullOrEmpty(s3Options.AccessKey)
2020
|| string.IsNullOrEmpty(s3Options.SecretKey)
2121
|| string.IsNullOrEmpty(s3Options.BucketName_Public)
2222
|| string.IsNullOrEmpty(s3Options.BucketName_Private))
2323
throw new ConfigurationErrorsException();
2424

25-
var minio = new MinioClient().WithEndpoint(s3Options.Endpoint)
26-
.WithCredentials(s3Options.AccessKey, s3Options.SecretKey)
27-
.WithSSL(s3Options.Secure)
28-
.Build();
25+
IMinioClient? minio = new MinioClient().WithEndpoint(s3Options.Endpoint)
26+
.WithCredentials(s3Options.AccessKey, s3Options.SecretKey)
27+
.WithSSL(s3Options.Secure)
28+
.Build();
2929

3030
services.AddSingleton(minio);
3131
services.AddSingleton<IStorageService, S3Service>();

0 commit comments

Comments
 (0)