Skip to content

Commit

Permalink
feat: Make CsvDataReader methods virtual (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyshibanov authored Dec 2, 2024
1 parent 0db16e3 commit 25a57fd
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions src/VirtoCommerce.ImportModule.CsvHelper/CsvDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,16 @@ namespace VirtoCommerce.ImportModule.CsvHelper
{
public class CsvDataReader<TCsvImportable, TCsvClassMap> : IImportDataReader where TCsvClassMap : ClassMap
{
private int? _totalCount;
private int _pageSize;
private string _headerRaw;
private readonly Stream _stream;
protected CsvConfiguration CsvConfiguration { get; set; }
private readonly CsvReader _csvReader;
private readonly int _pageSize;
private readonly bool _needReadRaw;
private int? _totalCount;
private string _headerRaw;
protected CsvConfiguration CsvConfiguration { get; set; }

public bool HasMoreResults { get; private set; } = true;

public CsvDataReader(Stream stream, ImportContext context) :
this(stream, context, false)
{
}

public CsvDataReader(Stream stream, ImportContext context, bool needReadRaw = false)
{
CsvConfiguration = GetConfiguration(context);
Expand All @@ -53,7 +48,7 @@ public CsvDataReader(Stream stream, ImportContext context, CsvConfiguration csvC
_needReadRaw = needReadRaw;
}

public async Task<int> GetTotalCountAsync(ImportContext context)
public virtual async Task<int> GetTotalCountAsync(ImportContext context)
{
if (_totalCount.HasValue)
{
Expand Down Expand Up @@ -83,7 +78,7 @@ public async Task<int> GetTotalCountAsync(ImportContext context)
return _totalCount.Value;
}

public async Task<object[]> ReadNextPageAsync(ImportContext context)
public virtual async Task<object[]> ReadNextPageAsync(ImportContext context)
{
var result = new List<object>();

Expand All @@ -109,20 +104,17 @@ public async Task<object[]> ReadNextPageAsync(ImportContext context)
Row = row,
RawHeader = _headerRaw,
RawRecord = rawRecord,
Record = record
Record = record,
});
}
}
}
catch (Exception ex)
{
if (context.ErrorCallback != null)
context.ErrorCallback?.Invoke(new ErrorInfo
{
context.ErrorCallback(new ErrorInfo
{
ErrorMessage = ex.Message
});
}
ErrorMessage = ex.Message,
});
}
}

Expand Down

0 comments on commit 25a57fd

Please sign in to comment.