Skip to content

Commit 12d2c92

Browse files
chore: format and clean up
1 parent 7fca527 commit 12d2c92

File tree

11 files changed

+173
-173
lines changed

11 files changed

+173
-173
lines changed

src/Nullinside.Api.Common.AspNetCore/Middleware/BasicAuthenticationHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync() {
7575
try {
7676
//auth logic
7777
List<Claim> claims = [
78-
new Claim(ClaimTypes.Email, dbUser.Email ?? string.Empty),
79-
new Claim(ClaimTypes.UserData, dbUser.Id.ToString())
78+
new(ClaimTypes.Email, dbUser.Email ?? string.Empty),
79+
new(ClaimTypes.UserData, dbUser.Id.ToString())
8080
];
8181

8282
if (null != dbUser.Roles) {

src/Nullinside.Api.Common.AspNetCore/Nullinside.Api.Common.AspNetCore.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2222
<PrivateAssets>all</PrivateAssets>
2323
</PackageReference>
24-
<PackageReference Include="Nullinside.MySql.EntityFrameworkCore" Version="9.0.3" />
25-
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.4" />
26-
<PackageReference Include="System.Text.Json" Version="9.0.6" />
24+
<PackageReference Include="Nullinside.MySql.EntityFrameworkCore" Version="9.0.3"/>
25+
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.4"/>
26+
<PackageReference Include="System.Text.Json" Version="9.0.6"/>
2727
</ItemGroup>
2828

2929
<ItemGroup>

src/Nullinside.Api.Common/Nullinside.Api.Common.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
</PropertyGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="log4net" Version="3.1.0" />
21-
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.6" />
20+
<PackageReference Include="log4net" Version="3.1.0"/>
21+
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.6"/>
2222
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
2323
<PackageReference Include="SSH.NET" Version="2025.0.0"/>
2424
<PackageReference Include="TwitchLib.Api" Version="3.9.0"/>

src/Nullinside.Api.Common/Twitch/TwitchClientProxy.cs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public class TwitchClientProxy : ITwitchClientProxy {
2929
/// </summary>
3030
private static TwitchClientProxy? instance;
3131

32+
/// <summary>
33+
/// The callback(s) to invoke when a channel receives a chat message.
34+
/// </summary>
35+
private readonly Dictionary<string, Action<OnMessageReceivedArgs>?> _onMessageReceived = new();
36+
3237
/// <summary>
3338
/// The list of chats we attempted to join with the bot.
3439
/// </summary>
@@ -39,42 +44,37 @@ public class TwitchClientProxy : ITwitchClientProxy {
3944
private readonly HashSet<string> joinedChannels;
4045

4146
/// <summary>
42-
/// A timer used to re-connect the Twitch chat client.
47+
/// The callback(s) to invoke when a channel is raided.
4348
/// </summary>
44-
private readonly Timer twitchChatClientReconnect;
49+
private readonly Dictionary<string, Action<OnRaidNotificationArgs>?> onRaid = new();
4550

4651
/// <summary>
47-
/// The lock to prevent mutual exclusion on the <see cref="client" /> object.
52+
/// The callback(s) to invoke when a channel receives a ban message.
4853
/// </summary>
49-
private readonly object twitchClientLock = new();
54+
private readonly Dictionary<string, Action<OnUserBannedArgs>?> onUserBanReceived = new();
5055

5156
/// <summary>
52-
/// The twitch client to send and receive messages with.
57+
/// A timer used to re-connect the Twitch chat client.
5358
/// </summary>
54-
private TwitchClient? client;
59+
private readonly Timer twitchChatClientReconnect;
5560

5661
/// <summary>
57-
/// The callback(s) to invoke when a channel receives a chat message.
62+
/// The lock to prevent mutual exclusion on the <see cref="client" /> object.
5863
/// </summary>
59-
private Dictionary<string, Action<OnMessageReceivedArgs>?> _onMessageReceived = new();
64+
private readonly object twitchClientLock = new();
6065

61-
/// <summary>
62-
/// The callback(s) to invoke when a channel is raided.
63-
/// </summary>
64-
private Dictionary<string, Action<OnRaidNotificationArgs>?> onRaid = new();
66+
private string? _twitchOAuthToken;
6567

6668
/// <summary>
67-
/// The callback(s) to invoke when a channel receives a ban message.
69+
/// The twitch client to send and receive messages with.
6870
/// </summary>
69-
private Dictionary<string, Action<OnUserBannedArgs>?> onUserBanReceived = new();
71+
private TwitchClient? client;
7072

7173
/// <summary>
7274
/// The web socket to connect to twitch chat with.
7375
/// </summary>
7476
private WebSocketClient? socket;
7577

76-
private string? _twitchOAuthToken;
77-
7878
/// <summary>
7979
/// Initializes a new instance of the <see cref="TwitchClientProxy" /> class.
8080
/// </summary>
@@ -109,7 +109,7 @@ public string? TwitchOAuthToken {
109109
get => _twitchOAuthToken;
110110
set {
111111
_twitchOAuthToken = value;
112-
112+
113113
// If we have a client, try to connect.
114114
if (null != client) {
115115
client.SetConnectionCredentials(new ConnectionCredentials(TwitchUsername, value));
@@ -169,7 +169,7 @@ public async Task<bool> SendMessage(string channel, string message, uint retryCo
169169
/// <inheritdoc />
170170
public async Task AddMessageCallback(string channel, Action<OnMessageReceivedArgs> callback) {
171171
await JoinChannel(channel);
172-
var channelSan = channel.ToLowerInvariant();
172+
string channelSan = channel.ToLowerInvariant();
173173
lock (_onMessageReceived) {
174174
if (!_onMessageReceived.TryAdd(channelSan, callback)) {
175175
_onMessageReceived[channelSan] += callback;
@@ -180,10 +180,10 @@ public async Task AddMessageCallback(string channel, Action<OnMessageReceivedArg
180180
/// <inheritdoc />
181181
public void RemoveMessageCallback(string channel, Action<OnMessageReceivedArgs> callback) {
182182
bool shouldRemove = false;
183-
var channelSan = channel.ToLowerInvariant();
183+
string channelSan = channel.ToLowerInvariant();
184184
lock (_onMessageReceived) {
185185
if (_onMessageReceived.ContainsKey(channelSan)) {
186-
var item = _onMessageReceived[channelSan];
186+
Action<OnMessageReceivedArgs>? item = _onMessageReceived[channelSan];
187187
item -= callback;
188188
if (null == item) {
189189
_onMessageReceived.Remove(channelSan);
@@ -196,7 +196,7 @@ public void RemoveMessageCallback(string channel, Action<OnMessageReceivedArgs>
196196

197197
if (shouldRemove) {
198198
client?.LeaveChannel(channelSan);
199-
199+
200200
// First add the channel to the master list.
201201
lock (joinedChannels) {
202202
joinedChannels.Add(channelSan);
@@ -257,7 +257,7 @@ private async Task<bool> JoinChannel(string channel) {
257257
if (!await Connect()) {
258258
return false;
259259
}
260-
260+
261261
try {
262262
// If we don't have a client, give up.
263263
if (null == client) {
@@ -407,11 +407,11 @@ private Task<bool> Connect() {
407407
/// <param name="e">The event arguments.</param>
408408
private void TwitchChatClient_OnRaidNotification(object? sender, OnRaidNotificationArgs e) {
409409
Action<OnRaidNotificationArgs>? callback;
410-
var channel = e.Channel.ToLowerInvariant();
410+
string channel = e.Channel.ToLowerInvariant();
411411
lock (onRaid) {
412412
onRaid.TryGetValue(channel, out callback);
413413
}
414-
414+
415415
Delegate[]? invokeList = callback?.GetInvocationList();
416416
if (null == invokeList) {
417417
return;
@@ -429,7 +429,7 @@ private void TwitchChatClient_OnRaidNotification(object? sender, OnRaidNotificat
429429
/// <param name="e">The event arguments.</param>
430430
private void TwitchChatClient_OnMessageReceived(object? sender, OnMessageReceivedArgs e) {
431431
Action<OnMessageReceivedArgs>? callbacks = null;
432-
var channelSan = e.ChatMessage.Channel.ToLowerInvariant();
432+
string channelSan = e.ChatMessage.Channel.ToLowerInvariant();
433433
lock (_onMessageReceived) {
434434
if (_onMessageReceived.TryGetValue(channelSan, out Action<OnMessageReceivedArgs>? messageReceivedCallback)) {
435435
callbacks = messageReceivedCallback;
@@ -457,11 +457,11 @@ private void TwitchChatClient_OnMessageReceived(object? sender, OnMessageReceive
457457
/// <param name="e">The event arguments.</param>
458458
private void TwitchChatClient_OnUserBanned(object? sender, OnUserBannedArgs e) {
459459
Action<OnUserBannedArgs>? callback;
460-
var channel = e.UserBan.Channel.ToLowerInvariant();
460+
string channel = e.UserBan.Channel.ToLowerInvariant();
461461
lock (onUserBanReceived) {
462462
onUserBanReceived.TryGetValue(channel, out callback);
463463
}
464-
464+
465465
Delegate[]? invokeList = callback?.GetInvocationList();
466466
if (null == invokeList) {
467467
return;

src/Nullinside.Api.Model/Nullinside.Api.Model.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
</PropertyGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.6" />
20+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.6"/>
2121
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.6">
2222
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2323
<PrivateAssets>all</PrivateAssets>
2424
</PackageReference>
25-
<PackageReference Include="Nullinside.MySql.EntityFrameworkCore" Version="9.0.3" />
26-
<PackageReference Include="System.Text.Json" Version="9.0.6" />
25+
<PackageReference Include="Nullinside.MySql.EntityFrameworkCore" Version="9.0.3"/>
26+
<PackageReference Include="System.Text.Json" Version="9.0.6"/>
2727
</ItemGroup>
2828

2929
<ItemGroup>

src/Nullinside.Api.Model/Shared/DatabaseLock.cs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,37 @@
55
namespace Nullinside.Api.Common;
66

77
/// <summary>
8-
/// Handles acquiring a lock at the database level.
8+
/// Handles acquiring a lock at the database level.
99
/// </summary>
1010
/// <remarks>Requires a transaction wrapping its functionality.</remarks>
1111
public class DatabaseLock : IDisposable {
1212
/// <summary>
13-
/// The database context.
13+
/// The database context.
1414
/// </summary>
15-
private INullinsideContext _mysqlDbContext;
15+
private readonly INullinsideContext _mysqlDbContext;
16+
1617
/// <summary>
17-
/// The lock name used on the previous lock.
18+
/// The lock name used on the previous lock.
1819
/// </summary>
1920
private string? _name;
20-
21+
2122
/// <summary>
22-
/// Initializes a new instance of the <see cref="DatabaseLock"/> class.
23+
/// Initializes a new instance of the <see cref="DatabaseLock" /> class.
2324
/// </summary>
2425
/// <param name="mysqlDbContext">The database context.</param>
2526
/// <exception cref="ArgumentNullException">Must provide parameter.</exception>
2627
public DatabaseLock(INullinsideContext mysqlDbContext) {
2728
_mysqlDbContext = mysqlDbContext ?? throw new ArgumentNullException(nameof(mysqlDbContext));
2829
}
2930

31+
/// <inheritdoc />
32+
public void Dispose() {
33+
Dispose(true);
34+
GC.SuppressFinalize(this);
35+
}
36+
3037
/// <summary>
31-
/// Acquires the lock.
38+
/// Acquires the lock.
3239
/// </summary>
3340
/// <remarks>Waits indefinitely.</remarks>
3441
/// <param name="name">The name of the lock. MUST BE A HARD CODED VALUE</param>
@@ -38,55 +45,49 @@ public DatabaseLock(INullinsideContext mysqlDbContext) {
3845
if (string.IsNullOrWhiteSpace(name)) {
3946
return false;
4047
}
41-
48+
4249
// This is only used with hard coded names.
4350
#pragma warning disable EF1002
44-
await _mysqlDbContext.Database.ExecuteSqlRawAsync($"SELECT GET_LOCK('{name}', -1)", cancellationToken: cancellationToken);
51+
await _mysqlDbContext.Database.ExecuteSqlRawAsync($"SELECT GET_LOCK('{name}', -1)", cancellationToken);
4552
#pragma warning restore EF1002
4653
_name = name;
4754
return true;
4855
}
49-
56+
5057
/// <summary>
51-
/// Releases the lock.
58+
/// Releases the lock.
5259
/// </summary>
5360
/// <param name="name">The name of the lock. MUST BE A HARD CODED VALUE</param>
5461
/// <param name="cancellationToken">The cancellation token.</param>
5562
public async Task ReleaseLock(string name, CancellationToken cancellationToken = new()) {
5663
if (!string.IsNullOrWhiteSpace(name) && !name.Equals(_name, StringComparison.InvariantCultureIgnoreCase)) {
5764
// This is only used with hard coded names.
5865
#pragma warning disable EF1002
59-
await _mysqlDbContext.Database.ExecuteSqlRawAsync($"SELECT RELEASE_LOCK('{_name}')", cancellationToken: cancellationToken);
66+
await _mysqlDbContext.Database.ExecuteSqlRawAsync($"SELECT RELEASE_LOCK('{_name}')", cancellationToken);
6067
#pragma warning restore EF1002
6168
}
62-
69+
6370
// This is only used with hard coded names.
6471
#pragma warning disable EF1002
65-
await _mysqlDbContext.Database.ExecuteSqlRawAsync($"SELECT RELEASE_LOCK('{name}')", cancellationToken: cancellationToken);
72+
await _mysqlDbContext.Database.ExecuteSqlRawAsync($"SELECT RELEASE_LOCK('{name}')", cancellationToken);
6673
#pragma warning restore EF1002
6774
_name = null;
6875
}
6976

7077
/// <summary>
71-
/// Disposes of resources.
78+
/// Disposes of resources.
7279
/// </summary>
7380
/// <param name="disposing">True if dispose called, false if finalizer.</param>
7481
protected virtual void Dispose(bool disposing) {
7582
if (disposing) {
7683
if (!string.IsNullOrWhiteSpace(_name)) {
77-
Task.WaitAll(this.ReleaseLock(_name));
84+
Task.WaitAll(ReleaseLock(_name));
7885
}
7986
}
8087
}
8188

82-
/// <inheritdoc />
83-
public void Dispose() {
84-
Dispose(true);
85-
GC.SuppressFinalize(this);
86-
}
87-
8889
/// <summary>
89-
/// Finalizes instance of the <see cref="DatabaseLock"/> class.
90+
/// Finalizes instance of the <see cref="DatabaseLock" /> class.
9091
/// </summary>
9192
~DatabaseLock() {
9293
Dispose(false);

src/Nullinside.Api.Model/Shared/UserHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static class UserHelpers {
3131
if (null == existing && !string.IsNullOrWhiteSpace(twitchUsername)) {
3232
existing = await dbContext.Users.FirstOrDefaultAsync(u => u.TwitchUsername == twitchUsername && !u.IsBanned, token);
3333
}
34-
34+
3535
if (null == existing) {
3636
dbContext.Users.Add(new User {
3737
Email = email,

src/Nullinside.Api.Tests/Nullinside.Api.Tests.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
</PropertyGroup>
1616

1717
<ItemGroup>
18-
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.6" />
19-
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.6" />
20-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
18+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.6"/>
19+
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.6"/>
20+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1"/>
2121
<PackageReference Include="Moq" Version="4.20.72"/>
22-
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
23-
<PackageReference Include="NUnit" Version="4.3.2" />
24-
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
22+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
23+
<PackageReference Include="NUnit" Version="4.3.2"/>
24+
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0"/>
2525
<PackageReference Include="NUnit.Analyzers" Version="4.8.1">
2626
<PrivateAssets>all</PrivateAssets>
2727
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

0 commit comments

Comments
 (0)