DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/WellOperations/Factories/WellOperationParserFactory.cs
Степанов Дмитрий 16645d053a Новая реализация экпорта/импорта ГГД
1. Изменено апи
2. Добавлен парсер для ГГД
3. Добавлен ссервис экспорта ГГД
2024-03-22 10:42:48 +03:00

43 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using AsbCloudApp.Data.WellOperation;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests.ParserOptions;
using AsbCloudApp.Services.Parsers;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.ExcelServices.Templates.WellOperations;
using Microsoft.Extensions.DependencyInjection;
namespace AsbCloudInfrastructure.Services.WellOperations.Factories;
public class WellOperationParserFactory : IParserFactory<int, WellOperationDto>
{
private readonly IDictionary<int, Func<IParserService>> parsers;
public WellOperationParserFactory(IServiceProvider serviceProvider)
{
var wellOperationRepository = serviceProvider.GetRequiredService<IWellOperationRepository>();
var categoryRepository = serviceProvider.GetRequiredService<IWellOperationCategoryRepository>();
parsers = new Dictionary<int, Func<IParserService>>
{
{
WellOperation.IdOperationTypeFact,
() => new WellOperationParser<WellOperationFactTemplate>(wellOperationRepository, categoryRepository)
},
{
WellOperation.IdOperationTypePlan,
() => new WellOperationParser<WellOperationPlanTemplate>(wellOperationRepository, categoryRepository)
}
};
}
public IParserService<WellOperationDto, TOptions> CreateParser<TOptions>(int id)
where TOptions : IParserOptionsRequest
{
var parser = parsers[id].Invoke();
return parser as IParserService<WellOperationDto, TOptions>
?? throw new ArgumentNullException(nameof(id), "Не удалось распознать файл");
}
}