forked from ddrilling/AsbCloudServer
16645d053a
1. Изменено апи 2. Добавлен парсер для ГГД 3. Добавлен ссервис экспорта ГГД
43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
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), "Не удалось распознать файл");
|
||
}
|
||
} |