using System; using System.Collections.Generic; using AsbCloudApp.Data; using AsbCloudApp.Requests.ParserOptions; using AsbCloudApp.Services.Parser; using AsbCloudInfrastructure.Services.Trajectory.Parser; namespace AsbCloudInfrastructure.Services; public class ParserServiceFactory { public const int IdTrajectoryFactManualParserService = 1; public const int IdTrajectoryPlanParserService = 2; private readonly IDictionary> parsers = new Dictionary> { { IdTrajectoryPlanParserService, () => new TrajectoryPlanParserService() }, { IdTrajectoryFactManualParserService, () => new TrajectoryFactManualParserService() } }; public IParserService GetParser(int idParserService) where TDto : class, IId { if (!parsers.TryGetValue(idParserService, out var parserService)) throw new ArgumentNullException(nameof(idParserService), "Сервис не зарегистрирован"); return parserService.Invoke() as IParserService ?? throw new ArgumentNullException(nameof(idParserService), "Ошибка приведения типа"); } public IParserServiceWithOptions GetParserWithOptions(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 ?? throw new ArgumentNullException(nameof(idParserService), "Ошибка приведения типа"); } }