diff --git a/SfeduSchedule/Services/ModeusEmployeeService.cs b/SfeduSchedule/Services/ModeusEmployeeService.cs index 0505847..cc8888f 100644 --- a/SfeduSchedule/Services/ModeusEmployeeService.cs +++ b/SfeduSchedule/Services/ModeusEmployeeService.cs @@ -36,10 +36,6 @@ public class ModeusEmployeeService(ILogger logger, Modeus _employees = employees; logger.LogInformationHere($"Получено {employees.Count} сотрудников из Modeus."); } - - await Task.Delay(TimeSpan.FromSeconds(5), _cts.Token); - GC.Collect(); - GC.WaitForPendingFinalizers(); } catch (OperationCanceledException) { diff --git a/SfeduSchedule/Services/ModeusHttpClient.cs b/SfeduSchedule/Services/ModeusHttpClient.cs index 557ec0e..6860b3f 100644 --- a/SfeduSchedule/Services/ModeusHttpClient.cs +++ b/SfeduSchedule/Services/ModeusHttpClient.cs @@ -1,6 +1,6 @@ using System.Diagnostics; -using System.Text; using System.Text.Json; +using System.Net.Http.Json; using Microsoft.Net.Http.Headers; using ModeusSchedule.Abstractions; using ModeusSchedule.Abstractions.DTO; @@ -40,8 +40,7 @@ public class ModeusHttpClient { using var request = new HttpRequestMessage(HttpMethod.Post, $"schedule-calendar-v2/api/calendar/events/search?tz={_configuration["TZ"]!}"); - request.Content = new StringContent(JsonSerializer.Serialize(msr, GlobalConsts.JsonSerializerOptions), - Encoding.UTF8, "application/json"); + request.Content = JsonContent.Create(msr, options: GlobalConsts.JsonSerializerOptions); using var response = await _httpClient.SendAsync(request); if (response.StatusCode != System.Net.HttpStatusCode.OK) { @@ -60,11 +59,13 @@ public class ModeusHttpClient { _logger.LogErrorHere($"Неуспешный статус при получении расписания: {response.StatusCode}, eventId: {eventId}"); } - List? attendees; try { - attendees = Attendees.FromJson(await response.Content.ReadAsStringAsync()); - return attendees; + await using var contentStream = await response.Content.ReadAsStreamAsync(); + var attendees = await JsonSerializer.DeserializeAsync>( + contentStream, + GlobalConsts.JsonSerializerOptions); + return attendees ?? []; } catch (Exception ex) { @@ -78,9 +79,7 @@ public class ModeusHttpClient { using var request = new HttpRequestMessage(HttpMethod.Post, $"schedule-calendar-v2/api/people/persons/search"); - request.Content = new StringContent( - JsonSerializer.Serialize(modeusSearchPersonRequest, GlobalConsts.JsonSerializerOptions), - Encoding.UTF8, "application/json"); + request.Content = JsonContent.Create(modeusSearchPersonRequest, options: GlobalConsts.JsonSerializerOptions); var stopwatch = Stopwatch.StartNew(); using var response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead); var requestMs = stopwatch.ElapsedMilliseconds; @@ -114,9 +113,7 @@ public class ModeusHttpClient public async Task SearchRoomsAsync(RoomSearchRequest requestDto) { using var request = new HttpRequestMessage(HttpMethod.Post, "schedule-calendar-v2/api/campus/rooms/search"); - request.Content = - new StringContent(JsonSerializer.Serialize(requestDto, GlobalConsts.JsonSerializerOptions), - Encoding.UTF8, "application/json"); + request.Content = JsonContent.Create(requestDto, options: GlobalConsts.JsonSerializerOptions); using var response = await _httpClient.SendAsync(request); if (response.StatusCode != System.Net.HttpStatusCode.OK) {