Рефакторинг
This commit is contained in:
		| @@ -1,5 +1,7 @@ | |||||||
| using Microsoft.Playwright; |  | ||||||
| using System.Text.RegularExpressions; | using System.Text.RegularExpressions; | ||||||
|  | using Microsoft.Playwright; | ||||||
|  | 
 | ||||||
|  | namespace SfeduSchedule.BrowserScripts; | ||||||
| 
 | 
 | ||||||
| public static class MicrosoftLoginHelper | public static class MicrosoftLoginHelper | ||||||
| { | { | ||||||
| @@ -32,7 +32,7 @@ public class ScheduleController(ModeusService modeusService, ILogger<ScheduleCon | |||||||
|         { |         { | ||||||
|             logger.LogError("Ошибка при получении расписания\n\n" + e.Message + "\n\n" + e.StackTrace + |             logger.LogError("Ошибка при получении расписания\n\n" + e.Message + "\n\n" + e.StackTrace + | ||||||
|                             "\n\n JSON: " + |                             "\n\n JSON: " + | ||||||
|                             JsonSerializer.Serialize(request, GlobalVariables.jsonSerializerOptions)); |                             JsonSerializer.Serialize(request, GlobalVariables.JsonSerializerOptions)); | ||||||
|             return StatusCode((int)(e.StatusCode ?? HttpStatusCode.InternalServerError), |             return StatusCode((int)(e.StatusCode ?? HttpStatusCode.InternalServerError), | ||||||
|                 "Proxied Modeus: " + e.Message); |                 "Proxied Modeus: " + e.Message); | ||||||
|         } |         } | ||||||
| @@ -59,7 +59,7 @@ public class ScheduleController(ModeusService modeusService, ILogger<ScheduleCon | |||||||
|         catch (HttpRequestException e) |         catch (HttpRequestException e) | ||||||
|         { |         { | ||||||
|             logger.LogError("Ошибка при поиске аудиторий\n\n" + e.Message + "\n\n" + e.StackTrace + "\n\n JSON: " + |             logger.LogError("Ошибка при поиске аудиторий\n\n" + e.Message + "\n\n" + e.StackTrace + "\n\n JSON: " + | ||||||
|                             JsonSerializer.Serialize(request, GlobalVariables.jsonSerializerOptions)); |                             JsonSerializer.Serialize(request, GlobalVariables.JsonSerializerOptions)); | ||||||
|             return StatusCode((int)(e.StatusCode ?? HttpStatusCode.InternalServerError), |             return StatusCode((int)(e.StatusCode ?? HttpStatusCode.InternalServerError), | ||||||
|                 "Proxied Modeus: " + e.Message); |                 "Proxied Modeus: " + e.Message); | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -5,14 +5,10 @@ using SfeduSchedule.Services; | |||||||
| namespace SfeduSchedule.Controllers | namespace SfeduSchedule.Controllers | ||||||
| { | { | ||||||
|     [ApiController] |     [ApiController] | ||||||
|     [Route("api/[controller]")] |     [Route("api/sfedu")] | ||||||
|     [Authorize(AuthenticationSchemes = "OpenIdConnect")] |     [Authorize(AuthenticationSchemes = "OpenIdConnect")] | ||||||
|     public class SfeduController : ControllerBase |     public class SfeduController(ModeusService modeusService) : ControllerBase | ||||||
|     { |     { | ||||||
|         private readonly ModeusService _modeusService; |  | ||||||
|         public SfeduController(ModeusService modeusService) => |  | ||||||
|         _modeusService = modeusService; |  | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Получить GUID пользователя через авторизацию Microsoft. |         /// Получить GUID пользователя через авторизацию Microsoft. | ||||||
|         /// </summary> |         /// </summary> | ||||||
| @@ -30,7 +26,7 @@ namespace SfeduSchedule.Controllers | |||||||
|             if (string.IsNullOrEmpty(name)) |             if (string.IsNullOrEmpty(name)) | ||||||
|                 return StatusCode(StatusCodes.Status500InternalServerError); |                 return StatusCode(StatusCodes.Status500InternalServerError); | ||||||
|  |  | ||||||
|             var guid = await _modeusService.GetGuidAsync(name); |             var guid = await modeusService.GetGuidAsync(name); | ||||||
|             if (string.IsNullOrEmpty(guid)) |             if (string.IsNullOrEmpty(guid)) | ||||||
|                 return NotFound(); |                 return NotFound(); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -5,6 +5,6 @@ namespace SfeduSchedule | |||||||
|     public static class GlobalVariables |     public static class GlobalVariables | ||||||
|     { |     { | ||||||
|         public static string JwtFilePath { get; set; } = "data/jwt.txt"; |         public static string JwtFilePath { get; set; } = "data/jwt.txt"; | ||||||
|         public static readonly JsonSerializerOptions jsonSerializerOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping }; |         public static readonly JsonSerializerOptions JsonSerializerOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping }; | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -1,5 +1,6 @@ | |||||||
| using Microsoft.Playwright; | using Microsoft.Playwright; | ||||||
| using Quartz; | using Quartz; | ||||||
|  | using SfeduSchedule.BrowserScripts; | ||||||
|  |  | ||||||
| namespace SfeduSchedule.Jobs; | namespace SfeduSchedule.Jobs; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -20,9 +20,7 @@ string updateJwtCron = configuration["UPDATE_JWT_CRON"] ?? "0 0 4 ? * *"; | |||||||
|  |  | ||||||
| // Если не указана TZ, ставим Europe/Moscow | // Если не указана TZ, ставим Europe/Moscow | ||||||
| if (string.IsNullOrEmpty(configuration["TZ"])) | if (string.IsNullOrEmpty(configuration["TZ"])) | ||||||
| { |  | ||||||
|     configuration["TZ"] = "Europe/Moscow"; |     configuration["TZ"] = "Europe/Moscow"; | ||||||
| } |  | ||||||
|  |  | ||||||
| int permitLimit = int.TryParse(configuration["PERMIT_LIMIT"], out var parsedPermitLimit) ? parsedPermitLimit : 40; | int permitLimit = int.TryParse(configuration["PERMIT_LIMIT"], out var parsedPermitLimit) ? parsedPermitLimit : 40; | ||||||
| int timeLimit = int.TryParse(configuration["TIME_LIMIT"], out var parsedTimeLimit) ? parsedTimeLimit : 10; | int timeLimit = int.TryParse(configuration["TIME_LIMIT"], out var parsedTimeLimit) ? parsedTimeLimit : 10; | ||||||
| @@ -67,9 +65,9 @@ builder.Services.AddAuthorization(); | |||||||
| builder.Services.AddMicrosoftIdentityWebAppAuthentication(builder.Configuration); | builder.Services.AddMicrosoftIdentityWebAppAuthentication(builder.Configuration); | ||||||
|  |  | ||||||
| // Загружаем плагины (изолированно), даём им зарегистрировать DI и подключаем контроллеры | // Загружаем плагины (изолированно), даём им зарегистрировать DI и подключаем контроллеры | ||||||
| var loaded = PluginLoader.LoadPlugins(pluginsPath); | var loadedPlugins = PluginLoader.LoadPlugins(pluginsPath); | ||||||
| Console.WriteLine("Plugins count: " + loaded.Count); | Console.WriteLine("Plugins count: " + loadedPlugins.Count); | ||||||
| foreach (var p in loaded) | foreach (var p in loadedPlugins) | ||||||
| { | { | ||||||
|     Console.WriteLine("Loading plugin: " + p.Instance.Name); |     Console.WriteLine("Loading plugin: " + p.Instance.Name); | ||||||
|      |      | ||||||
| @@ -225,9 +223,8 @@ app.MapGet("/", async context => | |||||||
| app.MapControllers(); | app.MapControllers(); | ||||||
|  |  | ||||||
| // Маршруты Minimal API из плагинов | // Маршруты Minimal API из плагинов | ||||||
| foreach (var p in loaded) | foreach (var p in loadedPlugins) | ||||||
| { | { | ||||||
|     logger.LogInformation("Mapping endpoints for plugin: {PluginName}", p.Instance.Name); |  | ||||||
|     p.Instance.MapEndpoints(app); |     p.Instance.MapEndpoints(app); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -27,7 +27,7 @@ namespace SfeduSchedule.Services | |||||||
|         { |         { | ||||||
|             var request = new HttpRequestMessage(HttpMethod.Post, |             var request = new HttpRequestMessage(HttpMethod.Post, | ||||||
|                 $"schedule-calendar-v2/api/calendar/events/search?tz={_configuration["TZ"]!}"); |                 $"schedule-calendar-v2/api/calendar/events/search?tz={_configuration["TZ"]!}"); | ||||||
|             request.Content = new StringContent(JsonSerializer.Serialize(msr, GlobalVariables.jsonSerializerOptions), |             request.Content = new StringContent(JsonSerializer.Serialize(msr, GlobalVariables.JsonSerializerOptions), | ||||||
|                 System.Text.Encoding.UTF8, "application/json"); |                 System.Text.Encoding.UTF8, "application/json"); | ||||||
|             var response = await _httpClient.SendAsync(request); |             var response = await _httpClient.SendAsync(request); | ||||||
|             _logger.LogInformation("GetScheduleAsync: Ответ получен: {StatusCode}", response.StatusCode); |             _logger.LogInformation("GetScheduleAsync: Ответ получен: {StatusCode}", response.StatusCode); | ||||||
| @@ -59,7 +59,7 @@ namespace SfeduSchedule.Services | |||||||
|         { |         { | ||||||
|             var request = new HttpRequestMessage(HttpMethod.Post, $"schedule-calendar-v2/api/campus/rooms/search"); |             var request = new HttpRequestMessage(HttpMethod.Post, $"schedule-calendar-v2/api/campus/rooms/search"); | ||||||
|             request.Content = |             request.Content = | ||||||
|                 new StringContent(JsonSerializer.Serialize(requestDto, GlobalVariables.jsonSerializerOptions), |                 new StringContent(JsonSerializer.Serialize(requestDto, GlobalVariables.JsonSerializerOptions), | ||||||
|                     System.Text.Encoding.UTF8, "application/json"); |                     System.Text.Encoding.UTF8, "application/json"); | ||||||
|             var response = await _httpClient.SendAsync(request); |             var response = await _httpClient.SendAsync(request); | ||||||
|             _logger.LogInformation("SearchRoomsAsync: Ответ получен: {StatusCode}", response.StatusCode); |             _logger.LogInformation("SearchRoomsAsync: Ответ получен: {StatusCode}", response.StatusCode); | ||||||
| @@ -122,22 +122,22 @@ namespace SfeduSchedule.Services | |||||||
|                     case null: |                     case null: | ||||||
|                         _logger.LogError( |                         _logger.LogError( | ||||||
|                             "GetScheduleJsonAsync: scheduleJson is null. Schedule: {Schedule}\n Request: {msr}", |                             "GetScheduleJsonAsync: scheduleJson is null. Schedule: {Schedule}\n Request: {msr}", | ||||||
|                             schedule, JsonSerializer.Serialize(msr, GlobalVariables.jsonSerializerOptions)); |                             schedule, JsonSerializer.Serialize(msr, GlobalVariables.JsonSerializerOptions)); | ||||||
|                         break; |                         break; | ||||||
|                     case { Embedded: null }: |                     case { Embedded: null }: | ||||||
|                         _logger.LogError( |                         _logger.LogError( | ||||||
|                             "GetScheduleJsonAsync: scheduleJson.Embedded is null. scheduleJson: {@scheduleJson}\n Request: {msr}", |                             "GetScheduleJsonAsync: scheduleJson.Embedded is null. scheduleJson: {@scheduleJson}\n Request: {msr}", | ||||||
|                             scheduleJson, JsonSerializer.Serialize(msr, GlobalVariables.jsonSerializerOptions)); |                             scheduleJson, JsonSerializer.Serialize(msr, GlobalVariables.JsonSerializerOptions)); | ||||||
|                         break; |                         break; | ||||||
|                     case { Embedded.Events: null }: |                     case { Embedded.Events: null }: | ||||||
|                         _logger.LogError( |                         _logger.LogError( | ||||||
|                             "GetScheduleJsonAsync: scheduleJson.Embedded.Events is null. Embedded: {@Embedded}\n Request: {msr}", |                             "GetScheduleJsonAsync: scheduleJson.Embedded.Events is null. Embedded: {@Embedded}\n Request: {msr}", | ||||||
|                             scheduleJson.Embedded, JsonSerializer.Serialize(msr, GlobalVariables.jsonSerializerOptions)); |                             scheduleJson.Embedded, JsonSerializer.Serialize(msr, GlobalVariables.JsonSerializerOptions)); | ||||||
|                         break; |                         break; | ||||||
|                     case { Embedded.Events.Length: 0 }: |                     case { Embedded.Events.Length: 0 }: | ||||||
|                         _logger.LogWarning( |                         _logger.LogWarning( | ||||||
|                             "GetScheduleJsonAsync: scheduleJson.Embedded.Events is empty. Embedded: {@Embedded}\n Request: {msr}", |                             "GetScheduleJsonAsync: scheduleJson.Embedded.Events is empty. Embedded: {@Embedded}\n Request: {msr}", | ||||||
|                             scheduleJson.Embedded, JsonSerializer.Serialize(msr, GlobalVariables.jsonSerializerOptions)); |                             scheduleJson.Embedded, JsonSerializer.Serialize(msr, GlobalVariables.JsonSerializerOptions)); | ||||||
|                         break; |                         break; | ||||||
|                     default: |                     default: | ||||||
|                         return scheduleJson; |                         return scheduleJson; | ||||||
| @@ -147,7 +147,7 @@ namespace SfeduSchedule.Services | |||||||
|             { |             { | ||||||
|                 _logger.LogError(ex, |                 _logger.LogError(ex, | ||||||
|                     "GetScheduleJsonAsync: Deserialization failed. Schedule: {Schedule}\n Request: {msr}", schedule, |                     "GetScheduleJsonAsync: Deserialization failed. Schedule: {Schedule}\n Request: {msr}", schedule, | ||||||
|                     JsonSerializer.Serialize(msr, GlobalVariables.jsonSerializerOptions)); |                     JsonSerializer.Serialize(msr, GlobalVariables.JsonSerializerOptions)); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             return null; |             return null; | ||||||
| @@ -158,7 +158,7 @@ namespace SfeduSchedule.Services | |||||||
|             Schedule? scheduleJson = await GetScheduleJsonAsync(msr); |             Schedule? scheduleJson = await GetScheduleJsonAsync(msr); | ||||||
|             if (scheduleJson == null) |             if (scheduleJson == null) | ||||||
|             { |             { | ||||||
|                 _logger.LogError("GetIcsAsync: scheduleJson is null after deserialization. Request: " + JsonSerializer.Serialize(msr, GlobalVariables.jsonSerializerOptions)); |                 _logger.LogError("GetIcsAsync: scheduleJson is null after deserialization. Request: " + JsonSerializer.Serialize(msr, GlobalVariables.JsonSerializerOptions)); | ||||||
|                 return null; |                 return null; | ||||||
|             } |             } | ||||||
|  |  | ||||||
| @@ -252,7 +252,7 @@ namespace SfeduSchedule.Services | |||||||
|                                 shortNameCourse = courseUnitRealization.NameShort ?? ""; |                                 shortNameCourse = courseUnitRealization.NameShort ?? ""; | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                     catch (Exception ex) |                     catch (Exception) | ||||||
|                     { |                     { | ||||||
|                         // Ignored    |                         // Ignored    | ||||||
|                     } |                     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user