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-01-29 15:03:53 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services.Trajectory.Parser;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Services;
|
|
|
|
|
|
|
|
|
|
public class ParserServiceFactory
|
|
|
|
|
{
|
|
|
|
|
public const int IdTrajectoryFactManualParserService = 1;
|
|
|
|
|
public const int IdTrajectoryPlanParserService = 2;
|
|
|
|
|
|
2024-02-01 16:35:29 +05:00
|
|
|
|
private readonly IDictionary<int, Func<IParserService>> parsers;
|
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-01 16:35:29 +05:00
|
|
|
|
parsers = new Dictionary<int, Func<IParserService>>
|
|
|
|
|
{
|
|
|
|
|
{ IdTrajectoryPlanParserService, () => new TrajectoryPlanParserService(serviceProvider) },
|
|
|
|
|
{ IdTrajectoryFactManualParserService, () => new TrajectoryFactManualParserService(serviceProvider) }
|
|
|
|
|
};
|
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
|
|
|
|
}
|
|
|
|
|
}
|