2024-01-29 15:03:53 +05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using AsbCloudApp.Data;
|
2024-01-31 17:20:54 +05:00
|
|
|
|
using AsbCloudApp.Requests.ParserOptions;
|
2024-02-01 16:35:29 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
2024-02-08 14:50:14 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services.ProcessMapPlan.Parser;
|
2024-01-29 15:03:53 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services.Trajectory.Parser;
|
2024-02-08 14:50:14 +05:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2024-01-29 15:03:53 +05:00
|
|
|
|
|
2024-02-13 16:05:16 +05:00
|
|
|
|
namespace AsbCloudInfrastructure.Services.Parser;
|
2024-01-29 15:03:53 +05:00
|
|
|
|
|
2024-02-08 14:50:14 +05:00
|
|
|
|
public class ParserServiceFactory : IDisposable
|
2024-01-29 15:03:53 +05:00
|
|
|
|
{
|
2024-02-08 14:50:14 +05:00
|
|
|
|
public const int IdTrajectoryFactManualParser = 1;
|
|
|
|
|
public const int IdTrajectoryPlanParser = 2;
|
|
|
|
|
public const int IdProcessMapPlanDrillingParser = 3;
|
2024-01-29 15:03:53 +05:00
|
|
|
|
|
2024-02-01 16:35:29 +05:00
|
|
|
|
private readonly IDictionary<int, Func<IParserService>> parsers;
|
2024-02-08 14:50:14 +05:00
|
|
|
|
private readonly IServiceScope serviceScope;
|
2024-01-29 15:03:53 +05:00
|
|
|
|
|
2024-02-01 16:35:29 +05:00
|
|
|
|
public ParserServiceFactory(IServiceProvider serviceProvider)
|
2024-01-29 15:03:53 +05:00
|
|
|
|
{
|
2024-02-08 14:50:14 +05:00
|
|
|
|
serviceScope = serviceProvider.CreateScope();
|
|
|
|
|
|
2024-02-01 16:35:29 +05:00
|
|
|
|
parsers = new Dictionary<int, Func<IParserService>>
|
|
|
|
|
{
|
2024-02-08 14:50:14 +05:00
|
|
|
|
{ IdTrajectoryPlanParser, () => new TrajectoryPlanParser(serviceScope.ServiceProvider) },
|
|
|
|
|
{ IdTrajectoryFactManualParser, () => new TrajectoryFactManualParser(serviceScope.ServiceProvider) },
|
|
|
|
|
{ IdProcessMapPlanDrillingParser, () => new ProcessMapPlanDrillingParser(serviceScope.ServiceProvider) }
|
2024-02-01 16:35:29 +05:00
|
|
|
|
};
|
2024-01-31 17:20:54 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-01 16:35:29 +05:00
|
|
|
|
public IParserService<TDto, TOptions> Create<TDto, TOptions>(int idParserService)
|
2024-01-31 17:20:54 +05:00
|
|
|
|
where TDto : class, IId
|
|
|
|
|
where TOptions : IParserOptionsRequest
|
|
|
|
|
{
|
|
|
|
|
if (!parsers.TryGetValue(idParserService, out var parserService))
|
2024-02-01 16:35:29 +05:00
|
|
|
|
throw new ArgumentNullException(nameof(idParserService), "Не правильный идентификатор парсера");
|
2024-01-31 17:20:54 +05:00
|
|
|
|
|
2024-02-01 16:35:29 +05:00
|
|
|
|
return parserService.Invoke() as IParserService<TDto, TOptions>
|
2024-01-31 17:20:54 +05:00
|
|
|
|
?? throw new ArgumentNullException(nameof(idParserService), "Ошибка приведения типа");
|
2024-01-29 15:03:53 +05:00
|
|
|
|
}
|
2024-02-08 14:50:14 +05:00
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
serviceScope.Dispose();
|
|
|
|
|
}
|
2024-01-29 15:03:53 +05:00
|
|
|
|
}
|