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;
|
|
|
|
using AsbCloudApp.Services.Parser;
|
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-01-31 17:20:54 +05:00
|
|
|
private readonly IDictionary<int, Func<object>> parsers = new Dictionary<int, Func<object>>
|
2024-01-29 15:03:53 +05:00
|
|
|
{
|
|
|
|
{ IdTrajectoryPlanParserService, () => new TrajectoryPlanParserService() },
|
|
|
|
{ IdTrajectoryFactManualParserService, () => new TrajectoryFactManualParserService() }
|
|
|
|
};
|
|
|
|
|
2024-01-31 17:20:54 +05:00
|
|
|
public IParserService<TDto> GetParser<TDto>(int idParserService)
|
2024-01-29 15:03:53 +05:00
|
|
|
where TDto : class, IId
|
|
|
|
{
|
2024-01-31 17:20:54 +05:00
|
|
|
if (!parsers.TryGetValue(idParserService, out var parserService))
|
|
|
|
throw new ArgumentNullException(nameof(idParserService), "Сервис не зарегистрирован");
|
2024-01-29 15:03:53 +05:00
|
|
|
|
2024-01-31 17:20:54 +05:00
|
|
|
return parserService.Invoke() as IParserService<TDto>
|
|
|
|
?? throw new ArgumentNullException(nameof(idParserService), "Ошибка приведения типа");
|
|
|
|
}
|
|
|
|
|
|
|
|
public IParserServiceWithOptions<TDto, TOptions> GetParserWithOptions<TDto, TOptions>(int idParserService)
|
|
|
|
where TDto : class, IId
|
|
|
|
where TOptions : IParserOptionsRequest
|
|
|
|
{
|
|
|
|
if (!parsers.TryGetValue(idParserService, out var parserService))
|
|
|
|
throw new ArgumentNullException(nameof(idParserService), "Сервис не зарегистрирован");
|
|
|
|
|
|
|
|
return parserService.Invoke() as IParserServiceWithOptions<TDto, TOptions>
|
|
|
|
?? throw new ArgumentNullException(nameof(idParserService), "Ошибка приведения типа");
|
2024-01-29 15:03:53 +05:00
|
|
|
}
|
|
|
|
}
|