2024-03-22 12:42:48 +05:00
|
|
|
|
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>
|
|
|
|
|
{
|
2024-07-04 11:02:45 +05:00
|
|
|
|
private readonly IDictionary<int, Func<IParserService>> parsers;
|
2024-03-22 12:42:48 +05:00
|
|
|
|
|
2024-07-04 11:02:45 +05:00
|
|
|
|
public WellOperationParserFactory(IServiceProvider serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
var wellOperationRepository = serviceProvider.GetRequiredService<IWellOperationRepository>();
|
|
|
|
|
var categoryRepository = serviceProvider.GetRequiredService<IWellOperationCategoryRepository>();
|
2024-03-22 12:42:48 +05:00
|
|
|
|
|
2024-07-04 11:02:45 +05:00
|
|
|
|
parsers = new Dictionary<int, Func<IParserService>>
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
WellOperation.IdOperationTypeFact,
|
|
|
|
|
() => new WellOperationParser<WellOperationFactTemplate>(wellOperationRepository, categoryRepository)
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
WellOperation.IdOperationTypePlan,
|
|
|
|
|
() => new WellOperationParser<WellOperationPlanTemplate>(wellOperationRepository, categoryRepository)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2024-03-22 12:42:48 +05:00
|
|
|
|
|
2024-07-04 11:02:45 +05:00
|
|
|
|
public IParserService<WellOperationDto, TOptions> CreateParser<TOptions>(int id)
|
|
|
|
|
where TOptions : IParserOptionsRequest
|
|
|
|
|
{
|
|
|
|
|
var parser = parsers[id].Invoke();
|
2024-03-22 12:42:48 +05:00
|
|
|
|
|
2024-07-04 11:02:45 +05:00
|
|
|
|
return parser as IParserService<WellOperationDto, TOptions>
|
|
|
|
|
?? throw new ArgumentNullException(nameof(id), "Не удалось распознать файл");
|
|
|
|
|
}
|
2024-03-22 12:42:48 +05:00
|
|
|
|
}
|