Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync() {
.AsNoTracking()
.FirstOrDefaultAsync(u => !string.IsNullOrWhiteSpace(u.Token) &&
u.Token == token &&
!u.IsBanned);
!u.IsBanned).ConfigureAwait(false);

if (null == dbUser) {
return AuthenticateResult.Fail("Invalid token");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<wpf:ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xml:space="preserve">
<s:String x:Key="/Default/CodeInspection/Daemon/ConfigureAwaitAnalysisMode/@EntryValue">Library</s:String></wpf:ResourceDictionary>
14 changes: 7 additions & 7 deletions src/Nullinside.Api.Common/Docker/DockerProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class DockerProxy : IDockerProxy {
/// <inheritdoc />
public async Task<IEnumerable<DockerResource>> GetContainers(CancellationToken cancellationToken) {
(string output, string error) response =
await ExecuteCommand("docker container ls -a --format '{{.Names}}|{{.Status}}'", cancellationToken);
await ExecuteCommand("docker container ls -a --format '{{.Names}}|{{.Status}}'", cancellationToken).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(response.output)) {
return Enumerable.Empty<DockerResource>();
}
Expand Down Expand Up @@ -69,7 +69,7 @@ public async Task<IEnumerable<DockerResource>> GetContainers(CancellationToken c
/// <inheritdoc />
public async Task<IEnumerable<DockerResource>> GetDockerComposeProjects(CancellationToken cancellationToken) {
(string output, string error) responseJson =
await ExecuteCommand("docker compose ls -a --format 'json'", cancellationToken);
await ExecuteCommand("docker compose ls -a --format 'json'", cancellationToken).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(responseJson.output)) {
return Enumerable.Empty<DockerResource>();
}
Expand All @@ -89,7 +89,7 @@ public async Task<IEnumerable<DockerResource>> GetDockerComposeProjects(Cancella
public async Task<bool> TurnOnOffDockerContainer(string name, bool turnOn, CancellationToken cancellationToken) {
string command = turnOn ? "start" : "stop";
(string output, string error) responseJson =
await ExecuteCommand($"docker container {command} {name}", cancellationToken);
await ExecuteCommand($"docker container {command} {name}", cancellationToken).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(responseJson.error)) {
return false;
}
Expand All @@ -101,11 +101,11 @@ public async Task<bool> TurnOnOffDockerContainer(string name, bool turnOn, Cance
/// <inheritdoc />
public async Task<bool> TurnOnOffDockerCompose(string name, bool turnOn, CancellationToken cancellationToken,
string? backupFolder) {
IEnumerable<DockerResource> existing = await GetDockerComposeProjects(cancellationToken);
IEnumerable<DockerResource> existing = await GetDockerComposeProjects(cancellationToken).ConfigureAwait(false);
if (null != existing.FirstOrDefault(e => name.Equals(e.Name))) {
string command = turnOn ? "start" : "stop";
(string output, string error) stdout =
await ExecuteCommand($"docker compose -p {name} {command}", cancellationToken);
await ExecuteCommand($"docker compose -p {name} {command}", cancellationToken).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(stdout.error)) {
return false;
}
Expand All @@ -119,7 +119,7 @@ public async Task<bool> TurnOnOffDockerCompose(string name, bool turnOn, Cancell
}

(string output, string error)
output = await ExecuteCommand("docker compose up -d", cancellationToken, backupFolder);
output = await ExecuteCommand("docker compose up -d", cancellationToken, backupFolder).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(output.error)) {
return false;
}
Expand All @@ -138,7 +138,7 @@ public async Task<bool> TurnOnOffDockerCompose(string name, bool turnOn, Cancell
private async Task<(string output, string error)> ExecuteCommand(string command, CancellationToken token = new(),
string? dir = null) {
using SshClient client = new(_server!, _username!, _password!);
await client.ConnectAsync(token);
await client.ConnectAsync(token).ConfigureAwait(false);
using SshCommand? responseJson = client.RunCommand($"cd {dir}; echo {_password2} | sudo -S {command}");
return (responseJson.Result, responseJson.Error);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Nullinside.Api.Common/Extensions/WebSocketExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static class WebSocketExtensions {
/// <param name="message">The message to send.</param>
/// <param name="cancelToken">The cancellation token.</param>
public static async Task SendTextAsync(this WebSocket webSocket, string message, CancellationToken cancelToken = new()) {
await webSocket.SendAsync(Encoding.ASCII.GetBytes(message), WebSocketMessageType.Text, true, cancelToken);
await webSocket.SendAsync(Encoding.ASCII.GetBytes(message), WebSocketMessageType.Text, true, cancelToken).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -29,7 +29,7 @@ public static class WebSocketExtensions {

do {
var data = new ArraySegment<byte>(new byte[1024]);
response = await webSocket.ReceiveAsync(data, cancelToken);
response = await webSocket.ReceiveAsync(data, cancelToken).ConfigureAwait(false);
fullMessage.AddRange(data);
} while (null == response.CloseStatus && !response.EndOfMessage);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<wpf:ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xml:space="preserve">
<s:String x:Key="/Default/CodeInspection/Daemon/ConfigureAwaitAnalysisMode/@EntryValue">Library</s:String></wpf:ResourceDictionary>
4 changes: 2 additions & 2 deletions src/Nullinside.Api.Common/Retry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public static class Retry {
Exception? exceptionToThrow = null;
while (tries <= numberOfRetries && !token.IsCancellationRequested) {
try {
return await action();
return await action().ConfigureAwait(false);
}
catch (Exception ex) {
exceptionToThrow = ex;
++tries;

// Why did I do as delay THEN method? Honestly...I don't have a good reason. You can change it if you want, just
// update the documentation if you do.
await Task.Delay(waitTime.HasValue ? (int)waitTime.Value.TotalMilliseconds : 1000, token);
await Task.Delay(waitTime.HasValue ? (int)waitTime.Value.TotalMilliseconds : 1000, token).ConfigureAwait(false);
if (null != runOnFailure) {
runOnFailure(ex);
}
Expand Down
42 changes: 21 additions & 21 deletions src/Nullinside.Api.Common/Twitch/TwitchApiProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public TwitchApiProxy(string token, string refreshToken, DateTime tokenExpires,
public virtual async Task<TwitchAccessToken?> CreateAccessToken(string code, CancellationToken token = new()) {
ITwitchAPI api = GetApi();
AuthCodeResponse? response = await api.Auth.GetAccessTokenFromCodeAsync(code, TwitchAppConfig?.ClientSecret,
TwitchAppConfig?.ClientRedirect);
TwitchAppConfig?.ClientRedirect).ConfigureAwait(false);
if (null == response) {
return null;
}
Expand All @@ -109,7 +109,7 @@ public TwitchApiProxy(string token, string refreshToken, DateTime tokenExpires,
}

ITwitchAPI api = GetApi();
RefreshResponse? response = await api.Auth.RefreshAuthTokenAsync(OAuth?.RefreshToken, TwitchAppConfig?.ClientSecret, TwitchAppConfig?.ClientId);
RefreshResponse? response = await api.Auth.RefreshAuthTokenAsync(OAuth?.RefreshToken, TwitchAppConfig?.ClientSecret, TwitchAppConfig?.ClientId).ConfigureAwait(false);
if (null == response) {
return null;
}
Expand All @@ -129,7 +129,7 @@ public TwitchApiProxy(string token, string refreshToken, DateTime tokenExpires,
/// <inheritdoc />
public async Task<bool> GetAccessTokenIsValid(CancellationToken token = new()) {
try {
return !string.IsNullOrWhiteSpace((await GetUser(token))?.Id);
return !string.IsNullOrWhiteSpace((await GetUser(token).ConfigureAwait(false))?.Id);
}
catch {
return false;
Expand All @@ -140,40 +140,40 @@ public TwitchApiProxy(string token, string refreshToken, DateTime tokenExpires,
public virtual async Task<User?> GetUser(CancellationToken token = new()) {
return await Retry.Execute(async () => {
ITwitchAPI api = GetApi();
GetUsersResponse? response = await api.Helix.Users.GetUsersAsync();
GetUsersResponse? response = await api.Helix.Users.GetUsersAsync().ConfigureAwait(false);
if (null == response) {
return null;
}

return response.Users.FirstOrDefault();
}, Retries, token);
}, Retries, token).ConfigureAwait(false);
}

/// <inheritdoc />
public virtual async Task<(string? id, string? username)> GetUser(string username, CancellationToken token = new()) {
return await Retry.Execute(async () => {
ITwitchAPI api = GetApi();
GetUsersResponse? response = await api.Helix.Users.GetUsersAsync(logins: [username]);
GetUsersResponse? response = await api.Helix.Users.GetUsersAsync(logins: [username]).ConfigureAwait(false);
if (null == response) {
return (null, null);
}

User? user = response.Users.FirstOrDefault();
return (user?.Id, user?.Login);
}, Retries, token);
}, Retries, token).ConfigureAwait(false);
}

/// <inheritdoc />
public virtual async Task<string?> GetUserEmail(CancellationToken token = new()) {
return await Retry.Execute(async () => {
ITwitchAPI api = GetApi();
GetUsersResponse? response = await api.Helix.Users.GetUsersAsync();
GetUsersResponse? response = await api.Helix.Users.GetUsersAsync().ConfigureAwait(false);
if (null == response) {
return null;
}

return response.Users.FirstOrDefault()?.Email;
}, Retries, token);
}, Retries, token).ConfigureAwait(false);
}

/// <inheritdoc />
Expand All @@ -192,9 +192,9 @@ public virtual async Task<IEnumerable<TwitchModeratedChannel>> GetUserModChannel
request.Headers.Add("Authorization", $"Bearer {OAuth?.AccessToken}");
request.Headers.Add("Client-Id", TwitchAppConfig?.ClientId);

using HttpResponseMessage response = await client.SendAsync(request);
using HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
string responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var moderatedChannels = JsonConvert.DeserializeObject<TwitchModeratedChannelsResponse>(responseBody);
if (null == moderatedChannels) {
break;
Expand All @@ -219,7 +219,7 @@ public virtual async Task<IEnumerable<BannedUser>> BanChannelUsers(string channe
BanUserResponse? response = await api.Helix.Moderation.BanUserAsync(channelId, botId, new BanUserRequest {
UserId = user.Id,
Reason = reason
});
}).ConfigureAwait(false);

if (null == response || null == response.Data) {
continue;
Expand All @@ -229,7 +229,7 @@ public virtual async Task<IEnumerable<BannedUser>> BanChannelUsers(string channe
LOG.Info($"Banned {user.Username} ({user.Id}) in {channelId}: {reason}");
}
catch (HttpResponseException ex) {
string exceptionReason = await ex.HttpResponse.Content.ReadAsStringAsync(token);
string exceptionReason = await ex.HttpResponse.Content.ReadAsStringAsync(token).ConfigureAwait(false);
LOG.Debug($"Failed to ban {user.Username} ({user.Id}) in {channelId}: {exceptionReason}", ex);
}
catch (Exception ex) {
Expand All @@ -238,7 +238,7 @@ public virtual async Task<IEnumerable<BannedUser>> BanChannelUsers(string channe
}

return bannedUsers;
}, Retries, token);
}, Retries, token).ConfigureAwait(false);
}

/// <inheritdoc />
Expand All @@ -250,7 +250,7 @@ public virtual async Task<IEnumerable<Chatter>> GetChannelUsers(string channelId
string? cursor = null;
int total = 0;
do {
GetChattersResponse? response = await api.Helix.Chat.GetChattersAsync(channelId, botId, 1000, cursor);
GetChattersResponse? response = await api.Helix.Chat.GetChattersAsync(channelId, botId, 1000, cursor).ConfigureAwait(false);
if (null == response) {
break;
}
Expand All @@ -262,7 +262,7 @@ public virtual async Task<IEnumerable<Chatter>> GetChannelUsers(string channelId

Debug.Assert(chatters.Count == total);
return chatters;
}, Retries, token);
}, Retries, token).ConfigureAwait(false);
}

/// <inheritdoc />
Expand All @@ -279,7 +279,7 @@ public virtual async Task<IEnumerable<string>> GetChannelsLive(IEnumerable<strin
}

GetStreamsResponse? response =
await api.Helix.Streams.GetStreamsAsync(userIds: twitchIdsArray[i..lastIndex].ToList());
await api.Helix.Streams.GetStreamsAsync(userIds: twitchIdsArray[i..lastIndex].ToList()).ConfigureAwait(false);
if (null != response) {
liveUsers.AddRange(response.Streams.Where(s =>
"live".Equals(s.Type, StringComparison.InvariantCultureIgnoreCase)));
Expand All @@ -298,7 +298,7 @@ public virtual async Task<IEnumerable<string>> GetChannelsLive(IEnumerable<strin
GetModeratorsResponse? response = null;
do {
response = await api.Helix.Moderation.GetModeratorsAsync(channelId, first: 100,
after: response?.Pagination?.Cursor);
after: response?.Pagination?.Cursor).ConfigureAwait(false);
if (null == response || null == response.Data) {
break;
}
Expand All @@ -313,16 +313,16 @@ public virtual async Task<IEnumerable<string>> GetChannelsLive(IEnumerable<strin
} while (null != response.Pagination?.Cursor);

return results;
}, Retries, token);
}, Retries, token).ConfigureAwait(false);
}

/// <inheritdoc />
public virtual async Task<bool> AddChannelMod(string channelId, string userId, CancellationToken token = new()) {
return await Retry.Execute(async () => {
ITwitchAPI api = GetApi();
await api.Helix.Moderation.AddChannelModeratorAsync(channelId, userId);
await api.Helix.Moderation.AddChannelModeratorAsync(channelId, userId).ConfigureAwait(false);
return true;
}, Retries, token);
}, Retries, token).ConfigureAwait(false);
}

/// <summary>
Expand Down
14 changes: 7 additions & 7 deletions src/Nullinside.Api.Common/Twitch/TwitchClientProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public async Task<bool> SendMessage(string channel, string message, uint retryCo
// Try to connect and join the channel.
bool connectedAndJoined = false;
for (int i = 0; i < retryConnection; i++) {
if (await JoinChannel(channel)) {
if (await JoinChannel(channel).ConfigureAwait(false)) {
connectedAndJoined = true;
break;
}
Expand Down Expand Up @@ -184,7 +184,7 @@ public async Task<bool> SendMessage(string channel, string message, uint retryCo

/// <inheritdoc />
public async Task AddMessageCallback(string channel, Action<OnMessageReceivedArgs> callback) {
await JoinChannel(channel);
await JoinChannel(channel).ConfigureAwait(false);
string channelSan = channel.ToLowerInvariant();
lock (_onMessageReceived) {
if (!_onMessageReceived.TryAdd(channelSan, callback)) {
Expand Down Expand Up @@ -223,7 +223,7 @@ public void RemoveMessageCallback(string channel, Action<OnMessageReceivedArgs>

/// <inheritdoc />
public async Task AddBannedCallback(string channel, Action<OnUserBannedArgs> callback) {
await JoinChannel(channel);
await JoinChannel(channel).ConfigureAwait(false);

lock (_onUserBanReceived) {
_onUserBanReceived[channel] = callback;
Expand All @@ -250,7 +250,7 @@ public void RemoveDisconnectedCallback(Action callback) {

/// <inheritdoc />
public async Task AddRaidCallback(string channel, Action<OnRaidNotificationArgs> callback) {
await JoinChannel(channel);
await JoinChannel(channel).ConfigureAwait(false);

lock (_onRaid) {
_onRaid[channel] = callback;
Expand Down Expand Up @@ -282,7 +282,7 @@ private async Task<bool> JoinChannel(string channel) {
}

// Try to connect.
if (!await Connect()) {
if (!await Connect().ConfigureAwait(false)) {
return false;
}

Expand Down Expand Up @@ -319,7 +319,7 @@ private async Task<bool> JoinChannel(string channel) {
/// <param name="e">The event arguments.</param>
private async void TwitchChatClientReconnectOnElapsed(object? sender, ElapsedEventArgs e) {
// Connect the chat client.
await Connect();
await Connect().ConfigureAwait(false);

// Pull the master list of channels we should be connected to the stack.
string[]? allChannels = null;
Expand All @@ -329,7 +329,7 @@ private async void TwitchChatClientReconnectOnElapsed(object? sender, ElapsedEve

// Join all the channels.
foreach (string channel in allChannels) {
await JoinChannel(channel);
await JoinChannel(channel).ConfigureAwait(false);
}

// Restart the timer.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<wpf:ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xml:space="preserve">
<s:String x:Key="/Default/CodeInspection/Daemon/ConfigureAwaitAnalysisMode/@EntryValue">Library</s:String></wpf:ResourceDictionary>
6 changes: 3 additions & 3 deletions src/Nullinside.Api.Model/Shared/DatabaseLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void Dispose() {

// This is only used with hard coded names.
#pragma warning disable EF1002
await _mysqlDbContext.Database.ExecuteSqlRawAsync($"SELECT GET_LOCK('{name}', -1)", cancellationToken);
await _mysqlDbContext.Database.ExecuteSqlRawAsync($"SELECT GET_LOCK('{name}', -1)", cancellationToken).ConfigureAwait(false);
#pragma warning restore EF1002
_name = name;
return true;
Expand All @@ -63,13 +63,13 @@ public void Dispose() {
if (!string.IsNullOrWhiteSpace(name) && !name.Equals(_name, StringComparison.InvariantCultureIgnoreCase)) {
// This is only used with hard coded names.
#pragma warning disable EF1002
await _mysqlDbContext.Database.ExecuteSqlRawAsync($"SELECT RELEASE_LOCK('{_name}')", cancellationToken);
await _mysqlDbContext.Database.ExecuteSqlRawAsync($"SELECT RELEASE_LOCK('{_name}')", cancellationToken).ConfigureAwait(false);
#pragma warning restore EF1002
}

// This is only used with hard coded names.
#pragma warning disable EF1002
await _mysqlDbContext.Database.ExecuteSqlRawAsync($"SELECT RELEASE_LOCK('{name}')", cancellationToken);
await _mysqlDbContext.Database.ExecuteSqlRawAsync($"SELECT RELEASE_LOCK('{name}')", cancellationToken).ConfigureAwait(false);
#pragma warning restore EF1002
_name = null;
}
Expand Down
Loading