2024-02-01 16:35:29 +05:00
|
|
|
|
using System;
|
|
|
|
|
using AsbCloudApp.Data.Trajectory;
|
2024-01-29 15:03:53 +05:00
|
|
|
|
using ClosedXML.Excel;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2024-02-01 16:35:29 +05:00
|
|
|
|
using System.Reflection;
|
2024-01-29 15:03:53 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2024-02-01 16:35:29 +05:00
|
|
|
|
using AsbCloudApp.Requests.ParserOptions;
|
2024-01-29 15:03:53 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Services.Trajectory.Parser;
|
|
|
|
|
|
2024-02-01 16:35:29 +05:00
|
|
|
|
public abstract class TrajectoryParserService<T> : ParserServiceBase<T, IParserOptionsRequest>
|
2024-01-29 15:03:53 +05:00
|
|
|
|
where T : TrajectoryGeoDto
|
|
|
|
|
{
|
2024-01-31 17:20:54 +05:00
|
|
|
|
private const int HeaderRowsCount = 2;
|
|
|
|
|
private const int ColumnCount = 6;
|
|
|
|
|
|
2024-02-01 16:35:29 +05:00
|
|
|
|
protected TrajectoryParserService(IServiceProvider serviceProvider)
|
|
|
|
|
: base(serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-31 17:20:54 +05:00
|
|
|
|
protected abstract string SheetName { get; }
|
|
|
|
|
|
2024-02-01 16:35:29 +05:00
|
|
|
|
protected abstract string TemplateFileName { get; }
|
|
|
|
|
|
2024-01-29 15:03:53 +05:00
|
|
|
|
protected abstract ValidationResultDto<T> ParseRow(IXLRow row);
|
|
|
|
|
|
2024-02-01 16:35:29 +05:00
|
|
|
|
public override Stream GetTemplateFile() =>
|
|
|
|
|
Assembly.GetExecutingAssembly().GetTemplateCopyStream(TemplateFileName)
|
|
|
|
|
?? throw new ArgumentNullException($"Файл '{TemplateFileName}' не найден");
|
|
|
|
|
|
|
|
|
|
public override ParserResultDto<T> Parse(Stream file, IParserOptionsRequest options)
|
2024-01-29 15:03:53 +05:00
|
|
|
|
{
|
2024-02-07 11:33:00 +05:00
|
|
|
|
using var workbook = new XLWorkbook(file);
|
2024-01-29 15:03:53 +05:00
|
|
|
|
|
2024-02-07 11:33:00 +05:00
|
|
|
|
var sheet = workbook.GetWorksheet(SheetName);
|
2024-01-29 15:03:53 +05:00
|
|
|
|
|
2024-02-01 16:35:29 +05:00
|
|
|
|
var trajectoryRows = ParseExcelSheet(sheet, ParseRow, ColumnCount, HeaderRowsCount);
|
2024-01-29 15:03:53 +05:00
|
|
|
|
return trajectoryRows;
|
|
|
|
|
}
|
|
|
|
|
}
|