diff --git a/src/Heimdall.Application/Agents/Commands/Heartbeat/HeartbeatHandler.cs b/src/Heimdall.Application/Agents/Commands/Heartbeat/HeartbeatHandler.cs index 77f0609..9933527 100644 --- a/src/Heimdall.Application/Agents/Commands/Heartbeat/HeartbeatHandler.cs +++ b/src/Heimdall.Application/Agents/Commands/Heartbeat/HeartbeatHandler.cs @@ -13,7 +13,7 @@ public class HeartbeatHandler : IRequestHandler public async Task Handle(HeartbeatCommand request, CancellationToken ct) { - var agent = await _db.Agents.FirstOrDefaultAsync(a => a.Id == request.AgentId, ct); + var agent = await _db.Agents.FirstOrDefaultAsync(a => a.Id == request.AgentId, ct).ConfigureAwait(false); if (agent is null) return ServiceResult.NotFound("Agent not found"); @@ -28,7 +28,7 @@ public class HeartbeatHandler : IRequestHandler request.GpuType ?? GpuAcceleration.None); } - await _db.SaveChangesWithRetryAsync(ct: ct); + await _db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); return ServiceResult.Success(); } } diff --git a/src/Heimdall.Application/Agents/Commands/RegisterAgent/RegisterAgentHandler.cs b/src/Heimdall.Application/Agents/Commands/RegisterAgent/RegisterAgentHandler.cs index f2da67c..9c2f0ee 100644 --- a/src/Heimdall.Application/Agents/Commands/RegisterAgent/RegisterAgentHandler.cs +++ b/src/Heimdall.Application/Agents/Commands/RegisterAgent/RegisterAgentHandler.cs @@ -52,7 +52,7 @@ public class RegisterAgentHandler : IRequestHandler.Success( new RegisterAgentResponse(agent.Id, plainKey, prefix)); diff --git a/src/Heimdall.Application/Agents/Queries/GetAgent/GetAgentQuery.cs b/src/Heimdall.Application/Agents/Queries/GetAgent/GetAgentQuery.cs index 784419c..d39977c 100644 --- a/src/Heimdall.Application/Agents/Queries/GetAgent/GetAgentQuery.cs +++ b/src/Heimdall.Application/Agents/Queries/GetAgent/GetAgentQuery.cs @@ -15,7 +15,7 @@ public class GetAgentHandler : IRequestHandler> Handle(GetAgentQuery request, CancellationToken ct) { - var agent = await _db.Agents.FindAsync([request.Id], ct); + var agent = await _db.Agents.FindAsync([request.Id], ct).ConfigureAwait(false); if (agent is null) return ServiceResult.NotFound("Agent not found"); diff --git a/src/Heimdall.Application/Agents/Queries/GetAgentsBySite/GetAgentsBySiteQuery.cs b/src/Heimdall.Application/Agents/Queries/GetAgentsBySite/GetAgentsBySiteQuery.cs index 01624a4..f33fcf7 100644 --- a/src/Heimdall.Application/Agents/Queries/GetAgentsBySite/GetAgentsBySiteQuery.cs +++ b/src/Heimdall.Application/Agents/Queries/GetAgentsBySite/GetAgentsBySiteQuery.cs @@ -22,7 +22,7 @@ public class GetAgentsBySiteHandler : IRequestHandler a.SiteId == request.SiteId) .OrderBy(a => a.Name); - var total = await query.CountAsync(ct); + var total = await query.CountAsync(ct).ConfigureAwait(false); var items = await query .Skip((request.Page - 1) * request.PageSize) .Take(request.PageSize) diff --git a/src/Heimdall.Application/Agents/Queries/GetAllAgents/GetAllAgentsQuery.cs b/src/Heimdall.Application/Agents/Queries/GetAllAgents/GetAllAgentsQuery.cs index 9195d90..19ac230 100644 --- a/src/Heimdall.Application/Agents/Queries/GetAllAgents/GetAllAgentsQuery.cs +++ b/src/Heimdall.Application/Agents/Queries/GetAllAgents/GetAllAgentsQuery.cs @@ -19,7 +19,7 @@ public class GetAllAgentsHandler : IRequestHandler a.Name); - var total = await query.CountAsync(ct); + var total = await query.CountAsync(ct).ConfigureAwait(false); var items = await query .Skip((request.Page - 1) * request.PageSize) .Take(request.PageSize) diff --git a/src/Heimdall.Application/Assignments/Commands/Failover/FailoverHandler.cs b/src/Heimdall.Application/Assignments/Commands/Failover/FailoverHandler.cs index 0edebdf..1429b28 100644 --- a/src/Heimdall.Application/Assignments/Commands/Failover/FailoverHandler.cs +++ b/src/Heimdall.Application/Assignments/Commands/Failover/FailoverHandler.cs @@ -15,7 +15,7 @@ public sealed class FailoverHandler : IRequestHandler> Handle(FailoverCommand command, CancellationToken ct) { - var result = await _assignmentService.FailoverAgentAsync(command.AgentId, ct); + var result = await _assignmentService.FailoverAgentAsync(command.AgentId, ct).ConfigureAwait(false); if (!result.IsSuccess) return ServiceResult.Failure(result.Error!, result.StatusCode ?? 400); diff --git a/src/Heimdall.Application/Assignments/Commands/ReleaseCamera/ReleaseCameraHandler.cs b/src/Heimdall.Application/Assignments/Commands/ReleaseCamera/ReleaseCameraHandler.cs index 386ee9d..28d3147 100644 --- a/src/Heimdall.Application/Assignments/Commands/ReleaseCamera/ReleaseCameraHandler.cs +++ b/src/Heimdall.Application/Assignments/Commands/ReleaseCamera/ReleaseCameraHandler.cs @@ -15,6 +15,6 @@ public sealed class ReleaseCameraHandler : IRequestHandler Handle(ReleaseCameraCommand command, CancellationToken ct) { - return await _assignmentService.ReleaseCameraAsync(command.CameraId, ct); + return await _assignmentService.ReleaseCameraAsync(command.CameraId, ct).ConfigureAwait(false); } } diff --git a/src/Heimdall.Application/Assignments/Queries/GetActiveAssignment/GetActiveAssignmentHandler.cs b/src/Heimdall.Application/Assignments/Queries/GetActiveAssignment/GetActiveAssignmentHandler.cs index e6f0055..b120075 100644 --- a/src/Heimdall.Application/Assignments/Queries/GetActiveAssignment/GetActiveAssignmentHandler.cs +++ b/src/Heimdall.Application/Assignments/Queries/GetActiveAssignment/GetActiveAssignmentHandler.cs @@ -18,7 +18,7 @@ public sealed class GetActiveAssignmentHandler public async Task> Handle( GetActiveAssignmentQuery query, CancellationToken ct) { - var assignment = await _assignmentService.GetActiveAssignmentAsync(query.CameraId, ct); + var assignment = await _assignmentService.GetActiveAssignmentAsync(query.CameraId, ct).ConfigureAwait(false); if (assignment is null) return ServiceResult.Success(null); diff --git a/src/Heimdall.Application/Assignments/Queries/GetAgentAssignments/GetAgentAssignmentsHandler.cs b/src/Heimdall.Application/Assignments/Queries/GetAgentAssignments/GetAgentAssignmentsHandler.cs index 454ea4c..0db86ff 100644 --- a/src/Heimdall.Application/Assignments/Queries/GetAgentAssignments/GetAgentAssignmentsHandler.cs +++ b/src/Heimdall.Application/Assignments/Queries/GetAgentAssignments/GetAgentAssignmentsHandler.cs @@ -18,7 +18,7 @@ public sealed class GetAgentAssignmentsHandler public async Task>> Handle( GetAgentAssignmentsQuery query, CancellationToken ct) { - var assignments = await _assignmentService.GetAgentAssignmentsAsync(query.AgentId, ct); + var assignments = await _assignmentService.GetAgentAssignmentsAsync(query.AgentId, ct).ConfigureAwait(false); var result = assignments.Select(a => new AssignmentResponse( a.CameraId, diff --git a/src/Heimdall.Application/Assignments/Queries/GetCameraHistory/GetCameraHistoryHandler.cs b/src/Heimdall.Application/Assignments/Queries/GetCameraHistory/GetCameraHistoryHandler.cs index 79845a4..765ef14 100644 --- a/src/Heimdall.Application/Assignments/Queries/GetCameraHistory/GetCameraHistoryHandler.cs +++ b/src/Heimdall.Application/Assignments/Queries/GetCameraHistory/GetCameraHistoryHandler.cs @@ -18,7 +18,7 @@ public sealed class GetCameraHistoryHandler public async Task>> Handle( GetCameraHistoryQuery query, CancellationToken ct) { - var assignments = await _assignmentService.GetCameraHistoryAsync(query.CameraId, ct); + var assignments = await _assignmentService.GetCameraHistoryAsync(query.CameraId, ct).ConfigureAwait(false); var result = assignments.Select(a => new AssignmentResponse( a.CameraId, diff --git a/src/Heimdall.Application/Audit/Queries/GetAuditLogs/GetAuditLogsQuery.cs b/src/Heimdall.Application/Audit/Queries/GetAuditLogs/GetAuditLogsQuery.cs index 4a5f84c..a351c2b 100644 --- a/src/Heimdall.Application/Audit/Queries/GetAuditLogs/GetAuditLogsQuery.cs +++ b/src/Heimdall.Application/Audit/Queries/GetAuditLogs/GetAuditLogsQuery.cs @@ -28,7 +28,7 @@ public class GetAuditLogsQueryHandler if (!string.IsNullOrEmpty(request.Action)) query = query.Where(al => al.Action == request.Action); - var total = await query.CountAsync(ct); + var total = await query.CountAsync(ct).ConfigureAwait(false); var items = await query .OrderByDescending(al => al.Timestamp) diff --git a/src/Heimdall.Application/Auth/AuthHelper.cs b/src/Heimdall.Application/Auth/AuthHelper.cs index 168b94c..8458a11 100644 --- a/src/Heimdall.Application/Auth/AuthHelper.cs +++ b/src/Heimdall.Application/Auth/AuthHelper.cs @@ -14,7 +14,7 @@ internal static class AuthHelper IRolePermissionService rolePermissionService, UserManager userManager) { - var roles = await userManager.GetRolesAsync(user); + var roles = await userManager.GetRolesAsync(user).ConfigureAwait(false); var permissions = rolePermissionService.GetPermissionsForRoles(roles); var (accessToken, expiresAt) = jwtService.GenerateAccessToken(user, roles, permissions); @@ -30,7 +30,7 @@ internal static class AuthHelper internal static async Task MapUserInfoAsync(AppUser user, UserManager userManager) { - var roles = await userManager.GetRolesAsync(user); + var roles = await userManager.GetRolesAsync(user).ConfigureAwait(false); return new UserInfo(user.Id, user.Email ?? "", user.DisplayName, [.. roles]); } } diff --git a/src/Heimdall.Application/Auth/Commands/ChangePassword/ChangePasswordHandler.cs b/src/Heimdall.Application/Auth/Commands/ChangePassword/ChangePasswordHandler.cs index 10e6f17..32e475b 100644 --- a/src/Heimdall.Application/Auth/Commands/ChangePassword/ChangePasswordHandler.cs +++ b/src/Heimdall.Application/Auth/Commands/ChangePassword/ChangePasswordHandler.cs @@ -21,14 +21,14 @@ public class ChangePasswordHandler : IRequestHandler e.Description)); diff --git a/src/Heimdall.Application/Auth/Commands/Disable2fa/Disable2faHandler.cs b/src/Heimdall.Application/Auth/Commands/Disable2fa/Disable2faHandler.cs index 44b7d96..211a273 100644 --- a/src/Heimdall.Application/Auth/Commands/Disable2fa/Disable2faHandler.cs +++ b/src/Heimdall.Application/Auth/Commands/Disable2fa/Disable2faHandler.cs @@ -21,14 +21,14 @@ public class Disable2faHandler : IRequestHandler { _logger.LogDebug("Enable2fa: UserId={UserId}", request.UserId); - var user = await _userManager.FindByIdAsync(request.UserId.ToString()); + var user = await _userManager.FindByIdAsync(request.UserId.ToString()).ConfigureAwait(false); if (user is null) { _logger.LogWarning("Enable2fa: User not found UserId={UserId}", request.UserId); return ServiceResult.NotFound("User not found"); } - var result = await _userManager.SetTwoFactorEnabledAsync(user, true); + var result = await _userManager.SetTwoFactorEnabledAsync(user, true).ConfigureAwait(false); if (!result.Succeeded) { _logger.LogError("Enable2fa: Failed UserId={UserId}", request.UserId); diff --git a/src/Heimdall.Application/Auth/Commands/Login/LoginHandler.cs b/src/Heimdall.Application/Auth/Commands/Login/LoginHandler.cs index 99ec7f5..89eb182 100644 --- a/src/Heimdall.Application/Auth/Commands/Login/LoginHandler.cs +++ b/src/Heimdall.Application/Auth/Commands/Login/LoginHandler.cs @@ -34,7 +34,7 @@ public class LoginHandler : IRequestHandler if (!string.IsNullOrEmpty(request.RefreshToken)) { - await _authData.RevokeRefreshTokenAsync(request.RefreshToken, request.UserId, ct); + await _authData.RevokeRefreshTokenAsync(request.RefreshToken, request.UserId, ct).ConfigureAwait(false); } - await _signInService.SignOutAsync(); + await _signInService.SignOutAsync().ConfigureAwait(false); return ServiceResult.Success(); } } diff --git a/src/Heimdall.Application/Auth/Commands/RefreshToken/RefreshTokenHandler.cs b/src/Heimdall.Application/Auth/Commands/RefreshToken/RefreshTokenHandler.cs index 1e514db..878a934 100644 --- a/src/Heimdall.Application/Auth/Commands/RefreshToken/RefreshTokenHandler.cs +++ b/src/Heimdall.Application/Auth/Commands/RefreshToken/RefreshTokenHandler.cs @@ -43,7 +43,7 @@ public class RefreshTokenHandler : IRequestHandler.Unauthorized("Invalid token"); } - var user = await _userManager.FindByIdAsync(userId); + var user = await _userManager.FindByIdAsync(userId).ConfigureAwait(false); if (user is null) { _logger.LogWarning("RefreshToken: User not found UserId={UserId}", userId); @@ -66,6 +66,6 @@ public class RefreshTokenHandler : IRequestHandler.Conflict("Email already registered"); } - var anyUsers = await _authData.IsFirstUserAsync(ct); + var anyUsers = await _authData.IsFirstUserAsync(ct).ConfigureAwait(false); _logger.LogDebug("Register: anyUsers={AnyUsers}", anyUsers); if (!anyUsers) @@ -54,7 +54,7 @@ public class RegisterHandler : IRequestHandler e.Description)); @@ -62,13 +62,13 @@ public class RegisterHandler : IRequestHandler.Failure(errors); } - await _userManager.AddToRoleAsync(firstUser, "Admin"); + await _userManager.AddToRoleAsync(firstUser, "Admin").ConfigureAwait(false); _logger.LogInformation("Register: First user created and granted Admin role Email={Email}", request.Email); - return await AuthHelper.CreateAuthResponseAsync(firstUser, _jwtService, _rolePermissionService, _userManager); + return await AuthHelper.CreateAuthResponseAsync(firstUser, _jwtService, _rolePermissionService, _userManager).ConfigureAwait(false); } _logger.LogDebug("Register: checking PublicRegistrationEnabled setting"); - var setting = await _authData.GetSettingValueAsync("auth.public-registration.enabled", ct); + var setting = await _authData.GetSettingValueAsync("auth.public-registration.enabled", ct).ConfigureAwait(false); if (setting is not null && !string.Equals(setting, "true", StringComparison.OrdinalIgnoreCase)) { @@ -84,7 +84,7 @@ public class RegisterHandler : IRequestHandler e.Description)); @@ -93,9 +93,9 @@ public class RegisterHandler : IRequestHandler e.Description)); @@ -53,9 +53,9 @@ public class RegisterAdminHandler : IRequestHandler.Failure(errors); } - await _userManager.AddToRoleAsync(user, "Admin"); + await _userManager.AddToRoleAsync(user, "Admin").ConfigureAwait(false); _logger.LogInformation("RegisterAdmin: Created and granted Admin role Email={Email}", request.Email); - return await AuthHelper.CreateAuthResponseAsync(user, _jwtService, _rolePermissionService, _userManager); + return await AuthHelper.CreateAuthResponseAsync(user, _jwtService, _rolePermissionService, _userManager).ConfigureAwait(false); } } diff --git a/src/Heimdall.Application/Auth/Commands/Verify2fa/Verify2faHandler.cs b/src/Heimdall.Application/Auth/Commands/Verify2fa/Verify2faHandler.cs index cadbc3c..62de911 100644 --- a/src/Heimdall.Application/Auth/Commands/Verify2fa/Verify2faHandler.cs +++ b/src/Heimdall.Application/Auth/Commands/Verify2fa/Verify2faHandler.cs @@ -31,7 +31,7 @@ public class Verify2faHandler : IRequestHandler> Handle(CreateCameraCommand request, CancellationToken ct) { - var site = await _db.Sites.FindAsync([request.SiteId], ct); + var site = await _db.Sites.FindAsync([request.SiteId], ct).ConfigureAwait(false); if (site is null) return ServiceResult.NotFound("Site not found"); var camera = new Camera(request.SiteId, request.Name, request.RtspUrl, request.Manufacturer, request.Model); _db.Cameras.Add(camera); - await _db.SaveChangesWithRetryAsync(ct: ct); + await _db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); return ServiceResult.Success(MapResponse(camera)); } diff --git a/src/Heimdall.Application/Cameras/Commands/DeleteCamera/DeleteCameraCommand.cs b/src/Heimdall.Application/Cameras/Commands/DeleteCamera/DeleteCameraCommand.cs index 5de1cbb..57f6390 100644 --- a/src/Heimdall.Application/Cameras/Commands/DeleteCamera/DeleteCameraCommand.cs +++ b/src/Heimdall.Application/Cameras/Commands/DeleteCamera/DeleteCameraCommand.cs @@ -16,12 +16,12 @@ public class DeleteCameraCommandHandler : IRequestHandler Handle(DeleteCameraCommand request, CancellationToken ct) { - var camera = await _db.Cameras.FindAsync([request.Id], ct); + var camera = await _db.Cameras.FindAsync([request.Id], ct).ConfigureAwait(false); if (camera is null) return ServiceResult.NotFound("Camera not found"); camera.SoftDelete(); - await _db.SaveChangesWithRetryAsync(ct: ct); + await _db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); return ServiceResult.Success(); } diff --git a/src/Heimdall.Application/Cameras/Commands/SetCredentials/SetCameraCredentialsCommand.cs b/src/Heimdall.Application/Cameras/Commands/SetCredentials/SetCameraCredentialsCommand.cs index 7fc3048..662539f 100644 --- a/src/Heimdall.Application/Cameras/Commands/SetCredentials/SetCameraCredentialsCommand.cs +++ b/src/Heimdall.Application/Cameras/Commands/SetCredentials/SetCameraCredentialsCommand.cs @@ -23,7 +23,7 @@ public class SetCameraCredentialsCommandHandler : IRequestHandler Handle(SetCameraCredentialsCommand request, CancellationToken ct) { - var camera = await _db.Cameras.FindAsync([request.CameraId], ct); + var camera = await _db.Cameras.FindAsync([request.CameraId], ct).ConfigureAwait(false); if (camera is null) return ServiceResult.NotFound("Camera not found"); @@ -35,7 +35,7 @@ public class SetCameraCredentialsCommandHandler : IRequestHandler> Handle(UpdateCameraCommand request, CancellationToken ct) { - var camera = await _db.Cameras.FindAsync([request.Id], ct); + var camera = await _db.Cameras.FindAsync([request.Id], ct).ConfigureAwait(false); if (camera is null) return ServiceResult.NotFound("Camera not found"); @@ -32,7 +32,7 @@ public class UpdateCameraCommandHandler : IRequestHandler.Success(MapResponse(camera)); } diff --git a/src/Heimdall.Application/Cameras/Queries/GetCamera/GetCameraQuery.cs b/src/Heimdall.Application/Cameras/Queries/GetCamera/GetCameraQuery.cs index bf8908e..17a16e5 100644 --- a/src/Heimdall.Application/Cameras/Queries/GetCamera/GetCameraQuery.cs +++ b/src/Heimdall.Application/Cameras/Queries/GetCamera/GetCameraQuery.cs @@ -17,7 +17,7 @@ public class GetCameraQueryHandler : IRequestHandler> Handle(GetCameraQuery request, CancellationToken ct) { - var camera = await _db.Cameras.FindAsync([request.Id], ct); + var camera = await _db.Cameras.FindAsync([request.Id], ct).ConfigureAwait(false); if (camera is null) return ServiceResult.NotFound("Camera not found"); diff --git a/src/Heimdall.Application/Cameras/Queries/GetCamerasBySite/GetCamerasBySiteQuery.cs b/src/Heimdall.Application/Cameras/Queries/GetCamerasBySite/GetCamerasBySiteQuery.cs index 34aade1..efcb6e0 100644 --- a/src/Heimdall.Application/Cameras/Queries/GetCamerasBySite/GetCamerasBySiteQuery.cs +++ b/src/Heimdall.Application/Cameras/Queries/GetCamerasBySite/GetCamerasBySiteQuery.cs @@ -25,7 +25,7 @@ public class GetCamerasBySiteQueryHandler : IRequestHandler c.SiteId == request.SiteId) .OrderBy(c => c.Name); - var total = await query.CountAsync(ct); + var total = await query.CountAsync(ct).ConfigureAwait(false); var items = await query .Skip((request.Page - 1) * request.PageSize) .Take(request.PageSize) diff --git a/src/Heimdall.Application/Common/Behaviors/LoggingBehavior.cs b/src/Heimdall.Application/Common/Behaviors/LoggingBehavior.cs index df43adc..561ddd1 100644 --- a/src/Heimdall.Application/Common/Behaviors/LoggingBehavior.cs +++ b/src/Heimdall.Application/Common/Behaviors/LoggingBehavior.cs @@ -28,7 +28,7 @@ public class LoggingBehavior : IPipelineBehavior : IPipelineBehavior(request); var results = await Task.WhenAll( @@ -33,7 +33,7 @@ public class ValidationBehavior : IPipelineBehavior f.ErrorMessage)); return CreateFailure(error, 400); diff --git a/src/Heimdall.Application/Discovery/Commands/BuildStreamUrls/BuildStreamUrlsCommand.cs b/src/Heimdall.Application/Discovery/Commands/BuildStreamUrls/BuildStreamUrlsCommand.cs index 382a3fa..4e0087f 100644 --- a/src/Heimdall.Application/Discovery/Commands/BuildStreamUrls/BuildStreamUrlsCommand.cs +++ b/src/Heimdall.Application/Discovery/Commands/BuildStreamUrls/BuildStreamUrlsCommand.cs @@ -27,6 +27,6 @@ public class BuildStreamUrlsCommandHandler : IRequestHandler Handle(CancelTestSessionCommand request, CancellationToken ct) { - return await _discovery.CancelTestSessionAsync(request.SessionId, ct); + return await _discovery.CancelTestSessionAsync(request.SessionId, ct).ConfigureAwait(false); } } diff --git a/src/Heimdall.Application/Discovery/Commands/ConfirmDiscovery/ConfirmDiscoveryCommand.cs b/src/Heimdall.Application/Discovery/Commands/ConfirmDiscovery/ConfirmDiscoveryCommand.cs index fd2611b..d5c749f 100644 --- a/src/Heimdall.Application/Discovery/Commands/ConfirmDiscovery/ConfirmDiscoveryCommand.cs +++ b/src/Heimdall.Application/Discovery/Commands/ConfirmDiscovery/ConfirmDiscoveryCommand.cs @@ -32,6 +32,6 @@ public class ConfirmDiscoveryCommandHandler : IRequestHandler> Handle(ProbeIpCommand request, CancellationToken ct) { var dto = new ProbeRequest(request.SiteId, request.Ip); - return await _discovery.ProbeIpAsync(dto, ct); + return await _discovery.ProbeIpAsync(dto, ct).ConfigureAwait(false); } } diff --git a/src/Heimdall.Application/Discovery/Commands/ScanSubnet/ScanSubnetCommand.cs b/src/Heimdall.Application/Discovery/Commands/ScanSubnet/ScanSubnetCommand.cs index fe71b76..fdc473c 100644 --- a/src/Heimdall.Application/Discovery/Commands/ScanSubnet/ScanSubnetCommand.cs +++ b/src/Heimdall.Application/Discovery/Commands/ScanSubnet/ScanSubnetCommand.cs @@ -22,6 +22,6 @@ public class ScanSubnetCommandHandler : IRequestHandler>> Handle(ScanSubnetCommand request, CancellationToken ct) { var dto = new ScanRequest(request.SiteId, request.SubnetCidr, request.TimeoutMs); - return await _discovery.ScanSubnetAsync(dto, ct); + return await _discovery.ScanSubnetAsync(dto, ct).ConfigureAwait(false); } } diff --git a/src/Heimdall.Application/Discovery/Commands/TestStreams/TestStreamsCommand.cs b/src/Heimdall.Application/Discovery/Commands/TestStreams/TestStreamsCommand.cs index 81216d3..e3527b0 100644 --- a/src/Heimdall.Application/Discovery/Commands/TestStreams/TestStreamsCommand.cs +++ b/src/Heimdall.Application/Discovery/Commands/TestStreams/TestStreamsCommand.cs @@ -21,6 +21,6 @@ public class TestStreamsCommandHandler : IRequestHandler> Handle(TestStreamsCommand request, CancellationToken ct) { var dto = new StreamTestRequest(request.SourceId, request.Streams); - return await _discovery.TestStreamsAsync(dto, ct); + return await _discovery.TestStreamsAsync(dto, ct).ConfigureAwait(false); } } diff --git a/src/Heimdall.Application/Discovery/Queries/CheckDuplicate/CheckDuplicateQuery.cs b/src/Heimdall.Application/Discovery/Queries/CheckDuplicate/CheckDuplicateQuery.cs index 4d370d5..51d9d35 100644 --- a/src/Heimdall.Application/Discovery/Queries/CheckDuplicate/CheckDuplicateQuery.cs +++ b/src/Heimdall.Application/Discovery/Queries/CheckDuplicate/CheckDuplicateQuery.cs @@ -22,6 +22,6 @@ public class CheckDuplicateQueryHandler : IRequestHandler> Handle(CheckDuplicateQuery request, CancellationToken ct) { var dto = new CheckDuplicateRequest(request.SiteId, request.Ip, request.Mac); - return await _discovery.CheckDuplicateAsync(dto, ct); + return await _discovery.CheckDuplicateAsync(dto, ct).ConfigureAwait(false); } } diff --git a/src/Heimdall.Application/Discovery/Queries/GetScreenshot/GetScreenshotQuery.cs b/src/Heimdall.Application/Discovery/Queries/GetScreenshot/GetScreenshotQuery.cs index 6011c30..7b0aa99 100644 --- a/src/Heimdall.Application/Discovery/Queries/GetScreenshot/GetScreenshotQuery.cs +++ b/src/Heimdall.Application/Discovery/Queries/GetScreenshot/GetScreenshotQuery.cs @@ -17,7 +17,7 @@ public class GetScreenshotQueryHandler : IRequestHandler> Handle(GetScreenshotQuery request, CancellationToken ct) { - var bytes = await _discovery.GetScreenshotAsync(request.SessionId, request.Index, ct); + var bytes = await _discovery.GetScreenshotAsync(request.SessionId, request.Index, ct).ConfigureAwait(false); if (bytes is null || bytes.Length == 0) return ServiceResult.NotFound("Screenshot not found"); diff --git a/src/Heimdall.Application/Discovery/Queries/GetTestSession/GetTestSessionQuery.cs b/src/Heimdall.Application/Discovery/Queries/GetTestSession/GetTestSessionQuery.cs index 1a852a6..7e0be1c 100644 --- a/src/Heimdall.Application/Discovery/Queries/GetTestSession/GetTestSessionQuery.cs +++ b/src/Heimdall.Application/Discovery/Queries/GetTestSession/GetTestSessionQuery.cs @@ -18,6 +18,6 @@ public class GetTestSessionQueryHandler : IRequestHandler> Handle(GetTestSessionQuery request, CancellationToken ct) { - return await _discovery.GetTestSessionAsync(request.SessionId, ct); + return await _discovery.GetTestSessionAsync(request.SessionId, ct).ConfigureAwait(false); } } diff --git a/src/Heimdall.Application/Discovery/Queries/SearchDatabase/SearchDatabaseQuery.cs b/src/Heimdall.Application/Discovery/Queries/SearchDatabase/SearchDatabaseQuery.cs index 8cac8d4..dc5f973 100644 --- a/src/Heimdall.Application/Discovery/Queries/SearchDatabase/SearchDatabaseQuery.cs +++ b/src/Heimdall.Application/Discovery/Queries/SearchDatabase/SearchDatabaseQuery.cs @@ -18,6 +18,6 @@ public class SearchDatabaseQueryHandler : IRequestHandler> Handle(SearchDatabaseQuery request, CancellationToken ct) { - return await _discovery.SearchDatabaseAsync(request.Query, ct); + return await _discovery.SearchDatabaseAsync(request.Query, ct).ConfigureAwait(false); } } diff --git a/src/Heimdall.Application/Events/Commands/AttachSnapshot/AttachSnapshotHandler.cs b/src/Heimdall.Application/Events/Commands/AttachSnapshot/AttachSnapshotHandler.cs index 1277eae..914cda4 100644 --- a/src/Heimdall.Application/Events/Commands/AttachSnapshot/AttachSnapshotHandler.cs +++ b/src/Heimdall.Application/Events/Commands/AttachSnapshot/AttachSnapshotHandler.cs @@ -13,12 +13,12 @@ public class AttachSnapshotHandler : IRequestHandler Handle(AttachSnapshotCommand request, CancellationToken ct) { - var ev = await _context.CameraEvents.FindAsync([request.EventId], ct); + var ev = await _context.CameraEvents.FindAsync([request.EventId], ct).ConfigureAwait(false); if (ev is null) return ServiceResult.NotFound("Event not found"); ev.SetSnapshot(request.SnapshotUrl, request.ThumbUrl); - await _context.SaveChangesWithRetryAsync(ct: ct); + await _context.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); return ServiceResult.Success(); } diff --git a/src/Heimdall.Application/Events/Commands/CreateEvent/CreateEventHandler.cs b/src/Heimdall.Application/Events/Commands/CreateEvent/CreateEventHandler.cs index 1366484..8da7b3e 100644 --- a/src/Heimdall.Application/Events/Commands/CreateEvent/CreateEventHandler.cs +++ b/src/Heimdall.Application/Events/Commands/CreateEvent/CreateEventHandler.cs @@ -22,7 +22,7 @@ public class CreateEventHandler : IRequestHandler> Handle(CreateEventCommand request, CancellationToken ct) { - var camera = await _context.Cameras.FindAsync([request.CameraId], ct); + var camera = await _context.Cameras.FindAsync([request.CameraId], ct).ConfigureAwait(false); if (camera is null) return ServiceResult.NotFound("Camera not found"); @@ -31,10 +31,10 @@ public class CreateEventHandler : IRequestHandler.Success(response); } diff --git a/src/Heimdall.Application/Events/Commands/DeleteEvent/DeleteEventHandler.cs b/src/Heimdall.Application/Events/Commands/DeleteEvent/DeleteEventHandler.cs index f321b81..3111dae 100644 --- a/src/Heimdall.Application/Events/Commands/DeleteEvent/DeleteEventHandler.cs +++ b/src/Heimdall.Application/Events/Commands/DeleteEvent/DeleteEventHandler.cs @@ -13,12 +13,12 @@ public class DeleteEventHandler : IRequestHandler Handle(DeleteEventCommand request, CancellationToken ct) { - var ev = await _context.CameraEvents.FindAsync([request.Id], ct); + var ev = await _context.CameraEvents.FindAsync([request.Id], ct).ConfigureAwait(false); if (ev is null) return ServiceResult.NotFound("Event not found"); _context.CameraEvents.Remove(ev); - await _context.SaveChangesWithRetryAsync(ct: ct); + await _context.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); return ServiceResult.Success(); } diff --git a/src/Heimdall.Application/Events/Notifications/EventCreatedNotificationHandler.cs b/src/Heimdall.Application/Events/Notifications/EventCreatedNotificationHandler.cs index 637c875..3a76657 100644 --- a/src/Heimdall.Application/Events/Notifications/EventCreatedNotificationHandler.cs +++ b/src/Heimdall.Application/Events/Notifications/EventCreatedNotificationHandler.cs @@ -11,6 +11,6 @@ public class EventCreatedNotificationHandler : INotificationHandler e.Confidence >= request.MinConfidence.Value); - var total = await query.CountAsync(ct); + var total = await query.CountAsync(ct).ConfigureAwait(false); var items = await query .OrderByDescending(e => e.OccurredAt) .Skip((request.Page - 1) * pageSize) diff --git a/src/Heimdall.Application/Groups/Commands/AddUserToGroup/AddUserToGroupCommand.cs b/src/Heimdall.Application/Groups/Commands/AddUserToGroup/AddUserToGroupCommand.cs index 2fdf023..52d6497 100644 --- a/src/Heimdall.Application/Groups/Commands/AddUserToGroup/AddUserToGroupCommand.cs +++ b/src/Heimdall.Application/Groups/Commands/AddUserToGroup/AddUserToGroupCommand.cs @@ -15,11 +15,11 @@ public class AddUserToGroupCommandHandler : IRequestHandler Handle(AddUserToGroupCommand request, CancellationToken ct) { - var group = await _db.Groups.FindAsync([request.GroupId], ct); + var group = await _db.Groups.FindAsync([request.GroupId], ct).ConfigureAwait(false); if (group is null) return ServiceResult.NotFound("Group not found"); - var user = await _db.Users.FindAsync([request.UserId], ct); + var user = await _db.Users.FindAsync([request.UserId], ct).ConfigureAwait(false); if (user is null) return ServiceResult.NotFound("User not found"); @@ -32,7 +32,7 @@ public class AddUserToGroupCommandHandler : IRequestHandler> Handle(CreateGroupCommand request, CancellationToken ct) { - var exists = await _db.Groups.AnyAsync(g => g.Name == request.Name, ct); + var exists = await _db.Groups.AnyAsync(g => g.Name == request.Name, ct).ConfigureAwait(false); if (exists) return ServiceResult.Conflict("A group with this name already exists"); @@ -24,7 +24,7 @@ public class CreateGroupCommandHandler : IRequestHandler.Success(Map(group, 0)); } diff --git a/src/Heimdall.Application/Groups/Commands/DeleteGroup/DeleteGroupCommand.cs b/src/Heimdall.Application/Groups/Commands/DeleteGroup/DeleteGroupCommand.cs index a9538f0..17a323c 100644 --- a/src/Heimdall.Application/Groups/Commands/DeleteGroup/DeleteGroupCommand.cs +++ b/src/Heimdall.Application/Groups/Commands/DeleteGroup/DeleteGroupCommand.cs @@ -14,14 +14,14 @@ public class DeleteGroupCommandHandler : IRequestHandler Handle(DeleteGroupCommand request, CancellationToken ct) { - var group = await _db.Groups.FindAsync([request.Id], ct); + var group = await _db.Groups.FindAsync([request.Id], ct).ConfigureAwait(false); if (group is null) return ServiceResult.NotFound("Group not found"); group.SoftDelete(); _db.AuditLogs.Add(new AuditLog(null, "Group.Deleted", "Group", request.Id.ToString())); - await _db.SaveChangesWithRetryAsync(ct: ct); + await _db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); return ServiceResult.Success(); } diff --git a/src/Heimdall.Application/Groups/Commands/RemoveUserFromGroup/RemoveUserFromGroupCommand.cs b/src/Heimdall.Application/Groups/Commands/RemoveUserFromGroup/RemoveUserFromGroupCommand.cs index 8cd04b7..e289ba6 100644 --- a/src/Heimdall.Application/Groups/Commands/RemoveUserFromGroup/RemoveUserFromGroupCommand.cs +++ b/src/Heimdall.Application/Groups/Commands/RemoveUserFromGroup/RemoveUserFromGroupCommand.cs @@ -14,7 +14,7 @@ public class RemoveUserFromGroupCommandHandler : IRequestHandler Handle(RemoveUserFromGroupCommand request, CancellationToken ct) { - var userGroup = await _db.UserGroups.FindAsync([request.UserId, request.GroupId], ct); + var userGroup = await _db.UserGroups.FindAsync([request.UserId, request.GroupId], ct).ConfigureAwait(false); if (userGroup is null) return ServiceResult.NotFound("User is not a member of this group"); @@ -22,7 +22,7 @@ public class RemoveUserFromGroupCommandHandler : IRequestHandler> Handle(UpdateGroupCommand request, CancellationToken ct) { - var group = await _db.Groups.FindAsync([request.Id], ct); + var group = await _db.Groups.FindAsync([request.Id], ct).ConfigureAwait(false); if (group is null) return ServiceResult.NotFound("Group not found"); group.Update(request.Name, request.Description); _db.AuditLogs.Add(new AuditLog(null, "Group.Updated", "Group", request.Id.ToString())); - await _db.SaveChangesWithRetryAsync(ct: ct); + await _db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); - var memberCount = await _db.UserGroups.CountAsync(ug => ug.GroupId == request.Id, ct); + var memberCount = await _db.UserGroups.CountAsync(ug => ug.GroupId == request.Id, ct).ConfigureAwait(false); return ServiceResult.Success(Map(group, memberCount)); } diff --git a/src/Heimdall.Application/Groups/Queries/GetGroup/GetGroupQuery.cs b/src/Heimdall.Application/Groups/Queries/GetGroup/GetGroupQuery.cs index c1dbfdd..ad3eaa5 100644 --- a/src/Heimdall.Application/Groups/Queries/GetGroup/GetGroupQuery.cs +++ b/src/Heimdall.Application/Groups/Queries/GetGroup/GetGroupQuery.cs @@ -16,11 +16,11 @@ public class GetGroupQueryHandler : IRequestHandler> Handle(GetGroupQuery request, CancellationToken ct) { - var group = await _db.Groups.FindAsync([request.Id], ct); + var group = await _db.Groups.FindAsync([request.Id], ct).ConfigureAwait(false); if (group is null) return ServiceResult.NotFound("Group not found"); - var memberCount = await _db.UserGroups.CountAsync(ug => ug.GroupId == request.Id, ct); + var memberCount = await _db.UserGroups.CountAsync(ug => ug.GroupId == request.Id, ct).ConfigureAwait(false); return ServiceResult.Success(Map(group, memberCount)); } diff --git a/src/Heimdall.Application/Groups/Queries/GetGroupMembers/GetGroupMembersQuery.cs b/src/Heimdall.Application/Groups/Queries/GetGroupMembers/GetGroupMembersQuery.cs index 6c31b86..87acb55 100644 --- a/src/Heimdall.Application/Groups/Queries/GetGroupMembers/GetGroupMembersQuery.cs +++ b/src/Heimdall.Application/Groups/Queries/GetGroupMembers/GetGroupMembersQuery.cs @@ -17,7 +17,7 @@ public class GetGroupMembersQueryHandler public async Task>> Handle( GetGroupMembersQuery request, CancellationToken ct) { - var groupExists = await _db.Groups.AnyAsync(g => g.Id == request.GroupId, ct); + var groupExists = await _db.Groups.AnyAsync(g => g.Id == request.GroupId, ct).ConfigureAwait(false); if (!groupExists) return ServiceResult>.NotFound("Group not found"); diff --git a/src/Heimdall.Application/Groups/Queries/GetGroups/GetGroupsQuery.cs b/src/Heimdall.Application/Groups/Queries/GetGroups/GetGroupsQuery.cs index 2a6a5d7..0707685 100644 --- a/src/Heimdall.Application/Groups/Queries/GetGroups/GetGroupsQuery.cs +++ b/src/Heimdall.Application/Groups/Queries/GetGroups/GetGroupsQuery.cs @@ -17,7 +17,7 @@ public class GetGroupsQueryHandler : IRequestHandler g.Name); - var total = await query.CountAsync(ct); + var total = await query.CountAsync(ct).ConfigureAwait(false); var groups = await query .Skip((request.Page - 1) * request.PageSize) .Take(request.PageSize) diff --git a/src/Heimdall.Application/Notifications/Commands/MarkAllAsRead/MarkAllAsReadHandler.cs b/src/Heimdall.Application/Notifications/Commands/MarkAllAsRead/MarkAllAsReadHandler.cs index ce01951..43fa05b 100644 --- a/src/Heimdall.Application/Notifications/Commands/MarkAllAsRead/MarkAllAsReadHandler.cs +++ b/src/Heimdall.Application/Notifications/Commands/MarkAllAsRead/MarkAllAsReadHandler.cs @@ -20,7 +20,7 @@ public class MarkAllAsReadHandler : IRequestHandler.Success(new MarkAsReadResponse(true)); } diff --git a/src/Heimdall.Application/Notifications/Commands/MarkAsRead/MarkAsReadHandler.cs b/src/Heimdall.Application/Notifications/Commands/MarkAsRead/MarkAsReadHandler.cs index ac133e8..f6a4113 100644 --- a/src/Heimdall.Application/Notifications/Commands/MarkAsRead/MarkAsReadHandler.cs +++ b/src/Heimdall.Application/Notifications/Commands/MarkAsRead/MarkAsReadHandler.cs @@ -20,7 +20,7 @@ public class MarkAsReadHandler : IRequestHandler.NotFound("Notification not found"); notification.MarkAsRead(); - await _context.SaveChangesWithRetryAsync(ct: ct); + await _context.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); return ServiceResult.Success(new MarkAsReadResponse(true)); } diff --git a/src/Heimdall.Application/Notifications/Commands/UpdateConfig/UpdateNotificationConfigHandler.cs b/src/Heimdall.Application/Notifications/Commands/UpdateConfig/UpdateNotificationConfigHandler.cs index 81faf29..f76f7dc 100644 --- a/src/Heimdall.Application/Notifications/Commands/UpdateConfig/UpdateNotificationConfigHandler.cs +++ b/src/Heimdall.Application/Notifications/Commands/UpdateConfig/UpdateNotificationConfigHandler.cs @@ -44,7 +44,7 @@ public class UpdateNotificationConfigHandler : IRequestHandler.Success(_mapper.Map(config)); } diff --git a/src/Heimdall.Application/Notifications/Queries/GetNotifications/GetNotificationsHandler.cs b/src/Heimdall.Application/Notifications/Queries/GetNotifications/GetNotificationsHandler.cs index 8f0913f..24feba8 100644 --- a/src/Heimdall.Application/Notifications/Queries/GetNotifications/GetNotificationsHandler.cs +++ b/src/Heimdall.Application/Notifications/Queries/GetNotifications/GetNotificationsHandler.cs @@ -26,7 +26,7 @@ public class GetNotificationsHandler : IRequestHandler n.IsRead == request.IsRead.Value); - var totalCount = await query.CountAsync(ct); + var totalCount = await query.CountAsync(ct).ConfigureAwait(false); var items = await query .OrderByDescending(n => n.CreatedAt) diff --git a/src/Heimdall.Application/Persons/Commands/CreatePerson/CreatePersonCommand.cs b/src/Heimdall.Application/Persons/Commands/CreatePerson/CreatePersonCommand.cs index 9112e7c..3a0fdce 100644 --- a/src/Heimdall.Application/Persons/Commands/CreatePerson/CreatePersonCommand.cs +++ b/src/Heimdall.Application/Persons/Commands/CreatePerson/CreatePersonCommand.cs @@ -21,7 +21,7 @@ public class CreatePersonCommandHandler : IRequestHandler.Success(Map(person)); } diff --git a/src/Heimdall.Application/Persons/Commands/DeleteFace/DeleteFaceCommand.cs b/src/Heimdall.Application/Persons/Commands/DeleteFace/DeleteFaceCommand.cs index 2cac8da..915f4d6 100644 --- a/src/Heimdall.Application/Persons/Commands/DeleteFace/DeleteFaceCommand.cs +++ b/src/Heimdall.Application/Persons/Commands/DeleteFace/DeleteFaceCommand.cs @@ -13,12 +13,12 @@ public class DeleteFaceCommandHandler : IRequestHandler Handle(DeleteFaceCommand request, CancellationToken ct) { - var face = await _db.KnownFaces.FindAsync([request.FaceId], ct); + var face = await _db.KnownFaces.FindAsync([request.FaceId], ct).ConfigureAwait(false); if (face is null) return ServiceResult.NotFound("Face not found"); _db.KnownFaces.Remove(face); - await _db.SaveChangesWithRetryAsync(ct: ct); + await _db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); return ServiceResult.Success(); } diff --git a/src/Heimdall.Application/Persons/Commands/DeletePerson/DeletePersonCommand.cs b/src/Heimdall.Application/Persons/Commands/DeletePerson/DeletePersonCommand.cs index 395c5e2..ca77717 100644 --- a/src/Heimdall.Application/Persons/Commands/DeletePerson/DeletePersonCommand.cs +++ b/src/Heimdall.Application/Persons/Commands/DeletePerson/DeletePersonCommand.cs @@ -13,12 +13,12 @@ public class DeletePersonCommandHandler : IRequestHandler Handle(DeletePersonCommand request, CancellationToken ct) { - var person = await _db.Persons.FindAsync([request.Id], ct); + var person = await _db.Persons.FindAsync([request.Id], ct).ConfigureAwait(false); if (person is null) return ServiceResult.NotFound("Person not found"); _db.Persons.Remove(person); - await _db.SaveChangesWithRetryAsync(ct: ct); + await _db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); return ServiceResult.Success(); } diff --git a/src/Heimdall.Application/Persons/Commands/RegisterFace/RegisterFaceCommand.cs b/src/Heimdall.Application/Persons/Commands/RegisterFace/RegisterFaceCommand.cs index 0b4bd07..95ebaba 100644 --- a/src/Heimdall.Application/Persons/Commands/RegisterFace/RegisterFaceCommand.cs +++ b/src/Heimdall.Application/Persons/Commands/RegisterFace/RegisterFaceCommand.cs @@ -27,7 +27,7 @@ public class RegisterFaceCommandHandler : IRequestHandler.Success(Map(face)); } diff --git a/src/Heimdall.Application/Persons/Commands/UpdatePerson/UpdatePersonCommand.cs b/src/Heimdall.Application/Persons/Commands/UpdatePerson/UpdatePersonCommand.cs index 5a02d17..c118491 100644 --- a/src/Heimdall.Application/Persons/Commands/UpdatePerson/UpdatePersonCommand.cs +++ b/src/Heimdall.Application/Persons/Commands/UpdatePerson/UpdatePersonCommand.cs @@ -17,12 +17,12 @@ public class UpdatePersonCommandHandler : IRequestHandler> Handle(UpdatePersonCommand request, CancellationToken ct) { - var person = await _db.Persons.FindAsync([request.Id], ct); + var person = await _db.Persons.FindAsync([request.Id], ct).ConfigureAwait(false); if (person is null) return ServiceResult.NotFound("Person not found"); person.Update(request.DisplayName, request.Notes, request.Category, request.IsWatchlisted); - await _db.SaveChangesWithRetryAsync(ct: ct); + await _db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); return ServiceResult.Success(Map(person)); } diff --git a/src/Heimdall.Application/Persons/Queries/GetPersons/GetPersonsQuery.cs b/src/Heimdall.Application/Persons/Queries/GetPersons/GetPersonsQuery.cs index 0d8f120..9c10cb7 100644 --- a/src/Heimdall.Application/Persons/Queries/GetPersons/GetPersonsQuery.cs +++ b/src/Heimdall.Application/Persons/Queries/GetPersons/GetPersonsQuery.cs @@ -20,7 +20,7 @@ public class GetPersonsQueryHandler : IRequestHandler p.Category == request.Category); - var persons = await query.OrderBy(p => p.DisplayName).ToListAsync(ct); + var persons = await query.OrderBy(p => p.DisplayName).ToListAsync(ct).ConfigureAwait(false); return ServiceResult>.Success(persons.Select(Map).ToList()); } diff --git a/src/Heimdall.Application/Settings/Commands/CreateAppSetting/CreateAppSettingCommand.cs b/src/Heimdall.Application/Settings/Commands/CreateAppSetting/CreateAppSettingCommand.cs index 7d10ceb..599b246 100644 --- a/src/Heimdall.Application/Settings/Commands/CreateAppSetting/CreateAppSettingCommand.cs +++ b/src/Heimdall.Application/Settings/Commands/CreateAppSetting/CreateAppSettingCommand.cs @@ -24,7 +24,7 @@ public class CreateAppSettingCommandHandler : IRequestHandler s.Key == key, ct); + var exists = await _db.AppSettings.AnyAsync(s => s.Key == key, ct).ConfigureAwait(false); if (exists) return ServiceResult.Conflict($"Setting '{key}' already exists"); @@ -32,7 +32,7 @@ public class CreateAppSettingCommandHandler : IRequestHandler.Success(Map(setting)); } diff --git a/src/Heimdall.Application/Settings/Commands/DeleteAppSetting/DeleteAppSettingCommand.cs b/src/Heimdall.Application/Settings/Commands/DeleteAppSetting/DeleteAppSettingCommand.cs index 62ef933..730e2eb 100644 --- a/src/Heimdall.Application/Settings/Commands/DeleteAppSetting/DeleteAppSettingCommand.cs +++ b/src/Heimdall.Application/Settings/Commands/DeleteAppSetting/DeleteAppSettingCommand.cs @@ -14,12 +14,12 @@ public class DeleteAppSettingCommandHandler : IRequestHandler Handle(DeleteAppSettingCommand request, CancellationToken ct) { - var setting = await _db.AppSettings.FirstOrDefaultAsync(s => s.Key == request.Key, ct); + var setting = await _db.AppSettings.FirstOrDefaultAsync(s => s.Key == request.Key, ct).ConfigureAwait(false); if (setting is null) return ServiceResult.NotFound($"Setting '{request.Key}' not found"); _db.AppSettings.Remove(setting); - await _db.SaveChangesWithRetryAsync(ct: ct); + await _db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); return ServiceResult.Success(); } diff --git a/src/Heimdall.Application/Settings/Commands/RemoveAgentSetting/RemoveAgentSettingCommand.cs b/src/Heimdall.Application/Settings/Commands/RemoveAgentSetting/RemoveAgentSettingCommand.cs index fc34117..de9e08b 100644 --- a/src/Heimdall.Application/Settings/Commands/RemoveAgentSetting/RemoveAgentSettingCommand.cs +++ b/src/Heimdall.Application/Settings/Commands/RemoveAgentSetting/RemoveAgentSettingCommand.cs @@ -20,7 +20,7 @@ public class RemoveAgentSettingCommandHandler : IRequestHandler.Success(Map(existing)); } diff --git a/src/Heimdall.Application/Settings/Commands/UpdateAppSetting/UpdateAppSettingCommand.cs b/src/Heimdall.Application/Settings/Commands/UpdateAppSetting/UpdateAppSettingCommand.cs index ec6ec7e..797b6be 100644 --- a/src/Heimdall.Application/Settings/Commands/UpdateAppSetting/UpdateAppSettingCommand.cs +++ b/src/Heimdall.Application/Settings/Commands/UpdateAppSetting/UpdateAppSettingCommand.cs @@ -22,13 +22,13 @@ public class UpdateAppSettingCommandHandler : IRequestHandler> Handle(UpdateAppSettingCommand request, CancellationToken ct) { - var setting = await _db.AppSettings.FirstOrDefaultAsync(s => s.Key == request.Key, ct); + var setting = await _db.AppSettings.FirstOrDefaultAsync(s => s.Key == request.Key, ct).ConfigureAwait(false); if (setting is null) return ServiceResult.NotFound($"Setting '{request.Key}' not found"); setting.UpdateValue(request.Value); setting.UpdateMetadata(request.Description, request.Category, request.ValueType, request.AllowedValues); - await _db.SaveChangesWithRetryAsync(ct: ct); + await _db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); return ServiceResult.Success(Map(setting)); } diff --git a/src/Heimdall.Application/Settings/Queries/GetEffectiveAgentConfig/GetEffectiveAgentConfigQuery.cs b/src/Heimdall.Application/Settings/Queries/GetEffectiveAgentConfig/GetEffectiveAgentConfigQuery.cs index ecaa5d6..1bc684f 100644 --- a/src/Heimdall.Application/Settings/Queries/GetEffectiveAgentConfig/GetEffectiveAgentConfigQuery.cs +++ b/src/Heimdall.Application/Settings/Queries/GetEffectiveAgentConfig/GetEffectiveAgentConfigQuery.cs @@ -16,7 +16,7 @@ public class GetEffectiveAgentConfigQueryHandler public async Task>> Handle( GetEffectiveAgentConfigQuery request, CancellationToken ct) { - var appSettings = await _db.AppSettings.ToListAsync(ct); + var appSettings = await _db.AppSettings.ToListAsync(ct).ConfigureAwait(false); var config = new Dictionary(StringComparer.Ordinal); foreach (var s in appSettings) diff --git a/src/Heimdall.Application/Settings/Queries/GetSettingByKey/GetSettingByKeyQuery.cs b/src/Heimdall.Application/Settings/Queries/GetSettingByKey/GetSettingByKeyQuery.cs index 37f2808..b770271 100644 --- a/src/Heimdall.Application/Settings/Queries/GetSettingByKey/GetSettingByKeyQuery.cs +++ b/src/Heimdall.Application/Settings/Queries/GetSettingByKey/GetSettingByKeyQuery.cs @@ -16,7 +16,7 @@ public class GetSettingByKeyQueryHandler : IRequestHandler> Handle(GetSettingByKeyQuery request, CancellationToken ct) { - var setting = await _db.AppSettings.FirstOrDefaultAsync(s => s.Key == request.Key, ct); + var setting = await _db.AppSettings.FirstOrDefaultAsync(s => s.Key == request.Key, ct).ConfigureAwait(false); if (setting is null) return ServiceResult.NotFound($"Setting '{request.Key}' not found"); diff --git a/src/Heimdall.Application/Sites/Commands/CreateSite/CreateSiteHandler.cs b/src/Heimdall.Application/Sites/Commands/CreateSite/CreateSiteHandler.cs index 4ed0b77..2257911 100644 --- a/src/Heimdall.Application/Sites/Commands/CreateSite/CreateSiteHandler.cs +++ b/src/Heimdall.Application/Sites/Commands/CreateSite/CreateSiteHandler.cs @@ -14,14 +14,14 @@ public class CreateSiteHandler : IRequestHandler> Handle(CreateSiteCommand request, CancellationToken cancellationToken) { - var existing = await _context.Sites.AnyAsync(s => s.Name == request.Name, cancellationToken); + var existing = await _context.Sites.AnyAsync(s => s.Name == request.Name, cancellationToken).ConfigureAwait(false); if (existing) return ServiceResult.Conflict("A site with this name already exists"); var site = new Site(request.Name, request.Address, request.Timezone); _context.Sites.Add(site); - await _context.SaveChangesWithRetryAsync(ct: cancellationToken); + await _context.SaveChangesWithRetryAsync(ct: cancellationToken).ConfigureAwait(false); return ServiceResult.Success(new SiteResponse( site.Id, site.Name, site.Address, site.Timezone, site.Enabled, site.CreatedAt)); diff --git a/src/Heimdall.Application/Sites/Commands/DeleteSite/DeleteSiteHandler.cs b/src/Heimdall.Application/Sites/Commands/DeleteSite/DeleteSiteHandler.cs index d82a772..15b1c89 100644 --- a/src/Heimdall.Application/Sites/Commands/DeleteSite/DeleteSiteHandler.cs +++ b/src/Heimdall.Application/Sites/Commands/DeleteSite/DeleteSiteHandler.cs @@ -11,12 +11,12 @@ public class DeleteSiteHandler : IRequestHandler Handle(DeleteSiteCommand request, CancellationToken cancellationToken) { - var site = await _context.Sites.FindAsync([request.Id], cancellationToken); + var site = await _context.Sites.FindAsync([request.Id], cancellationToken).ConfigureAwait(false); if (site is null) return ServiceResult.NotFound("Site not found"); site.SoftDelete(); - await _context.SaveChangesWithRetryAsync(ct: cancellationToken); + await _context.SaveChangesWithRetryAsync(ct: cancellationToken).ConfigureAwait(false); return ServiceResult.Success(); } diff --git a/src/Heimdall.Application/Sites/Commands/GenerateSiteToken/GenerateSiteTokenHandler.cs b/src/Heimdall.Application/Sites/Commands/GenerateSiteToken/GenerateSiteTokenHandler.cs index b5221d7..41fe6e7 100644 --- a/src/Heimdall.Application/Sites/Commands/GenerateSiteToken/GenerateSiteTokenHandler.cs +++ b/src/Heimdall.Application/Sites/Commands/GenerateSiteToken/GenerateSiteTokenHandler.cs @@ -14,13 +14,13 @@ public class GenerateSiteTokenHandler : IRequestHandler> Handle(GenerateSiteTokenCommand request, CancellationToken cancellationToken) { - var site = await _context.Sites.FindAsync([request.Id], cancellationToken); + var site = await _context.Sites.FindAsync([request.Id], cancellationToken).ConfigureAwait(false); if (site is null) return ServiceResult.NotFound("Site not found"); var (plainToken, tokenHash, expiresAt) = GenerateRegistrationToken(); site.GenerateRegistrationToken(tokenHash, expiresAt); - await _context.SaveChangesWithRetryAsync(ct: cancellationToken); + await _context.SaveChangesWithRetryAsync(ct: cancellationToken).ConfigureAwait(false); return ServiceResult.Success( new RegistrationTokenResponse(plainToken, expiresAt)); diff --git a/src/Heimdall.Application/Sites/Commands/UpdateSite/UpdateSiteHandler.cs b/src/Heimdall.Application/Sites/Commands/UpdateSite/UpdateSiteHandler.cs index aada2f7..f5b1610 100644 --- a/src/Heimdall.Application/Sites/Commands/UpdateSite/UpdateSiteHandler.cs +++ b/src/Heimdall.Application/Sites/Commands/UpdateSite/UpdateSiteHandler.cs @@ -12,12 +12,12 @@ public class UpdateSiteHandler : IRequestHandler> Handle(UpdateSiteCommand request, CancellationToken cancellationToken) { - var site = await _context.Sites.FindAsync([request.Id], cancellationToken); + var site = await _context.Sites.FindAsync([request.Id], cancellationToken).ConfigureAwait(false); if (site is null) return ServiceResult.NotFound("Site not found"); site.Update(request.Name, request.Address, request.Timezone); - await _context.SaveChangesWithRetryAsync(ct: cancellationToken); + await _context.SaveChangesWithRetryAsync(ct: cancellationToken).ConfigureAwait(false); return ServiceResult.Success(new SiteResponse( site.Id, site.Name, site.Address, site.Timezone, site.Enabled, site.CreatedAt)); diff --git a/src/Heimdall.Application/Sites/Queries/GetSite/GetSiteHandler.cs b/src/Heimdall.Application/Sites/Queries/GetSite/GetSiteHandler.cs index 686c6dd..aa59d2a 100644 --- a/src/Heimdall.Application/Sites/Queries/GetSite/GetSiteHandler.cs +++ b/src/Heimdall.Application/Sites/Queries/GetSite/GetSiteHandler.cs @@ -12,7 +12,7 @@ public class GetSiteHandler : IRequestHandler> Handle(GetSiteQuery request, CancellationToken cancellationToken) { - var site = await _context.Sites.FindAsync([request.Id], cancellationToken); + var site = await _context.Sites.FindAsync([request.Id], cancellationToken).ConfigureAwait(false); if (site is null) return ServiceResult.NotFound("Site not found"); diff --git a/src/Heimdall.Application/Sites/Queries/GetSites/GetSitesHandler.cs b/src/Heimdall.Application/Sites/Queries/GetSites/GetSitesHandler.cs index 5b25a2b..8a2bfe9 100644 --- a/src/Heimdall.Application/Sites/Queries/GetSites/GetSitesHandler.cs +++ b/src/Heimdall.Application/Sites/Queries/GetSites/GetSitesHandler.cs @@ -15,7 +15,7 @@ public class GetSitesHandler : IRequestHandler s.Name); - var total = await query.CountAsync(cancellationToken); + var total = await query.CountAsync(cancellationToken).ConfigureAwait(false); var items = await query .Skip((request.Page - 1) * request.PageSize) .Take(request.PageSize) diff --git a/src/Heimdall.Application/Stats/Queries/GetAgentStats/GetAgentStatsQuery.cs b/src/Heimdall.Application/Stats/Queries/GetAgentStats/GetAgentStatsQuery.cs index 5967553..57cadf6 100644 --- a/src/Heimdall.Application/Stats/Queries/GetAgentStats/GetAgentStatsQuery.cs +++ b/src/Heimdall.Application/Stats/Queries/GetAgentStats/GetAgentStatsQuery.cs @@ -18,10 +18,10 @@ public class GetAgentStatsQueryHandler public async Task>> Handle( GetAgentStatsQuery request, CancellationToken ct) { - var totalAgents = await _db.Agents.CountAsync(ct); - var onlineAgents = await _db.Agents.CountAsync(a => a.Status == AgentStatus.Online, ct); - var offlineAgents = await _db.Agents.CountAsync(a => a.Status == AgentStatus.Offline, ct); - var errorAgents = await _db.Agents.CountAsync(a => a.Status == AgentStatus.Error, ct); + var totalAgents = await _db.Agents.CountAsync(ct).ConfigureAwait(false); + var onlineAgents = await _db.Agents.CountAsync(a => a.Status == AgentStatus.Online, ct).ConfigureAwait(false); + var offlineAgents = await _db.Agents.CountAsync(a => a.Status == AgentStatus.Offline, ct).ConfigureAwait(false); + var errorAgents = await _db.Agents.CountAsync(a => a.Status == AgentStatus.Error, ct).ConfigureAwait(false); var byVersion = await _db.Agents .AsNoTracking() diff --git a/src/Heimdall.Application/Stats/Queries/GetStats/GetStatsQuery.cs b/src/Heimdall.Application/Stats/Queries/GetStats/GetStatsQuery.cs index 1428311..7538179 100644 --- a/src/Heimdall.Application/Stats/Queries/GetStats/GetStatsQuery.cs +++ b/src/Heimdall.Application/Stats/Queries/GetStats/GetStatsQuery.cs @@ -17,13 +17,13 @@ public class GetStatsQueryHandler : IRequestHandler> Handle(GetStatsQuery request, CancellationToken ct) { // Execute queries sequentially - DbContext is not thread-safe for concurrent operations - var totalSites = await _db.Sites.CountAsync(ct); - var totalCameras = await _db.Cameras.CountAsync(ct); - var totalAgents = await _db.Agents.CountAsync(ct); - var onlineAgents = await _db.Agents.CountAsync(a => a.Status == AgentStatus.Online, ct); - var activeSites = await _db.Sites.CountAsync(s => s.Enabled, ct); - var camerasOnline = await _db.Cameras.CountAsync(c => c.Status == CameraStatus.Online, ct); - var totalUsers = await _db.Users.CountAsync(ct); + var totalSites = await _db.Sites.CountAsync(ct).ConfigureAwait(false); + var totalCameras = await _db.Cameras.CountAsync(ct).ConfigureAwait(false); + var totalAgents = await _db.Agents.CountAsync(ct).ConfigureAwait(false); + var onlineAgents = await _db.Agents.CountAsync(a => a.Status == AgentStatus.Online, ct).ConfigureAwait(false); + var activeSites = await _db.Sites.CountAsync(s => s.Enabled, ct).ConfigureAwait(false); + var camerasOnline = await _db.Cameras.CountAsync(c => c.Status == CameraStatus.Online, ct).ConfigureAwait(false); + var totalUsers = await _db.Users.CountAsync(ct).ConfigureAwait(false); return ServiceResult.Success(new StatsResponse( totalSites, diff --git a/src/Heimdall.Application/Users/Commands/AssignRoles/AssignRolesHandler.cs b/src/Heimdall.Application/Users/Commands/AssignRoles/AssignRolesHandler.cs index aeabd66..47c1b39 100644 --- a/src/Heimdall.Application/Users/Commands/AssignRoles/AssignRolesHandler.cs +++ b/src/Heimdall.Application/Users/Commands/AssignRoles/AssignRolesHandler.cs @@ -19,24 +19,24 @@ public class AssignRolesHandler : IRequestHandler Handle(AssignRolesCommand command, CancellationToken ct) { - var user = await _userManager.FindByIdAsync(command.UserId.ToString()); + var user = await _userManager.FindByIdAsync(command.UserId.ToString()).ConfigureAwait(false); if (user is null) return ServiceResult.NotFound("User not found"); - var currentRoles = await _userManager.GetRolesAsync(user); + var currentRoles = await _userManager.GetRolesAsync(user).ConfigureAwait(false); var wasAdmin = currentRoles.Contains("Admin"); var willBeAdmin = command.Roles.Contains("Admin"); if (wasAdmin && !willBeAdmin) { - var adminCount = await _repository.CountAdminUsersAsync(ct); + var adminCount = await _repository.CountAdminUsersAsync(ct).ConfigureAwait(false); if (adminCount <= 1) return ServiceResult.Failure("Cannot remove the last administrator role. " + "Promote another user to Admin first.", 400); } - await _userManager.RemoveFromRolesAsync(user, currentRoles); - await _userManager.AddToRolesAsync(user, command.Roles); + await _userManager.RemoveFromRolesAsync(user, currentRoles).ConfigureAwait(false); + await _userManager.AddToRolesAsync(user, command.Roles).ConfigureAwait(false); await _repository.AddAuditLogAsync(null, "UserRolesUpdated", "User", command.UserId.ToString(), diff --git a/src/Heimdall.Application/Users/Commands/AssignSites/AssignSitesHandler.cs b/src/Heimdall.Application/Users/Commands/AssignSites/AssignSitesHandler.cs index f7f6da5..cf66370 100644 --- a/src/Heimdall.Application/Users/Commands/AssignSites/AssignSitesHandler.cs +++ b/src/Heimdall.Application/Users/Commands/AssignSites/AssignSitesHandler.cs @@ -19,11 +19,11 @@ public class AssignSitesHandler : IRequestHandler Handle(AssignSitesCommand command, CancellationToken ct) { - var user = await _userManager.FindByIdAsync(command.UserId.ToString()); + var user = await _userManager.FindByIdAsync(command.UserId.ToString()).ConfigureAwait(false); if (user is null) return ServiceResult.NotFound("User not found"); - await _repository.SetUserSitesAsync(command.UserId, command.SiteIds, ct); + await _repository.SetUserSitesAsync(command.UserId, command.SiteIds, ct).ConfigureAwait(false); return ServiceResult.Success(); } diff --git a/src/Heimdall.Application/Users/Commands/CreateUser/CreateUserHandler.cs b/src/Heimdall.Application/Users/Commands/CreateUser/CreateUserHandler.cs index 81b1de1..630f4e3 100644 --- a/src/Heimdall.Application/Users/Commands/CreateUser/CreateUserHandler.cs +++ b/src/Heimdall.Application/Users/Commands/CreateUser/CreateUserHandler.cs @@ -20,7 +20,7 @@ public class CreateUserHandler : IRequestHandler> Handle(CreateUserCommand command, CancellationToken ct) { - var existing = await _userManager.FindByEmailAsync(command.Email); + var existing = await _userManager.FindByEmailAsync(command.Email).ConfigureAwait(false); if (existing is not null) return ServiceResult.Conflict("Email already registered"); @@ -31,18 +31,18 @@ public class CreateUserHandler : IRequestHandler.Failure( string.Join(", ", result.Errors.Select(e => e.Description))); var roles = command.Roles is { Count: > 0 } ? command.Roles : new List { "Viewer" }; - await _userManager.AddToRolesAsync(user, roles); + await _userManager.AddToRolesAsync(user, roles).ConfigureAwait(false); await _repository.AddAuditLogAsync(null, "UserCreated", "User", user.Id.ToString(), null, null, ct); - var response = await _repository.GetByIdAsync(user.Id, ct); + var response = await _repository.GetByIdAsync(user.Id, ct).ConfigureAwait(false); return ServiceResult.Success(response!); } } diff --git a/src/Heimdall.Application/Users/Commands/DeleteUser/DeleteUserHandler.cs b/src/Heimdall.Application/Users/Commands/DeleteUser/DeleteUserHandler.cs index de8322d..b46b983 100644 --- a/src/Heimdall.Application/Users/Commands/DeleteUser/DeleteUserHandler.cs +++ b/src/Heimdall.Application/Users/Commands/DeleteUser/DeleteUserHandler.cs @@ -22,22 +22,22 @@ public class DeleteUserHandler : IRequestHandler e.Description))); diff --git a/src/Heimdall.Application/Users/Commands/LockUser/LockUserHandler.cs b/src/Heimdall.Application/Users/Commands/LockUser/LockUserHandler.cs index cf19ee7..1f15069 100644 --- a/src/Heimdall.Application/Users/Commands/LockUser/LockUserHandler.cs +++ b/src/Heimdall.Application/Users/Commands/LockUser/LockUserHandler.cs @@ -19,11 +19,11 @@ public class LockUserHandler : IRequestHandler public async Task Handle(LockUserCommand command, CancellationToken ct) { - var user = await _userManager.FindByIdAsync(command.UserId.ToString()); + var user = await _userManager.FindByIdAsync(command.UserId.ToString()).ConfigureAwait(false); if (user is null) return ServiceResult.NotFound("User not found"); - await _userManager.SetLockoutEndDateAsync(user, DateTimeOffset.MaxValue); + await _userManager.SetLockoutEndDateAsync(user, DateTimeOffset.MaxValue).ConfigureAwait(false); await _repository.AddAuditLogAsync(null, "UserLocked", "User", command.UserId.ToString(), null, null, ct); diff --git a/src/Heimdall.Application/Users/Commands/ResetPassword/ResetPasswordHandler.cs b/src/Heimdall.Application/Users/Commands/ResetPassword/ResetPasswordHandler.cs index 7809428..06172a2 100644 --- a/src/Heimdall.Application/Users/Commands/ResetPassword/ResetPasswordHandler.cs +++ b/src/Heimdall.Application/Users/Commands/ResetPassword/ResetPasswordHandler.cs @@ -21,20 +21,20 @@ public class ResetPasswordHandler : IRequestHandler> Handle(ResetPasswordCommand command, CancellationToken ct) { - var user = await _userManager.FindByIdAsync(command.UserId.ToString()); + var user = await _userManager.FindByIdAsync(command.UserId.ToString()).ConfigureAwait(false); if (user is null) return ServiceResult.NotFound("User not found"); var temporaryPassword = GenerateTemporaryPassword(); - var token = await _userManager.GeneratePasswordResetTokenAsync(user); - var result = await _userManager.ResetPasswordAsync(user, token, temporaryPassword); + var token = await _userManager.GeneratePasswordResetTokenAsync(user).ConfigureAwait(false); + var result = await _userManager.ResetPasswordAsync(user, token, temporaryPassword).ConfigureAwait(false); if (!result.Succeeded) return ServiceResult.Failure( string.Join(", ", result.Errors.Select(e => e.Description))); user.MustChangePassword = true; - await _userManager.UpdateAsync(user); + await _userManager.UpdateAsync(user).ConfigureAwait(false); await _repository.AddAuditLogAsync(null, "UserPasswordReset", "User", command.UserId.ToString(), null, null, ct); diff --git a/src/Heimdall.Application/Users/Commands/UnlockUser/UnlockUserHandler.cs b/src/Heimdall.Application/Users/Commands/UnlockUser/UnlockUserHandler.cs index 21e9d0a..da8cb23 100644 --- a/src/Heimdall.Application/Users/Commands/UnlockUser/UnlockUserHandler.cs +++ b/src/Heimdall.Application/Users/Commands/UnlockUser/UnlockUserHandler.cs @@ -19,12 +19,12 @@ public class UnlockUserHandler : IRequestHandler Handle(UnlockUserCommand command, CancellationToken ct) { - var user = await _userManager.FindByIdAsync(command.UserId.ToString()); + var user = await _userManager.FindByIdAsync(command.UserId.ToString()).ConfigureAwait(false); if (user is null) return ServiceResult.NotFound("User not found"); - await _userManager.SetLockoutEndDateAsync(user, null); - await _userManager.ResetAccessFailedCountAsync(user); + await _userManager.SetLockoutEndDateAsync(user, null).ConfigureAwait(false); + await _userManager.ResetAccessFailedCountAsync(user).ConfigureAwait(false); await _repository.AddAuditLogAsync(null, "UserUnlocked", "User", command.UserId.ToString(), null, null, ct); diff --git a/src/Heimdall.Application/Users/Commands/UpdateUser/UpdateUserHandler.cs b/src/Heimdall.Application/Users/Commands/UpdateUser/UpdateUserHandler.cs index 1370cc9..95db7b3 100644 --- a/src/Heimdall.Application/Users/Commands/UpdateUser/UpdateUserHandler.cs +++ b/src/Heimdall.Application/Users/Commands/UpdateUser/UpdateUserHandler.cs @@ -20,7 +20,7 @@ public class UpdateUserHandler : IRequestHandler> Handle(UpdateUserCommand command, CancellationToken ct) { - var user = await _userManager.FindByIdAsync(command.Id.ToString()); + var user = await _userManager.FindByIdAsync(command.Id.ToString()).ConfigureAwait(false); if (user is null) return ServiceResult.NotFound("User not found"); @@ -28,12 +28,12 @@ public class UpdateUserHandler : IRequestHandler.Failure( string.Join(", ", result.Errors.Select(e => e.Description))); - var response = await _repository.GetByIdAsync(user.Id, ct); + var response = await _repository.GetByIdAsync(user.Id, ct).ConfigureAwait(false); return ServiceResult.Success(response!); } } diff --git a/src/Heimdall.Application/Users/Queries/GetMe/GetMeHandler.cs b/src/Heimdall.Application/Users/Queries/GetMe/GetMeHandler.cs index 2b3bd51..6e27f08 100644 --- a/src/Heimdall.Application/Users/Queries/GetMe/GetMeHandler.cs +++ b/src/Heimdall.Application/Users/Queries/GetMe/GetMeHandler.cs @@ -16,7 +16,7 @@ public class GetMeHandler : IRequestHandler> Handle(GetMeQuery query, CancellationToken ct) { - var user = await _repository.GetByIdAsync(query.CurrentUserId, ct); + var user = await _repository.GetByIdAsync(query.CurrentUserId, ct).ConfigureAwait(false); if (user is null) return ServiceResult.NotFound("User not found"); diff --git a/src/Heimdall.Application/Users/Queries/GetUser/GetUserHandler.cs b/src/Heimdall.Application/Users/Queries/GetUser/GetUserHandler.cs index 70f6ac7..33a766f 100644 --- a/src/Heimdall.Application/Users/Queries/GetUser/GetUserHandler.cs +++ b/src/Heimdall.Application/Users/Queries/GetUser/GetUserHandler.cs @@ -16,7 +16,7 @@ public class GetUserHandler : IRequestHandler> Handle(GetUserQuery query, CancellationToken ct) { - var user = await _repository.GetByIdAsync(query.Id, ct); + var user = await _repository.GetByIdAsync(query.Id, ct).ConfigureAwait(false); if (user is null) return ServiceResult.NotFound("User not found"); diff --git a/src/Heimdall.Application/Users/Queries/GetUsers/GetUsersHandler.cs b/src/Heimdall.Application/Users/Queries/GetUsers/GetUsersHandler.cs index d225a15..13010b5 100644 --- a/src/Heimdall.Application/Users/Queries/GetUsers/GetUsersHandler.cs +++ b/src/Heimdall.Application/Users/Queries/GetUsers/GetUsersHandler.cs @@ -16,7 +16,7 @@ public class GetUsersHandler : IRequestHandler>> Handle(GetUsersQuery query, CancellationToken ct) { - var result = await _repository.GetPagedAsync(query.Page, query.PageSize, ct); + var result = await _repository.GetPagedAsync(query.Page, query.PageSize, ct).ConfigureAwait(false); return ServiceResult>.Success(result); } } diff --git a/src/Heimdall.Infrastructure/Data/AppDbContext.cs b/src/Heimdall.Infrastructure/Data/AppDbContext.cs index 65bb3e0..5892eba 100644 --- a/src/Heimdall.Infrastructure/Data/AppDbContext.cs +++ b/src/Heimdall.Infrastructure/Data/AppDbContext.cs @@ -57,7 +57,7 @@ public class AppDbContext : IdentityDbContext, IApplicat public async Task SaveChangesWithRetryAsync(int maxRetries = 3, CancellationToken ct = default) { - await DbContextExtensions.SaveChangesWithRetryAsync(this, maxRetries, ct); + await DbContextExtensions.SaveChangesWithRetryAsync(this, maxRetries, ct).ConfigureAwait(false); } protected override void OnModelCreating(ModelBuilder builder) diff --git a/src/Heimdall.Infrastructure/Data/DbContextExtensions.cs b/src/Heimdall.Infrastructure/Data/DbContextExtensions.cs index a395578..0170bc8 100644 --- a/src/Heimdall.Infrastructure/Data/DbContextExtensions.cs +++ b/src/Heimdall.Infrastructure/Data/DbContextExtensions.cs @@ -11,12 +11,12 @@ public static class DbContextExtensions { try { - await context.SaveChangesAsync(ct); + await context.SaveChangesAsync(ct).ConfigureAwait(false); return; } catch (Exception ex) when (attempt < maxRetries && IsTransient(ex)) { - await Task.Delay(TimeSpan.FromMilliseconds(100 * Math.Pow(2, attempt - 1)), ct); + await Task.Delay(TimeSpan.FromMilliseconds(100 * Math.Pow(2, attempt - 1)), ct).ConfigureAwait(false); } } } diff --git a/src/Heimdall.Infrastructure/Jobs/AgentFailoverJob.cs b/src/Heimdall.Infrastructure/Jobs/AgentFailoverJob.cs index 420be6c..693fb4f 100644 --- a/src/Heimdall.Infrastructure/Jobs/AgentFailoverJob.cs +++ b/src/Heimdall.Infrastructure/Jobs/AgentFailoverJob.cs @@ -56,7 +56,7 @@ public sealed class AgentFailoverJob try { - var result = await _assignmentService.FailoverAgentAsync(agent.Id, ct); + var result = await _assignmentService.FailoverAgentAsync(agent.Id, ct).ConfigureAwait(false); if (result.IsSuccess && result.Data?.Count > 0) { _logger.LogWarning( @@ -70,7 +70,7 @@ public sealed class AgentFailoverJob } } - await db.SaveChangesWithRetryAsync(ct: ct); + await db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); if (staleAgents.Count > 0) { diff --git a/src/Heimdall.Infrastructure/Jobs/DailyDigestJob.cs b/src/Heimdall.Infrastructure/Jobs/DailyDigestJob.cs index a5341bc..e3b683e 100644 --- a/src/Heimdall.Infrastructure/Jobs/DailyDigestJob.cs +++ b/src/Heimdall.Infrastructure/Jobs/DailyDigestJob.cs @@ -73,7 +73,7 @@ public class DailyDigestJob

Cordialement,
L'équipe Heimdall

"""; - await _emailService.SendEmailAsync(config.EmailAddress!, subject, body, ct); + await _emailService.SendEmailAsync(config.EmailAddress!, subject, body, ct).ConfigureAwait(false); _logger.LogDebug("Daily digest sent to {Email}", config.EmailAddress); } catch (Exception ex) diff --git a/src/Heimdall.Infrastructure/Jobs/HeartbeatMonitorJob.cs b/src/Heimdall.Infrastructure/Jobs/HeartbeatMonitorJob.cs index 319f59d..027b990 100644 --- a/src/Heimdall.Infrastructure/Jobs/HeartbeatMonitorJob.cs +++ b/src/Heimdall.Infrastructure/Jobs/HeartbeatMonitorJob.cs @@ -43,6 +43,6 @@ public class HeartbeatMonitorJob agent.MarkOffline(); } - await db.SaveChangesWithRetryAsync(ct: ct); + await db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); } } diff --git a/src/Heimdall.Infrastructure/Jobs/SendNotificationJob.cs b/src/Heimdall.Infrastructure/Jobs/SendNotificationJob.cs index 30fc3e5..b1c8883 100644 --- a/src/Heimdall.Infrastructure/Jobs/SendNotificationJob.cs +++ b/src/Heimdall.Infrastructure/Jobs/SendNotificationJob.cs @@ -26,12 +26,12 @@ public class SendNotificationJob public async Task SendEmailAsync(string recipient, string subject, string bodyHtml, CancellationToken ct = default) { _logger.LogInformation("Sending email notification to {Recipient}: {Subject}", recipient, subject); - await _emailService.SendEmailAsync(recipient, subject, bodyHtml, ct); + await _emailService.SendEmailAsync(recipient, subject, bodyHtml, ct).ConfigureAwait(false); } public async Task SendNtfyAsync(string topic, string title, string message, int priority = 3, CancellationToken ct = default) { _logger.LogInformation("Sending ntfy notification: {Title}", title); - await _ntfyService.SendNotificationAsync(topic, title, message, priority, ct); + await _ntfyService.SendNotificationAsync(topic, title, message, priority, ct).ConfigureAwait(false); } } diff --git a/src/Heimdall.Infrastructure/Jobs/WeeklyDigestJob.cs b/src/Heimdall.Infrastructure/Jobs/WeeklyDigestJob.cs index 52a26a3..816338c 100644 --- a/src/Heimdall.Infrastructure/Jobs/WeeklyDigestJob.cs +++ b/src/Heimdall.Infrastructure/Jobs/WeeklyDigestJob.cs @@ -73,7 +73,7 @@ public class WeeklyDigestJob

Cordialement,
L'équipe Heimdall

"""; - await _emailService.SendEmailAsync(config.EmailAddress!, subject, body, ct); + await _emailService.SendEmailAsync(config.EmailAddress!, subject, body, ct).ConfigureAwait(false); _logger.LogDebug("Weekly digest sent to {Email}", config.EmailAddress); } catch (Exception ex) diff --git a/src/Heimdall.Infrastructure/Persistence/UserRepository.cs b/src/Heimdall.Infrastructure/Persistence/UserRepository.cs index 1eb642d..d6c553a 100644 --- a/src/Heimdall.Infrastructure/Persistence/UserRepository.cs +++ b/src/Heimdall.Infrastructure/Persistence/UserRepository.cs @@ -22,7 +22,7 @@ public class UserRepository : IUserRepository public async Task> GetPagedAsync(int page, int pageSize, CancellationToken ct) { var query = _db.Users.AsNoTracking().OrderBy(u => u.DisplayName); - var total = await query.CountAsync(ct); + var total = await query.CountAsync(ct).ConfigureAwait(false); var users = await query .Skip((page - 1) * pageSize) .Take(pageSize) @@ -56,10 +56,10 @@ public class UserRepository : IUserRepository public async Task GetByIdAsync(Guid id, CancellationToken ct) { - var user = await _userManager.FindByIdAsync(id.ToString()); + var user = await _userManager.FindByIdAsync(id.ToString()).ConfigureAwait(false); if (user is null) return null; - var roles = await _userManager.GetRolesAsync(user); + var roles = await _userManager.GetRolesAsync(user).ConfigureAwait(false); var siteIds = await _db.UserSites .Where(us => us.UserId == user.Id) .Select(us => us.SiteId) @@ -83,7 +83,7 @@ public class UserRepository : IUserRepository public async Task CountAdminUsersAsync(CancellationToken ct) { - var adminRole = await _db.Roles.FirstOrDefaultAsync(r => r.Name == AppRoles.Admin, ct); + var adminRole = await _db.Roles.FirstOrDefaultAsync(r => r.Name == AppRoles.Admin, ct).ConfigureAwait(false); if (adminRole is null) return 0; return await _db.Set>() @@ -94,32 +94,32 @@ public class UserRepository : IUserRepository string? resourceId, string? oldValue, string? newValue, CancellationToken ct) { _db.AuditLogs.Add(new AuditLog(userId, action, resourceType, resourceId, oldValue, newValue)); - await _db.SaveChangesWithRetryAsync(ct: ct); + await _db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); } public async Task SetUserSitesAsync(Guid userId, IList siteIds, CancellationToken ct) { - var existing = await _db.UserSites.Where(us => us.UserId == userId).ToListAsync(ct); + var existing = await _db.UserSites.Where(us => us.UserId == userId).ToListAsync(ct).ConfigureAwait(false); _db.UserSites.RemoveRange(existing); foreach (var siteId in siteIds) _db.UserSites.Add(new UserSite(userId, siteId)); - await _db.SaveChangesWithRetryAsync(ct: ct); + await _db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); } public async Task RemoveUserDataAsync(Guid userId, CancellationToken ct) { - var userSites = await _db.UserSites.Where(us => us.UserId == userId).ToListAsync(ct); + var userSites = await _db.UserSites.Where(us => us.UserId == userId).ToListAsync(ct).ConfigureAwait(false); _db.UserSites.RemoveRange(userSites); - var userGroups = await _db.UserGroups.Where(ug => ug.UserId == userId).ToListAsync(ct); + var userGroups = await _db.UserGroups.Where(ug => ug.UserId == userId).ToListAsync(ct).ConfigureAwait(false); _db.UserGroups.RemoveRange(userGroups); - var apiKeys = await _db.ApiKeys.Where(ak => ak.CreatedByUserId == userId).ToListAsync(ct); + var apiKeys = await _db.ApiKeys.Where(ak => ak.CreatedByUserId == userId).ToListAsync(ct).ConfigureAwait(false); _db.ApiKeys.RemoveRange(apiKeys); - await _db.SaveChangesWithRetryAsync(ct: ct); + await _db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); } private static UserResponse MapToResponse(AppUser user, List roles, List siteIds) diff --git a/src/Heimdall.Infrastructure/Security/AuthDataService.cs b/src/Heimdall.Infrastructure/Security/AuthDataService.cs index 5679f71..29dbd24 100644 --- a/src/Heimdall.Infrastructure/Security/AuthDataService.cs +++ b/src/Heimdall.Infrastructure/Security/AuthDataService.cs @@ -23,7 +23,7 @@ public class AuthDataService : IAuthDataService public async Task IsFirstUserAsync(CancellationToken ct) { - return await _db.Users.AnyAsync(ct); + return await _db.Users.AnyAsync(ct).ConfigureAwait(false); } public async Task IsRefreshTokenRevokedAsync(string tokenHash, CancellationToken ct) @@ -36,6 +36,6 @@ public class AuthDataService : IAuthDataService { _db.RevokedRefreshTokens.Add(new Heimdall.Domain.Entities.RevokedRefreshToken( refreshToken, userId, DateTime.UtcNow.AddDays(7))); - await _db.SaveChangesWithRetryAsync(ct: ct); + await _db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); } } diff --git a/src/Heimdall.Infrastructure/Security/AuthSignInService.cs b/src/Heimdall.Infrastructure/Security/AuthSignInService.cs index b282eb4..1b7c9f1 100644 --- a/src/Heimdall.Infrastructure/Security/AuthSignInService.cs +++ b/src/Heimdall.Infrastructure/Security/AuthSignInService.cs @@ -15,7 +15,7 @@ public class AuthSignInService : IAuthSignInService public async Task PasswordSignInAsync(AppUser user, string password, bool lockoutOnFailure) { - var result = await _signInManager.PasswordSignInAsync(user, password, false, lockoutOnFailure); + var result = await _signInManager.PasswordSignInAsync(user, password, false, lockoutOnFailure).ConfigureAwait(false); return result switch { { Succeeded: true } => new SignInServiceResult(SignInResultType.Success), @@ -27,6 +27,6 @@ public class AuthSignInService : IAuthSignInService public async Task SignOutAsync() { - await _signInManager.SignOutAsync(); + await _signInManager.SignOutAsync().ConfigureAwait(false); } } diff --git a/src/Heimdall.Infrastructure/Services/CameraAssignmentService.cs b/src/Heimdall.Infrastructure/Services/CameraAssignmentService.cs index cdaeba8..08a76b2 100644 --- a/src/Heimdall.Infrastructure/Services/CameraAssignmentService.cs +++ b/src/Heimdall.Infrastructure/Services/CameraAssignmentService.cs @@ -30,11 +30,11 @@ public sealed class CameraAssignmentService : ICameraAssignmentService { await using var db = await _dbFactory.CreateDbContextAsync(ct); - var camera = await db.Cameras.AsTracking().FirstOrDefaultAsync(c => c.Id == cameraId && !c.IsDeleted, ct); + var camera = await db.Cameras.AsTracking().FirstOrDefaultAsync(c => c.Id == cameraId && !c.IsDeleted, ct).ConfigureAwait(false); if (camera is null) return ServiceResult.NotFound("Camera not found"); - var agent = await db.Agents.AsTracking().FirstOrDefaultAsync(a => a.Id == agentId && !a.IsDeleted, ct); + var agent = await db.Agents.AsTracking().FirstOrDefaultAsync(a => a.Id == agentId && !a.IsDeleted, ct).ConfigureAwait(false); if (agent is null) return ServiceResult.NotFound("Agent not found"); @@ -53,7 +53,7 @@ public sealed class CameraAssignmentService : ICameraAssignmentService // Update camera.AgentId camera.AssignAgent(agentId); - await db.SaveChangesWithRetryAsync(ct: ct); + await db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); _logger.LogInformation( "Camera {CameraId} assigned to agent {AgentId} (reason: {Reason})", @@ -138,7 +138,7 @@ public sealed class CameraAssignmentService : ICameraAssignmentService assigned++; } - await db.SaveChangesWithRetryAsync(ct: ct); + await db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); _logger.LogInformation( "Site {SiteId} assignment ({Strategy}): {Assigned}/{Total} cameras assigned, {Unassigned} unassigned", @@ -197,7 +197,7 @@ public sealed class CameraAssignmentService : ICameraAssignmentService workload[bestAgent.Id] = count + 1; } - await db.SaveChangesWithRetryAsync(ct: ct); + await db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); _logger.LogWarning( "Failover for agent {AgentId}: {Total} cameras reassigned to {Agents} online agents", @@ -255,7 +255,7 @@ public sealed class CameraAssignmentService : ICameraAssignmentService if (camera is not null) camera.AssignAgent(null); // Clear agent - await db.SaveChangesWithRetryAsync(ct: ct); + await db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); _logger.LogInformation("Camera {CameraId} released from agent {AgentId}", cameraId, active.AgentId); return ServiceResult.Success(); diff --git a/src/Heimdall.Infrastructure/Services/CameraEventService.cs b/src/Heimdall.Infrastructure/Services/CameraEventService.cs index 5282ae8..3e35b96 100644 --- a/src/Heimdall.Infrastructure/Services/CameraEventService.cs +++ b/src/Heimdall.Infrastructure/Services/CameraEventService.cs @@ -29,7 +29,7 @@ public sealed class CameraEventService : ICameraEventService { await using var db = await _dbFactory.CreateDbContextAsync(ct); - var camera = await db.Cameras.FindAsync([request.CameraId], ct); + var camera = await db.Cameras.FindAsync([request.CameraId], ct).ConfigureAwait(false); if (camera is null) return ServiceResult.NotFound("Camera not found"); @@ -38,7 +38,7 @@ public sealed class CameraEventService : ICameraEventService ev.SetMetadata(request.Label, request.MetadataJson); db.CameraEvents.Add(ev); - await db.SaveChangesWithRetryAsync(ct: ct); + await db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); _logger.LogDebug( "Camera event {EventId}: {Type} (confidence={Conf}) for camera {CameraId}", @@ -54,7 +54,7 @@ public sealed class CameraEventService : ICameraEventService { using var scope = _serviceProvider.CreateScope(); var broadcast = scope.ServiceProvider.GetRequiredService(); - await broadcast.NotifyEventCreated(MapResponse(ev), CancellationToken.None); + await broadcast.NotifyEventCreated(MapResponse(ev), CancellationToken.None).ConfigureAwait(false); } catch (Exception ex) { @@ -68,7 +68,7 @@ public sealed class CameraEventService : ICameraEventService public async Task> GetByIdAsync(Guid id, CancellationToken ct) { await using var db = await _dbFactory.CreateDbContextAsync(ct); - var ev = await db.CameraEvents.AsNoTracking().Include(e => e.Camera).FirstOrDefaultAsync(e => e.Id == id, ct); + var ev = await db.CameraEvents.AsNoTracking().Include(e => e.Camera).FirstOrDefaultAsync(e => e.Id == id, ct).ConfigureAwait(false); return ev is null ? ServiceResult.NotFound("Event not found") : ServiceResult.Success(MapResponse(ev)); @@ -99,7 +99,7 @@ public sealed class CameraEventService : ICameraEventService if (filter.MinConfidence.HasValue) query = query.Where(e => e.Confidence >= filter.MinConfidence.Value); - var total = await query.CountAsync(ct); + var total = await query.CountAsync(ct).ConfigureAwait(false); var items = await query .OrderByDescending(e => e.OccurredAt) .Skip((filter.Page - 1) * pageSize) @@ -128,24 +128,24 @@ public sealed class CameraEventService : ICameraEventService public async Task DeleteAsync(Guid id, CancellationToken ct) { await using var db = await _dbFactory.CreateDbContextAsync(ct); - var ev = await db.CameraEvents.FindAsync([id], ct); + var ev = await db.CameraEvents.FindAsync([id], ct).ConfigureAwait(false); if (ev is null) return ServiceResult.NotFound("Event not found"); db.CameraEvents.Remove(ev); - await db.SaveChangesWithRetryAsync(ct: ct); + await db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); return ServiceResult.Success(); } public async Task AttachSnapshotAsync(Guid eventId, string snapshotUrl, string? thumbUrl, CancellationToken ct) { await using var db = await _dbFactory.CreateDbContextAsync(ct); - var ev = await db.CameraEvents.FindAsync([eventId], ct); + var ev = await db.CameraEvents.FindAsync([eventId], ct).ConfigureAwait(false); if (ev is null) return ServiceResult.NotFound("Event not found"); ev.SetSnapshot(snapshotUrl, thumbUrl); - await db.SaveChangesWithRetryAsync(ct: ct); + await db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); return ServiceResult.Success(); } diff --git a/src/Heimdall.Infrastructure/Services/Discovery/ArpProbeService.cs b/src/Heimdall.Infrastructure/Services/Discovery/ArpProbeService.cs index 82a8396..947cd57 100644 --- a/src/Heimdall.Infrastructure/Services/Discovery/ArpProbeService.cs +++ b/src/Heimdall.Infrastructure/Services/Discovery/ArpProbeService.cs @@ -92,7 +92,7 @@ public sealed partial class ArpProbeService : IArpProbeService return null; } - var arpContent = await File.ReadAllTextAsync("/proc/net/arp", ct); + var arpContent = await File.ReadAllTextAsync("/proc/net/arp", ct).ConfigureAwait(false); foreach (var line in arpContent.Split('\n', StringSplitOptions.RemoveEmptyEntries)) { diff --git a/src/Heimdall.Infrastructure/Services/Discovery/CameraDiscoveryService.cs b/src/Heimdall.Infrastructure/Services/Discovery/CameraDiscoveryService.cs index 4d66256..92661a2 100644 --- a/src/Heimdall.Infrastructure/Services/Discovery/CameraDiscoveryService.cs +++ b/src/Heimdall.Infrastructure/Services/Discovery/CameraDiscoveryService.cs @@ -119,13 +119,13 @@ public sealed class CameraDiscoveryService : ICameraDiscoveryService var arpTask = _arp.ProbeAsync(request.Ip, ct); var portTask = _portScan.ScanAsync(request.Ip, ct); - await Task.WhenAll(onvifTask, mdnsTask, httpTask, arpTask, portTask); + await Task.WhenAll(onvifTask, mdnsTask, httpTask, arpTask, portTask).ConfigureAwait(false); - var onvifInfo = await onvifTask; - var mdnsInfo = await mdnsTask; - var httpInfo = await httpTask; - var arpInfo = await arpTask; - var openPorts = await portTask; + var onvifInfo = await onvifTask.ConfigureAwait(false); + var mdnsInfo = await mdnsTask.ConfigureAwait(false); + var httpInfo = await httpTask.ConfigureAwait(false); + var arpInfo = await arpTask.ConfigureAwait(false); + var openPorts = await portTask.ConfigureAwait(false); // Determine camera type and discovery method var (cameraType, discoveryMethod) = ClassifyCamera(onvifInfo, mdnsInfo, httpInfo, openPorts); @@ -179,11 +179,11 @@ public sealed class CameraDiscoveryService : ICameraDiscoveryService { if (ct.IsCancellationRequested) return; - await throttler.WaitAsync(ct); + await throttler.WaitAsync(ct).ConfigureAwait(false); try { var probeRequest = new ProbeRequest(request.SiteId, ip); - var result = await ProbeIpAsync(probeRequest, ct); + var result = await ProbeIpAsync(probeRequest, ct).ConfigureAwait(false); if (result.IsSuccess && result.Data is not null) { results.Add(result.Data); @@ -206,7 +206,7 @@ public sealed class CameraDiscoveryService : ICameraDiscoveryService try { - await Task.WhenAll(tasks).WaitAsync(timeoutCts.Token); + await Task.WhenAll(tasks).WaitAsync(timeoutCts.Token).ConfigureAwait(false); } catch (OperationCanceledException) when (!ct.IsCancellationRequested) { @@ -296,14 +296,14 @@ public sealed class CameraDiscoveryService : ICameraDiscoveryService return ServiceResult.Failure("No stream URLs provided"); var appRequest = new Application.DTOs.StreamTestRequest(request.SourceId, request.Streams); - var session = await _streamTester.CreateSessionAsync(appRequest, ct); + var session = await _streamTester.CreateSessionAsync(appRequest, ct).ConfigureAwait(false); return ServiceResult.Success(session); } public async Task> GetTestSessionAsync(Guid sessionId, CancellationToken ct) { - var session = await _streamTester.GetSessionAsync(sessionId, ct); + var session = await _streamTester.GetSessionAsync(sessionId, ct).ConfigureAwait(false); if (session is null) return ServiceResult.NotFound("Test session not found"); @@ -312,7 +312,7 @@ public sealed class CameraDiscoveryService : ICameraDiscoveryService public async Task GetScreenshotAsync(Guid sessionId, int index, CancellationToken ct) { - await Task.CompletedTask; + await Task.CompletedTask.ConfigureAwait(false); _logger.LogWarning("Screenshot requested but not yet implemented (session={SessionId}, index={Index})", sessionId, index); return null; @@ -320,7 +320,7 @@ public sealed class CameraDiscoveryService : ICameraDiscoveryService public async Task CancelTestSessionAsync(Guid sessionId, CancellationToken ct) { - await _streamTester.CancelSessionAsync(sessionId, ct); + await _streamTester.CancelSessionAsync(sessionId, ct).ConfigureAwait(false); return ServiceResult.Success(); } @@ -330,7 +330,7 @@ public sealed class CameraDiscoveryService : ICameraDiscoveryService { await using var db = await _dbFactory.CreateDbContextAsync(ct); - var site = await db.Sites.FindAsync([request.SiteId], ct); + var site = await db.Sites.FindAsync([request.SiteId], ct).ConfigureAwait(false); if (site is null) return ServiceResult.NotFound("Site not found"); @@ -342,7 +342,7 @@ public sealed class CameraDiscoveryService : ICameraDiscoveryService return ServiceResult.NotFound("Discovery result not found"); // ── Anti-duplication: check existing cameras ────────────────── - var dupCheck = await FindDuplicateCameraAsync(db, request.SiteId, discoveryResult.IpAddress, discoveryResult.MacAddress, ct); + var dupCheck = await FindDuplicateCameraAsync(db, request.SiteId, discoveryResult.IpAddress, discoveryResult.MacAddress, ct).ConfigureAwait(false); if (dupCheck is not null) { _logger.LogWarning( @@ -411,7 +411,7 @@ public sealed class CameraDiscoveryService : ICameraDiscoveryService db.Cameras.Add(camera); discoveryResult.MarkProcessed(); - await db.SaveChangesWithRetryAsync(ct: ct); + await db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); _logger.LogInformation( "Camera '{Name}' created from discovery result {ResultId} (IP={Ip}, MAC={Mac})", @@ -425,7 +425,7 @@ public sealed class CameraDiscoveryService : ICameraDiscoveryService { await using var db = await _dbFactory.CreateDbContextAsync(ct); - var dup = await FindDuplicateCameraAsync(db, request.SiteId, request.Ip, request.Mac, ct); + var dup = await FindDuplicateCameraAsync(db, request.SiteId, request.Ip, request.Mac, ct).ConfigureAwait(false); return ServiceResult.Success(new CameraCheckResponse( dup is not null, diff --git a/src/Heimdall.Infrastructure/Services/Discovery/HttpProbeService.cs b/src/Heimdall.Infrastructure/Services/Discovery/HttpProbeService.cs index df4e37b..f031ed2 100644 --- a/src/Heimdall.Infrastructure/Services/Discovery/HttpProbeService.cs +++ b/src/Heimdall.Infrastructure/Services/Discovery/HttpProbeService.cs @@ -33,7 +33,7 @@ public sealed class HttpProbeService : IHttpProbeService // Probe all HTTP ports in parallel, take first positive result var tasks = HttpPorts.Select(port => ProbePortAsync(ipAddress, port, cts.Token)); - var results = await Task.WhenAll(tasks); + var results = await Task.WhenAll(tasks).ConfigureAwait(false); var firstHit = results.FirstOrDefault(r => r is not null); return firstHit; @@ -60,7 +60,7 @@ public sealed class HttpProbeService : IHttpProbeService ? $"https://{ipAddress}:{port}/" : $"http://{ipAddress}:{port}/"; - using var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, ct); + using var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, ct).ConfigureAwait(false); var serverHeader = response.Headers.Server?.FirstOrDefault()?.ToString(); var statusCode = (int)response.StatusCode; diff --git a/src/Heimdall.Infrastructure/Services/Discovery/MdnsProbeService.cs b/src/Heimdall.Infrastructure/Services/Discovery/MdnsProbeService.cs index b939851..6c1a245 100644 --- a/src/Heimdall.Infrastructure/Services/Discovery/MdnsProbeService.cs +++ b/src/Heimdall.Infrastructure/Services/Discovery/MdnsProbeService.cs @@ -40,7 +40,7 @@ public sealed class MdnsProbeService : IMdnsProbeService { if (ct.IsCancellationRequested) break; - var result = await QueryServiceTypeAsync(ipAddress, serviceType, ct); + var result = await QueryServiceTypeAsync(ipAddress, serviceType, ct).ConfigureAwait(false); if (result is not null) { // If it's a HomeKit device, parse HomeKit-specific info @@ -76,10 +76,10 @@ public sealed class MdnsProbeService : IMdnsProbeService // Build a DNS-SD PTR query for the service type var query = BuildPtrQuery(serviceType); - await udpClient.SendAsync(query, ct); + await udpClient.SendAsync(query, ct).ConfigureAwait(false); // Try to receive within timeout - var result = await udpClient.ReceiveAsync(ct); + var result = await udpClient.ReceiveAsync(ct).ConfigureAwait(false); var responseBytes = result.Buffer; return ParseMdnsResponse(responseBytes); diff --git a/src/Heimdall.Infrastructure/Services/Discovery/OnvifProbeService.cs b/src/Heimdall.Infrastructure/Services/Discovery/OnvifProbeService.cs index dd3aaf0..e7823d3 100644 --- a/src/Heimdall.Infrastructure/Services/Discovery/OnvifProbeService.cs +++ b/src/Heimdall.Infrastructure/Services/Discovery/OnvifProbeService.cs @@ -47,10 +47,10 @@ public sealed class OnvifProbeService : IOnvifProbeService udpClient.Connect(ipAddress, port); var probeMessage = BuildProbeMessage(); - await udpClient.SendAsync(probeMessage, ct); + await udpClient.SendAsync(probeMessage, ct).ConfigureAwait(false); // Step 2: Receive response - var result = await udpClient.ReceiveAsync(ct); + var result = await udpClient.ReceiveAsync(ct).ConfigureAwait(false); var responseXml = Encoding.UTF8.GetString(result.Buffer); // Step 3: Parse ProbeMatch @@ -63,7 +63,7 @@ public sealed class OnvifProbeService : IOnvifProbeService // Step 4: Try to get device information from first XAddr var deviceUrl = xaddrs[0]; - var deviceInfo = await GetDeviceInformationAsync(deviceUrl, ct); + var deviceInfo = await GetDeviceInformationAsync(deviceUrl, ct).ConfigureAwait(false); _logger.LogDebug( "ONVIF device found at {Ip}:{Port} — {Name} ({Hardware})", @@ -156,11 +156,11 @@ public sealed class OnvifProbeService : IOnvifProbeService "; using var content = new StringContent(soapBody, Encoding.UTF8, "application/soap+xml"); - using var response = await client.PostAsync(deviceServiceUrl, content, ct); + using var response = await client.PostAsync(deviceServiceUrl, content, ct).ConfigureAwait(false); if (!response.IsSuccessStatusCode) return null; - var responseXml = await response.Content.ReadAsStringAsync(ct); + var responseXml = await response.Content.ReadAsStringAsync(ct).ConfigureAwait(false); var doc = XDocument.Parse(responseXml); var body = doc.Root?.Element(SoapNs + "Body"); diff --git a/src/Heimdall.Infrastructure/Services/Discovery/PortScanService.cs b/src/Heimdall.Infrastructure/Services/Discovery/PortScanService.cs index e0e0cb0..8db5b9b 100644 --- a/src/Heimdall.Infrastructure/Services/Discovery/PortScanService.cs +++ b/src/Heimdall.Infrastructure/Services/Discovery/PortScanService.cs @@ -49,7 +49,7 @@ public sealed class PortScanService : IPortScanService var openPorts = new List(); var tasks = CameraPorts.Select(port => TryConnectAsync(ipAddress, port, ct)); - var results = await Task.WhenAll(tasks); + var results = await Task.WhenAll(tasks).ConfigureAwait(false); for (int i = 0; i < results.Length; i++) { if (results[i]) @@ -87,7 +87,7 @@ public sealed class PortScanService : IPortScanService try { - await socket.ConnectAsync(ipAddress, port, linkedCts.Token).AsTask(); + await socket.ConnectAsync(ipAddress, port, linkedCts.Token).AsTask().ConfigureAwait(false); return socket.Connected; } catch (OperationCanceledException) when (!ct.IsCancellationRequested) diff --git a/src/Heimdall.Infrastructure/Services/Discovery/StreamTesterService.cs b/src/Heimdall.Infrastructure/Services/Discovery/StreamTesterService.cs index 1e37e1f..3214b53 100644 --- a/src/Heimdall.Infrastructure/Services/Discovery/StreamTesterService.cs +++ b/src/Heimdall.Infrastructure/Services/Discovery/StreamTesterService.cs @@ -86,14 +86,14 @@ public sealed partial class StreamTesterService { if (session.IsCancelled) break; - await throttler.WaitAsync(ct); + await throttler.WaitAsync(ct).ConfigureAwait(false); var urlCopy = url; tasks.Add(Task.Run(async () => { try { - var result = await TestSingleUrlAsync(urlCopy, ct); + var result = await TestSingleUrlAsync(urlCopy, ct).ConfigureAwait(false); session.AddResult(result); } catch (Exception ex) @@ -109,7 +109,7 @@ public sealed partial class StreamTesterService }, ct)); } - await Task.WhenAll(tasks); + await Task.WhenAll(tasks).ConfigureAwait(false); session.MarkDone(); _logger.LogInformation( @@ -126,7 +126,7 @@ public sealed partial class StreamTesterService // Schedule cleanup regardless of success/failure _ = Task.Run(async () => { - await Task.Delay(SessionTtl, CancellationToken.None); + await Task.Delay(SessionTtl, CancellationToken.None).ConfigureAwait(false); _sessions.TryRemove(sessionId, out _); }, CancellationToken.None); } @@ -154,7 +154,7 @@ public sealed partial class StreamTesterService cts.CancelAfter(RtspTimeout); using var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - await socket.ConnectAsync(uri.Host, uri.Port, cts.Token); + await socket.ConnectAsync(uri.Host, uri.Port, cts.Token).ConfigureAwait(false); sw.Stop(); var latencyMs = sw.ElapsedMilliseconds; @@ -162,10 +162,10 @@ public sealed partial class StreamTesterService // Send RTSP DESCRIBE to get stream info var describeRequest = $"DESCRIBE {url} RTSP/1.0\r\nCSeq: 1\r\nAccept: application/sdp\r\nUser-Agent: Heimdall/1.0\r\n\r\n"; var bytes = Encoding.ASCII.GetBytes(describeRequest); - await socket.SendAsync(bytes, SocketFlags.None, cts.Token); + await socket.SendAsync(bytes, SocketFlags.None, cts.Token).ConfigureAwait(false); var buffer = new byte[4096]; - var received = await socket.ReceiveAsync(buffer, SocketFlags.None, cts.Token); + var received = await socket.ReceiveAsync(buffer, SocketFlags.None, cts.Token).ConfigureAwait(false); var response = Encoding.ASCII.GetString(buffer, 0, received); var codecs = ParseSdpCodecs(response); @@ -192,7 +192,7 @@ public sealed partial class StreamTesterService var client = _httpClientFactory.CreateClient("Discovery"); client.Timeout = HttpTimeout; - using var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, cts.Token); + using var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, cts.Token).ConfigureAwait(false); sw.Stop(); if (!response.IsSuccessStatusCode) @@ -223,7 +223,7 @@ public sealed partial class StreamTesterService using var cts = CancellationTokenSource.CreateLinkedTokenSource(ct); cts.CancelAfter(RtspTimeout); - await socket.ConnectAsync(uri.Host, uri.Port, cts.Token); + await socket.ConnectAsync(uri.Host, uri.Port, cts.Token).ConfigureAwait(false); sw.Stop(); return new Application.DTOs.StreamTestResult(url, [], 0, 0, sw.ElapsedMilliseconds, null, true); diff --git a/src/Heimdall.Infrastructure/Services/EmailService.cs b/src/Heimdall.Infrastructure/Services/EmailService.cs index e6568db..009d306 100644 --- a/src/Heimdall.Infrastructure/Services/EmailService.cs +++ b/src/Heimdall.Infrastructure/Services/EmailService.cs @@ -66,7 +66,7 @@ public class EmailService : IEmailService client.Credentials = new NetworkCredential(_username, _password); } - await client.SendMailAsync(message, ct); + await client.SendMailAsync(message, ct).ConfigureAwait(false); _logger.LogDebug("Email sent to {To}: {Subject}", recipient, subject); } catch (OperationCanceledException) diff --git a/src/Heimdall.Infrastructure/Services/NotificationService.cs b/src/Heimdall.Infrastructure/Services/NotificationService.cs index 6cb3599..22a3359 100644 --- a/src/Heimdall.Infrastructure/Services/NotificationService.cs +++ b/src/Heimdall.Infrastructure/Services/NotificationService.cs @@ -78,15 +78,15 @@ public class NotificationService : INotificationService userId, title, message, type, eventType, cameraId, siteId, snapshotUrl, link); _context.Notifications.Add(notification); - await _context.SaveChangesWithRetryAsync(ct: ct); + await _context.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); var dto = _mapper.Map(notification); // Broadcast in-app - await _broadcast.NotifyNewNotification(dto, ct); + await _broadcast.NotifyNewNotification(dto, ct).ConfigureAwait(false); // Send via email/ntfy if user has config - await DispatchToExternalChannelsAsync(notification, userId, ct); + await DispatchToExternalChannelsAsync(notification, userId, ct).ConfigureAwait(false); return ServiceResult.Success(dto); } @@ -139,7 +139,7 @@ public class NotificationService : INotificationService if (isRead.HasValue) query = query.Where(n => n.IsRead == isRead.Value); - var totalCount = await query.CountAsync(ct); + var totalCount = await query.CountAsync(ct).ConfigureAwait(false); var items = await query .OrderByDescending(n => n.CreatedAt) .Skip((page - 1) * pageSize) @@ -158,7 +158,7 @@ public class NotificationService : INotificationService if (notification is not null) { notification.MarkAsRead(); - await _context.SaveChangesWithRetryAsync(ct: ct); + await _context.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); } } @@ -171,6 +171,6 @@ public class NotificationService : INotificationService foreach (var notification in unread) notification.MarkAsRead(); - await _context.SaveChangesWithRetryAsync(ct: ct); + await _context.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); } } diff --git a/src/Heimdall.Infrastructure/Services/NtfyService.cs b/src/Heimdall.Infrastructure/Services/NtfyService.cs index ad72e35..a38aa8d 100644 --- a/src/Heimdall.Infrastructure/Services/NtfyService.cs +++ b/src/Heimdall.Infrastructure/Services/NtfyService.cs @@ -39,10 +39,10 @@ public class NtfyService : INtfyService client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _authToken); - var response = await client.PostAsync(requestUrl, content, ct); + var response = await client.PostAsync(requestUrl, content, ct).ConfigureAwait(false); if (!response.IsSuccessStatusCode) { - var body = await response.Content.ReadAsStringAsync(ct); + var body = await response.Content.ReadAsStringAsync(ct).ConfigureAwait(false); _logger.LogWarning("ntfy returned {StatusCode} for topic {Topic}: {Body}", response.StatusCode, topic, body); } } diff --git a/src/Heimdall.Infrastructure/Services/PersonService.cs b/src/Heimdall.Infrastructure/Services/PersonService.cs index b001cc9..3800115 100644 --- a/src/Heimdall.Infrastructure/Services/PersonService.cs +++ b/src/Heimdall.Infrastructure/Services/PersonService.cs @@ -26,7 +26,7 @@ public sealed class PersonService : IPersonService await using var db = await _dbFactory.CreateDbContextAsync(ct); db.Persons.Add(person); - await db.SaveChangesWithRetryAsync(ct: ct); + await db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); _logger.LogInformation("Person created: {PersonId} ({Name})", person.Id, person.DisplayName); return ServiceResult.Success(Map(person)); @@ -35,11 +35,11 @@ public sealed class PersonService : IPersonService public async Task> UpdateAsync(Guid id, UpdatePersonRequest request, CancellationToken ct) { await using var db = await _dbFactory.CreateDbContextAsync(ct); - var person = await db.Persons.FindAsync([id], ct); + var person = await db.Persons.FindAsync([id], ct).ConfigureAwait(false); if (person is null) return ServiceResult.NotFound("Person not found"); person.Update(request.DisplayName, request.Notes, request.Category, request.IsWatchlisted); - await db.SaveChangesWithRetryAsync(ct: ct); + await db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); return ServiceResult.Success(Map(person)); } @@ -47,7 +47,7 @@ public sealed class PersonService : IPersonService public async Task> GetByIdAsync(Guid id, CancellationToken ct) { await using var db = await _dbFactory.CreateDbContextAsync(ct); - var person = await db.Persons.Include(p => p.Faces).FirstOrDefaultAsync(p => p.Id == id, ct); + var person = await db.Persons.Include(p => p.Faces).FirstOrDefaultAsync(p => p.Id == id, ct).ConfigureAwait(false); return person is null ? ServiceResult.NotFound("Person not found") : ServiceResult.Success(Map(person)); @@ -60,30 +60,30 @@ public sealed class PersonService : IPersonService if (!string.IsNullOrEmpty(category)) query = query.Where(p => p.Category == category); - var persons = await query.OrderBy(p => p.DisplayName).ToListAsync(ct); + var persons = await query.OrderBy(p => p.DisplayName).ToListAsync(ct).ConfigureAwait(false); return ServiceResult>.Success(persons.Select(Map).ToList()); } public async Task DeleteAsync(Guid id, CancellationToken ct) { await using var db = await _dbFactory.CreateDbContextAsync(ct); - var person = await db.Persons.FindAsync([id], ct); + var person = await db.Persons.FindAsync([id], ct).ConfigureAwait(false); if (person is null) return ServiceResult.NotFound("Person not found"); db.Persons.Remove(person); - await db.SaveChangesWithRetryAsync(ct: ct); + await db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); return ServiceResult.Success(); } public async Task> RegisterFaceAsync(RegisterFaceRequest request, CancellationToken ct) { await using var db = await _dbFactory.CreateDbContextAsync(ct); - var person = await db.Persons.Include(p => p.Faces).FirstOrDefaultAsync(p => p.Id == request.PersonId, ct); + var person = await db.Persons.Include(p => p.Faces).FirstOrDefaultAsync(p => p.Id == request.PersonId, ct).ConfigureAwait(false); if (person is null) return ServiceResult.NotFound("Person not found"); var face = new KnownFace(request.PersonId, request.Embedding, request.ThumbnailUrl, request.SourceEventId); person.AddFace(face); - await db.SaveChangesWithRetryAsync(ct: ct); + await db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); return ServiceResult.Success(MapFace(face)); } @@ -102,11 +102,11 @@ public sealed class PersonService : IPersonService public async Task DeleteFaceAsync(Guid faceId, CancellationToken ct) { await using var db = await _dbFactory.CreateDbContextAsync(ct); - var face = await db.KnownFaces.FindAsync([faceId], ct); + var face = await db.KnownFaces.FindAsync([faceId], ct).ConfigureAwait(false); if (face is null) return ServiceResult.NotFound("Face not found"); db.KnownFaces.Remove(face); - await db.SaveChangesWithRetryAsync(ct: ct); + await db.SaveChangesWithRetryAsync(ct: ct).ConfigureAwait(false); return ServiceResult.Success(); } diff --git a/tests/Heimdall.Application.Tests/Handlers/Cameras/CreateCameraHandlerTests.cs b/tests/Heimdall.Application.Tests/Handlers/Cameras/CreateCameraHandlerTests.cs index 078678b..c16a20c 100644 --- a/tests/Heimdall.Application.Tests/Handlers/Cameras/CreateCameraHandlerTests.cs +++ b/tests/Heimdall.Application.Tests/Handlers/Cameras/CreateCameraHandlerTests.cs @@ -52,6 +52,6 @@ public class CreateCameraHandlerTests await handler.Handle(command, CancellationToken.None); - await context.Received(1).SaveChangesAsync(Arg.Any()); + await context.Received(1).SaveChangesWithRetryAsync(ct: Arg.Any()); } } diff --git a/tests/Heimdall.Application.Tests/Handlers/Cameras/DeleteCameraHandlerTests.cs b/tests/Heimdall.Application.Tests/Handlers/Cameras/DeleteCameraHandlerTests.cs index e6c3f96..acd3ebd 100644 --- a/tests/Heimdall.Application.Tests/Handlers/Cameras/DeleteCameraHandlerTests.cs +++ b/tests/Heimdall.Application.Tests/Handlers/Cameras/DeleteCameraHandlerTests.cs @@ -49,6 +49,6 @@ public class DeleteCameraHandlerTests _existingCamera.IsDeleted.ShouldBeTrue(); _existingCamera.DeletedAt.ShouldNotBeNull(); - await context.Received(1).SaveChangesAsync(Arg.Any()); + await context.Received(1).SaveChangesWithRetryAsync(ct: Arg.Any()); } } diff --git a/tests/Heimdall.Application.Tests/Handlers/Cameras/SetCameraCredentialsHandlerTests.cs b/tests/Heimdall.Application.Tests/Handlers/Cameras/SetCameraCredentialsHandlerTests.cs index 6119a2d..5e056be 100644 --- a/tests/Heimdall.Application.Tests/Handlers/Cameras/SetCameraCredentialsHandlerTests.cs +++ b/tests/Heimdall.Application.Tests/Handlers/Cameras/SetCameraCredentialsHandlerTests.cs @@ -72,6 +72,6 @@ public class SetCameraCredentialsHandlerTests await handler.Handle(command, CancellationToken.None); - await context.Received(1).SaveChangesAsync(Arg.Any()); + await context.Received(1).SaveChangesWithRetryAsync(ct: Arg.Any()); } } diff --git a/tests/Heimdall.Application.Tests/Handlers/Cameras/UpdateCameraHandlerTests.cs b/tests/Heimdall.Application.Tests/Handlers/Cameras/UpdateCameraHandlerTests.cs index b5015f2..4c5e09e 100644 --- a/tests/Heimdall.Application.Tests/Handlers/Cameras/UpdateCameraHandlerTests.cs +++ b/tests/Heimdall.Application.Tests/Handlers/Cameras/UpdateCameraHandlerTests.cs @@ -65,6 +65,6 @@ public class UpdateCameraHandlerTests await handler.Handle(command, CancellationToken.None); - await context.Received(1).SaveChangesAsync(Arg.Any()); + await context.Received(1).SaveChangesWithRetryAsync(ct: Arg.Any()); } }