Skip to content

Commit

Permalink
Merge pull request #502 from ychung-mot/1.2.5
Browse files Browse the repository at this point in the history
HMCR-650 Added support for blank line
  • Loading branch information
ychung-mot authored Aug 27, 2020
2 parents da44fb6 + 498f62d commit 5a51490
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 21 deletions.
31 changes: 26 additions & 5 deletions api/Hmcr.Domain/Hangfire/RockfallReportJobService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,14 +487,35 @@ private string GetValidationEntityName(RockfallReportCsvDto untypedRow)
CsvHelperUtils.Config(errors, csv, false);
csv.Configuration.RegisterClassMap<RockfallReportCsvDtoMap>();

var rows = csv.GetRecords<RockfallReportCsvDto>().ToList();
for (var i = 0; i < rows.Count; i++)
var rows = GetRecords(csv);

return (rows, string.Join(',', csv.Context.HeaderRecord).Replace("\"", ""));
}

private List<RockfallReportCsvDto> GetRecords(CsvReader csv)
{
var rows = new List<RockfallReportCsvDto>();

while (csv.Read())
{
rows[i].RowNum = i + 2;
rows[i].ServiceArea = _serviceArea.ConvertToServiceAreaString(rows[i].ServiceArea);
RockfallReportCsvDto row = null;

try
{
row = csv.GetRecord<RockfallReportCsvDto>();
}
catch (Exception ex)
{
_logger.LogError(ex.ToString());
throw;
}

row.RowNum = csv.Context.Row;
row.ServiceArea = _serviceArea.ConvertToServiceAreaString(row.ServiceArea);
rows.Add(row);
}

return (rows, string.Join(',', csv.Context.HeaderRecord).Replace("\"", ""));
return rows;
}

private (decimal rowNum, List<RockfallReportTyped> rows) ParseRowsTyped(string text, Dictionary<string, List<string>> errors)
Expand Down
31 changes: 26 additions & 5 deletions api/Hmcr.Domain/Hangfire/WildlifeReportJobService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,35 @@ private string GetValidationEntityName(WildlifeReportCsvDto untypedRow)
CsvHelperUtils.Config(errors, csv, false);
csv.Configuration.RegisterClassMap<WildlifeReportCsvDtoMap>();

var rows = csv.GetRecords<WildlifeReportCsvDto>().ToList();
for (var i = 0; i < rows.Count; i++)
var rows = GetRecords(csv);

return (rows, string.Join(',', csv.Context.HeaderRecord).Replace("\"", ""));
}

private List<WildlifeReportCsvDto> GetRecords(CsvReader csv)
{
var rows = new List<WildlifeReportCsvDto>();

while (csv.Read())
{
rows[i].RowNum = i + 2;
rows[i].ServiceArea = _serviceArea.ConvertToServiceAreaString(rows[i].ServiceArea);
WildlifeReportCsvDto row = null;

try
{
row = csv.GetRecord<WildlifeReportCsvDto>();
}
catch (Exception ex)
{
_logger.LogError(ex.ToString());
throw;
}

row.RowNum = csv.Context.Row;
row.ServiceArea = _serviceArea.ConvertToServiceAreaString(row.ServiceArea);
rows.Add(row);
}

return (rows, string.Join(',', csv.Context.HeaderRecord).Replace("\"", ""));
return rows;
}

private (decimal rowNum, List<WildlifeReportTyped> rows) ParseRowsTyped(string text, Dictionary<string, List<string>> errors)
Expand Down
33 changes: 28 additions & 5 deletions api/Hmcr.Domain/Hangfire/WorkReportJobService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CsvHelper;
using CsvHelper.TypeConversion;
using Hmcr.Data.Database;
using Hmcr.Data.Database.Entities;
using Hmcr.Data.Repositories;
Expand All @@ -19,6 +20,7 @@
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Threading.Tasks;

Expand Down Expand Up @@ -648,14 +650,35 @@ private string GetValidationEntityName(WorkReportCsvDto untypedRow, ActivityCode
CsvHelperUtils.Config(errors, csv, false);
csv.Configuration.RegisterClassMap<WorkReportCsvDtoMap>();

var rows = csv.GetRecords<WorkReportCsvDto>().ToList();
for (var i = 0; i < rows.Count; i++)
var rows = GetRecords(csv);

return (rows, string.Join(',', csv.Context.HeaderRecord).Replace("\"", ""));
}

private List<WorkReportCsvDto> GetRecords(CsvReader csv)
{
var rows = new List<WorkReportCsvDto>();

while (csv.Read())
{
rows[i].RowNum = i + 2;
rows[i].ServiceArea = _serviceArea.ConvertToServiceAreaString(rows[i].ServiceArea);
WorkReportCsvDto row = null;

try
{
row = csv.GetRecord<WorkReportCsvDto>();
}
catch (Exception ex)
{
_logger.LogError(ex.ToString());
throw;
}

row.RowNum = csv.Context.Row;
row.ServiceArea = _serviceArea.ConvertToServiceAreaString(row.ServiceArea);
rows.Add(row);
}

return (rows, string.Join(',', csv.Context.HeaderRecord).Replace("\"", ""));
return rows;
}

private (decimal rowNum, List<WorkReportTyped> rows) ParseRowsTyped(string text, Dictionary<string, List<string>> errors)
Expand Down
2 changes: 0 additions & 2 deletions api/Hmcr.Domain/Services/RockfallReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ protected override async Task<bool> ParseRowsAsync(SubmissionObjectCreateDto sub

var headerValidated = false;
var rows = new List<RockfallRptInitCsvDto>();
var rowNum = 1;

while (csv.Read())
{
Expand All @@ -77,7 +76,6 @@ protected override async Task<bool> ParseRowsAsync(SubmissionObjectCreateDto sub
}
}

row.RowNum = ++rowNum;
row.ServiceArea = serviceArea.ConvertToServiceAreaString(row.ServiceArea);
rows.Add(row);
}
Expand Down
2 changes: 0 additions & 2 deletions api/Hmcr.Domain/Services/WildlifeReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ protected override async Task<bool> ParseRowsAsync(SubmissionObjectCreateDto sub

var headerValidated = false;
var rows = new List<WildlifeRptInitCsvDto>();
var rowNum = 1;

while (csv.Read())
{
Expand All @@ -75,7 +74,6 @@ protected override async Task<bool> ParseRowsAsync(SubmissionObjectCreateDto sub
}
}

row.RowNum = ++rowNum;
row.ServiceArea = serviceArea.ConvertToServiceAreaString(row.ServiceArea);
rows.Add(row);
}
Expand Down
2 changes: 0 additions & 2 deletions api/Hmcr.Domain/Services/WorkReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ protected override async Task<bool> ParseRowsAsync(SubmissionObjectCreateDto sub

var headerValidated = false;
var rows = new List<WorkRptInitCsvDto>();
var rowNum = 1;

while (csv.Read())
{
Expand All @@ -77,7 +76,6 @@ protected override async Task<bool> ParseRowsAsync(SubmissionObjectCreateDto sub
}
}

row.RowNum = ++rowNum;
row.ServiceArea = serviceArea.ConvertToServiceAreaString(row.ServiceArea);
rows.Add(row);
}
Expand Down

0 comments on commit 5a51490

Please sign in to comment.