|
1 | 1 | //+:cnd:noEmit |
| 2 | +using System.Runtime.CompilerServices; |
2 | 3 | using Boilerplate.Server.Api.Controllers.Identity; |
3 | 4 | using Boilerplate.Server.Api.Models.Identity; |
4 | 5 | using Boilerplate.Shared.Dtos.Diagnostic; |
@@ -66,17 +67,30 @@ public Task ChangeAuthenticationState(string? accessToken) |
66 | 67 | /// <inheritdoc cref="SignalRMethods.UPLOAD_DIAGNOSTIC_LOGGER_STORE"/> |
67 | 68 | /// </summary> |
68 | 69 | [Authorize(Policy = AppFeatures.System.ManageLogs)] |
69 | | - public async Task<DiagnosticLogDto[]> GetUserSessionLogs(Guid userSessionId, [FromServices] AppDbContext dbContext) |
| 70 | + public async IAsyncEnumerable<DiagnosticLogDto> GetUserSessionLogs( |
| 71 | + Guid userSessionId, |
| 72 | + [EnumeratorCancellation] CancellationToken cancellationToken, |
| 73 | + [FromServices] AppDbContext dbContext) |
70 | 74 | { |
71 | 75 | var userSessionSignalRConnectionId = await dbContext.UserSessions |
72 | 76 | .Where(us => us.Id == userSessionId) |
73 | 77 | .Select(us => us.SignalRConnectionId) |
74 | | - .FirstOrDefaultAsync(Context.ConnectionAborted); |
| 78 | + .FirstOrDefaultAsync(cancellationToken); |
75 | 79 |
|
76 | 80 | if (string.IsNullOrEmpty(userSessionSignalRConnectionId)) |
77 | | - return []; |
| 81 | + yield break; |
78 | 82 |
|
79 | | - return await Clients.Client(userSessionSignalRConnectionId).InvokeAsync<DiagnosticLogDto[]>(SignalRMethods.UPLOAD_DIAGNOSTIC_LOGGER_STORE, Context.ConnectionAborted); |
| 83 | + var logs = await Clients.Client(userSessionSignalRConnectionId) |
| 84 | + .InvokeAsync<DiagnosticLogDto[]>(SignalRMethods.UPLOAD_DIAGNOSTIC_LOGGER_STORE, cancellationToken); |
| 85 | + |
| 86 | + if (logs is null || logs.Length is 0) |
| 87 | + yield break; |
| 88 | + |
| 89 | + foreach (var log in logs) |
| 90 | + { |
| 91 | + cancellationToken.ThrowIfCancellationRequested(); |
| 92 | + yield return log; |
| 93 | + } |
80 | 94 | } |
81 | 95 |
|
82 | 96 | private async Task ChangeAuthenticationStateImplementation(ClaimsPrincipal? user) |
|
0 commit comments