DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/Trajectory/Parser/TrajectoryParserService.cs

31 lines
958 B
C#
Raw Normal View History

using AsbCloudApp.Data.Trajectory;
using ClosedXML.Excel;
using System.IO;
using System.Linq;
using AsbCloudApp.Data;
using AsbCloudApp.Services.Parser;
namespace AsbCloudInfrastructure.Services.Trajectory.Parser;
public abstract class TrajectoryParserService<T> : IParserService<T>
where T : TrajectoryGeoDto
{
private const int HeaderRowsCount = 2;
private const int ColumnCount = 6;
protected abstract string SheetName { get; }
protected abstract ValidationResultDto<T> ParseRow(IXLRow row);
public ParserResultDto<T> Parse(Stream file)
{
using var workbook = new XLWorkbook(file, XLEventTracking.Disabled);
var sheet = workbook.Worksheets.FirstOrDefault(ws =>
ws.Name.ToLower().Trim() == SheetName.ToLower().Trim())
?? throw new FileFormatException($"Книга excel не содержит листа {SheetName}.");
var trajectoryRows = sheet.Parse(ParseRow, ColumnCount, HeaderRowsCount);
return trajectoryRows;
}
}