using System; using System.IO; using System.Reflection; using AsbCloudApp.Data; using AsbCloudApp.Data.ProcessMapPlan; using AsbCloudApp.Requests.ParserOptions; using ClosedXML.Excel; namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Parser; public abstract class ProcessMapPlanParser : ParserExcelService where TDto : ProcessMapPlanBaseDto { protected ProcessMapPlanParser(IServiceProvider serviceProvider) : base(serviceProvider) { } private const int HeaderRowsCount = 2; private const int ColumnCount = 18; protected abstract string TemplateFileName { get; } public override ParserResultDto Parse(Stream file, IParserOptionsRequest options) { using var workbook = new XLWorkbook(file); var sheet = workbook.GetWorksheet(SheetName); var processMaps = ParseExcelSheet(sheet, ColumnCount, HeaderRowsCount); return processMaps; } public override Stream GetTemplateFile() => Assembly.GetExecutingAssembly().GetTemplateCopyStream(TemplateFileName) ?? throw new ArgumentNullException($"Файл '{TemplateFileName}' не найден"); protected static int? GetIdMode(string? modeName) => modeName?.Trim().ToLower() switch { "ручной" => 0, "ротор" => 1, "слайд" => 2, _ => null }; }