Рефактор
All checks were successful
Create and publish a Docker image / Publish image (push) Successful in 4m6s
All checks were successful
Create and publish a Docker image / Publish image (push) Successful in 4m6s
This commit is contained in:
@@ -20,6 +20,7 @@ public class ProxyController(ModeusService modeusService, ILogger<ScheduleContro
|
|||||||
/// <response code="200">Возвращает расписание</response>
|
/// <response code="200">Возвращает расписание</response>
|
||||||
/// <response code="429">Слишком много запросов</response>
|
/// <response code="429">Слишком много запросов</response>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
[Route("events/search")]
|
||||||
public async Task<IActionResult> Post([FromBody] ModeusScheduleRequest request)
|
public async Task<IActionResult> Post([FromBody] ModeusScheduleRequest request)
|
||||||
{
|
{
|
||||||
string? schedule;
|
string? schedule;
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ using SfeduSchedule.Services;
|
|||||||
namespace SfeduSchedule.Controllers;
|
namespace SfeduSchedule.Controllers;
|
||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/[controller]")]
|
[Route("api/schedule")]
|
||||||
[EnableRateLimiting("throttle")]
|
[EnableRateLimiting("throttle")]
|
||||||
public class ScheduleController(ModeusService modeusService, ILogger<ScheduleController> logger) : ControllerBase
|
public class ScheduleController(ModeusService modeusService, ILogger<ScheduleController> logger) : ControllerBase
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить расписание по пользовательскому запросу.
|
/// [УСТАРЕЛО] Получить расписание по пользовательскому запросу.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request">Объект запроса, содержащий параметры фильтрации расписания.</param>
|
/// <param name="request">Объект запроса, содержащий параметры фильтрации расписания.</param>
|
||||||
/// <returns>Список событий расписания.</returns>
|
/// <returns>Список событий расписания.</returns>
|
||||||
@@ -41,7 +41,7 @@ public class ScheduleController(ModeusService modeusService, ILogger<ScheduleCon
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Поиск аудиторий по пользовательскому запросу.
|
/// [УСТАРЕЛО] Поиск аудиторий по пользовательскому запросу.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request">Объект запроса, содержащий параметры фильтрации аудиторий.</param>
|
/// <param name="request">Объект запроса, содержащий параметры фильтрации аудиторий.</param>
|
||||||
/// <returns>Список аудиторий.</returns>
|
/// <returns>Список аудиторий.</returns>
|
||||||
|
|||||||
@@ -17,12 +17,13 @@ public static class PluginLoader
|
|||||||
return result;
|
return result;
|
||||||
|
|
||||||
foreach (var file in Directory.EnumerateFiles(pluginsDir, "*.plugin.dll", SearchOption.AllDirectories))
|
foreach (var file in Directory.EnumerateFiles(pluginsDir, "*.plugin.dll", SearchOption.AllDirectories))
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var path = Path.GetFullPath(file);
|
var path = Path.GetFullPath(file);
|
||||||
var alc = new PluginLoadContext(path);
|
var alc = new PluginLoadContext(path);
|
||||||
var asm = alc.LoadFromAssemblyPath(path);
|
var asm = alc.LoadFromAssemblyPath(path);
|
||||||
|
|
||||||
// Ищем реализацию IPlugin
|
|
||||||
var pluginType = asm
|
var pluginType = asm
|
||||||
.GetTypes()
|
.GetTypes()
|
||||||
.FirstOrDefault(t => typeof(IPlugin).IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface);
|
.FirstOrDefault(t => typeof(IPlugin).IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface);
|
||||||
@@ -33,21 +34,20 @@ public static class PluginLoader
|
|||||||
var instance = (IPlugin)Activator.CreateInstance(pluginType)!;
|
var instance = (IPlugin)Activator.CreateInstance(pluginType)!;
|
||||||
result.Add(new LoadedPlugin(instance, asm, alc));
|
result.Add(new LoadedPlugin(instance, asm, alc));
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Ошибка загрузки плагина {file}: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Отдельный контекст загрузки для изоляции зависимостей плагина
|
// Отдельный контекст загрузки для изоляции зависимостей плагина
|
||||||
public sealed class PluginLoadContext : AssemblyLoadContext
|
public sealed class PluginLoadContext(string pluginMainAssemblyPath) : AssemblyLoadContext(isCollectible: true)
|
||||||
{
|
{
|
||||||
private readonly AssemblyDependencyResolver _resolver;
|
private readonly AssemblyDependencyResolver _resolver = new(pluginMainAssemblyPath);
|
||||||
|
|
||||||
public PluginLoadContext(string pluginMainAssemblyPath)
|
|
||||||
: base(isCollectible: true)
|
|
||||||
{
|
|
||||||
_resolver = new AssemblyDependencyResolver(pluginMainAssemblyPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Разрешаем управляемые зависимости плагина из его папки.
|
// Разрешаем управляемые зависимости плагина из его папки.
|
||||||
// Возвращаем null, чтобы отдать решение в Default ALC для общих сборок (например, SfeduSchedule.Abstractions).
|
// Возвращаем null, чтобы отдать решение в Default ALC для общих сборок (например, SfeduSchedule.Abstractions).
|
||||||
|
|||||||
Reference in New Issue
Block a user