forked from ddrilling/AsbCloudServer
32a0678a56
1. Использование новых методов расширения 2. Удалил неиспользуемый генератор файла DrillingProgramMaker 3. Поправлено название листа в ProcessMapReportTemplate
42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using System;
|
|
using AsbCloudApp.Data.Trajectory;
|
|
using ClosedXML.Excel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Requests.ParserOptions;
|
|
|
|
namespace AsbCloudInfrastructure.Services.Trajectory.Parser;
|
|
|
|
public abstract class TrajectoryParserService<T> : ParserServiceBase<T, IParserOptionsRequest>
|
|
where T : TrajectoryGeoDto
|
|
{
|
|
private const int HeaderRowsCount = 2;
|
|
private const int ColumnCount = 6;
|
|
|
|
protected TrajectoryParserService(IServiceProvider serviceProvider)
|
|
: base(serviceProvider)
|
|
{
|
|
}
|
|
|
|
protected abstract string SheetName { get; }
|
|
|
|
protected abstract string TemplateFileName { get; }
|
|
|
|
protected abstract ValidationResultDto<T> ParseRow(IXLRow row);
|
|
|
|
public override Stream GetTemplateFile() =>
|
|
Assembly.GetExecutingAssembly().GetTemplateCopyStream(TemplateFileName)
|
|
?? throw new ArgumentNullException($"Файл '{TemplateFileName}' не найден");
|
|
|
|
public override ParserResultDto<T> Parse(Stream file, IParserOptionsRequest options)
|
|
{
|
|
using var workbook = new XLWorkbook(file);
|
|
|
|
var sheet = workbook.GetWorksheet(SheetName);
|
|
|
|
var trajectoryRows = ParseExcelSheet(sheet, ParseRow, ColumnCount, HeaderRowsCount);
|
|
return trajectoryRows;
|
|
}
|
|
} |