private void PerformAdditionalValidation(List <WildlifeReportTyped> typedRows) { MethodLogger.LogEntry(_logger, _enableMethodLog, _methodLogHeader); foreach (var typedRow in typedRows) { var errors = new Dictionary <string, List <string> >(); var submissionRow = _submissionRows[(decimal)typedRow.RowNum]; if (typedRow.AccidentDate != null && typedRow.AccidentDate > DateTime.Now) { errors.AddItem(Fields.AccidentDate, "Cannot be a future date."); } ValidateHighwayUniqueAgainstServiceArea(typedRow.HighwayUnique, errors); if (!ValidateGpsCoordsRange(typedRow.Longitude, typedRow.Latitude)) { errors.AddItem($"{Fields.Longitude}/{Fields.Latitude}", "Invalid range of GPS coordinates."); } if (errors.Count > 0) { SetErrorDetail(submissionRow, errors, _statusService.FileConflictionError); } } }
private void PerformAdditionalValidation(List <WorkReportTyped> typedRows) { MethodLogger.LogEntry(_logger, _enableMethodLog, _methodLogHeader); foreach (var typedRow in typedRows) { var errors = new Dictionary <string, List <string> >(); var submissionRow = _submissionRows[(decimal)typedRow.RowNum]; if (typedRow.StartDate != null && typedRow.EndDate < typedRow.StartDate) { errors.AddItem("StartDate", "Start Date cannot be greater than End Date"); } if (typedRow.StartDate != null && typedRow.StartDate > DateTime.Now) { errors.AddItem(Fields.StartDate, "Cannot be a future date."); } if (typedRow.EndDate != null && typedRow.EndDate > DateTime.Now) { errors.AddItem(Fields.EndDate, "Cannot be a future date."); } ValidateHighwayUniqueAgainstServiceArea(typedRow.HighwayUnique, errors); if (typedRow.SpatialData == SpatialData.Gps) { PerformGpsPointValidation(typedRow, errors); PerformGpsLineValidation(typedRow, errors); PerformGpsEitherLineOrPointValidation(typedRow); } if (typedRow.SpatialData == SpatialData.Lrs) { PerformOffsetPointValidation(typedRow, errors); PerformOffsetLineValidation(typedRow, errors); PerformOffsetEitherLineOrPointValidation(typedRow); } if (!ValidateGpsCoordsRange(typedRow.StartLongitude, typedRow.StartLatitude)) { errors.AddItem($"{Fields.StartLongitude}/{Fields.StartLatitude}", "Invalid range of GPS coordinates."); } if (!ValidateGpsCoordsRange(typedRow.EndLongitude, typedRow.EndLatitude)) { errors.AddItem($"{Fields.EndLongitude}/{Fields.EndLatitude}", "Invalid range of GPS coordinates."); } if (errors.Count > 0) { SetErrorDetail(submissionRow, errors, _statusService.FileConflictionError); } } }
private void CopyCalculatedFieldsFormUntypedRow(List <RockfallReportTyped> typedRows, List <RockfallReportCsvDto> untypedRows) { MethodLogger.LogEntry(_logger, _enableMethodLog, _methodLogHeader); foreach (var typedRow in typedRows) { var untypedRow = untypedRows.First(x => x.RowNum == typedRow.RowNum); typedRow.SpatialData = untypedRow.SpatialData; typedRow.RowId = untypedRow.RowId; } }
private void PerformAdditionalValidation(List <RockfallReportTyped> typedRows) { MethodLogger.LogEntry(_logger, _enableMethodLog, _methodLogHeader); foreach (var typedRow in typedRows) { var errors = new Dictionary <string, List <string> >(); var submissionRow = _submissionRows[(decimal)typedRow.RowNum]; if (typedRow.StartOffset != null && typedRow.EndOffset < typedRow.StartOffset) { errors.AddItem(Fields.StartOffset, "Start Offset cannot be greater than End Offset"); } if (typedRow.DitchVolume == DitchVolume.Threshold) { _validator.Validate(Entities.RockfallReportOtherDitchVolume, Fields.OtherDitchVolume, typedRow.OtherDitchVolume, errors); } if (typedRow.TravelledLanesVolume == DitchVolume.Threshold) { _validator.Validate(Entities.RockfallReportOtherTravelledLanesVolume, Fields.OtherTravelledLanesVolume, typedRow.OtherTravelledLanesVolume, errors); } if (typedRow.ReportDate != null && typedRow.ReportDate > DateTime.Now) { errors.AddItem(Fields.ReportDate, "Cannot be a future date."); } if (typedRow.EstimatedRockfallDate != null && typedRow.EstimatedRockfallDate > DateTime.Now) { errors.AddItem(Fields.EstimatedRockfallDate, "Report Date cannot be a future date."); } ValidateHighwayUniqueAgainstServiceArea(typedRow.HighwayUnique, errors); if (!ValidateGpsCoordsRange(typedRow.StartLongitude, typedRow.StartLatitude)) { errors.AddItem($"{Fields.StartLongitude}/{Fields.StartLatitude}", "Invalid range of GPS coordinates."); } if (!ValidateGpsCoordsRange(typedRow.EndLongitude, typedRow.EndLatitude)) { errors.AddItem($"{Fields.EndLongitude}/{Fields.EndLatitude}", "Invalid range of GPS coordinates."); } if (errors.Count > 0) { SetErrorDetail(submissionRow, errors, _statusService.FileConflictionError); } } }
private void CopyCalculatedFieldsFormUntypedRow(List <WorkReportTyped> typedRows, List <WorkReportCsvDto> untypedRows) { MethodLogger.LogEntry(_logger, _enableMethodLog, _methodLogHeader); foreach (var typedRow in typedRows) { var untypedRow = untypedRows.First(x => x.RowNum == typedRow.RowNum); typedRow.FeatureType = untypedRow.FeatureType; typedRow.SpatialData = untypedRow.SpatialData; typedRow.RowId = untypedRow.RowId; typedRow.SpThresholdLevel = untypedRow.SpThresholdLevel; } }
private List <RockfallReportGeometry> PerformSpatialValidationAndConversionBatchAsync(List <RockfallReportTyped> typedRows) { MethodLogger.LogEntry(_logger, _enableMethodLog, _methodLogHeader, $"Total Record: {typedRows.Count}"); //grouping the rows var groups = new List <List <RockfallReportTyped> >(); var currentGroup = new List <RockfallReportTyped>(); var count = 0; foreach (var typedRow in typedRows) { currentGroup.Add(typedRow); count++; if (count % 10 == 0) { groups.Add(currentGroup); currentGroup = new List <RockfallReportTyped>(); } } if (currentGroup.Count > 0) { groups.Add(currentGroup); } var geometries = new ConcurrentBag <RockfallReportGeometry>(); var progress = 0; foreach (var group in groups) { var tasklist = new List <Task>(); foreach (var row in group) { tasklist.Add(Task.Run(async() => geometries.Add(await PerformSpatialValidationAndConversionAsync(row)))); } Task.WaitAll(tasklist.ToArray()); progress += 10; if (progress % 500 == 0) { _logger.LogInformation($"{_methodLogHeader} PerformSpatialValidationAndConversionAsync {progress}"); } } return(geometries.ToList()); }
private (List <WildlifeReportCsvDto> untypedRows, string headers) ParseRowsUnTyped(Dictionary <string, List <string> > errors) { MethodLogger.LogEntry(_logger, _enableMethodLog, _methodLogHeader); using TextReader textReader = new StreamReader(new MemoryStream(_submission.DigitalRepresentation), Encoding.UTF8); using var csv = new CsvReader(textReader, CultureInfo.InvariantCulture); CsvHelperUtils.Config(errors, csv, false); csv.Configuration.RegisterClassMap <WildlifeReportCsvDtoMap>(); var rows = GetRecords(csv); return(rows, string.Join(',', csv.Context.HeaderRecord).Replace("\"", "")); }
private (decimal rowNum, List <RockfallReportTyped> rows) ParseRowsTyped(string text, Dictionary <string, List <string> > errors) { MethodLogger.LogEntry(_logger, _enableMethodLog, _methodLogHeader); using var stringReader = new StringReader(text); using var csv = new CsvReader(stringReader, CultureInfo.InvariantCulture); CsvHelperUtils.Config(errors, csv, false); csv.Configuration.RegisterClassMap <RockfallReportDtoMap>(); var rows = new List <RockfallReportTyped>(); var rowNum = 0M; while (csv.Read()) { try { var row = csv.GetRecord <RockfallReportTyped>(); row.HighwayUnique = row.HighwayUnique.ToTrimAndUppercase(); //rockfall requires Y/N fields to be set to Uppercase, see HMCR-643 row.HeavyPrecip = row.HeavyPrecip.ToTrimAndUppercase(); row.FreezeThaw = row.FreezeThaw.ToTrimAndUppercase(); row.DitchSnowIce = row.DitchSnowIce.ToTrimAndUppercase(); row.VehicleDamage = row.VehicleDamage.ToTrimAndUppercase(); rows.Add(row); rowNum = (decimal)row.RowNum; row.ServiceArea = _serviceArea.ConvertToServiceAreaNumber(row.ServiceArea); } catch (CsvHelper.TypeConversion.TypeConverterException ex) { _logger.LogError(ex.ToString()); rowNum = GetRowNum(csv.Context.RawRecord); LogRowParseException(rowNum, ex.ToString(), csv.Context); errors.AddItem("Parse Error", $"Exception while parsing the text [{ex.Text}]"); return(rowNum, null); } catch (Exception ex) { _logger.LogError(ex.ToString()); rowNum = GetRowNum(csv.Context.RawRecord); LogRowParseException(rowNum, ex.ToString(), csv.Context); errors.AddItem("Parse Error", $"Exception while parsing"); return(rowNum, null); } } return(0, rows); }
private (decimal rowNum, List <RockfallReportTyped> rows) ParseRowsTyped(string text, Dictionary <string, List <string> > errors) { MethodLogger.LogEntry(_logger, _enableMethodLog, _methodLogHeader); using var stringReader = new StringReader(text); using var csv = new CsvReader(stringReader, CultureInfo.InvariantCulture); CsvHelperUtils.Config(errors, csv, false); csv.Configuration.RegisterClassMap <RockfallReportDtoMap>(); var rows = new List <RockfallReportTyped>(); var rowNum = 0M; while (csv.Read()) { try { var row = csv.GetRecord <RockfallReportTyped>(); rows.Add(row); rowNum = (decimal)row.RowNum; row.ServiceArea = _serviceArea.ConvertToServiceAreaNumber(row.ServiceArea); } catch (CsvHelper.TypeConversion.TypeConverterException ex) { _logger.LogError(ex.ToString()); rowNum = GetRowNum(csv.Context.RawRecord); LogRowParseException(rowNum, ex.ToString(), csv.Context); errors.AddItem("Parse Error", $"Exception while parsing the text [{ex.Text}]"); return(rowNum, null); } catch (Exception ex) { _logger.LogError(ex.ToString()); rowNum = GetRowNum(csv.Context.RawRecord); LogRowParseException(rowNum, ex.ToString(), csv.Context); errors.AddItem("Parse Error", $"Exception while parsing"); return(rowNum, null); } } return(0, rows); }
private (List <RockfallReportCsvDto> untypedRows, string headers) ParseRowsUnTyped(Dictionary <string, List <string> > errors) { MethodLogger.LogEntry(_logger, _enableMethodLog, _methodLogHeader); using TextReader textReader = new StreamReader(new MemoryStream(_submission.DigitalRepresentation), Encoding.UTF8); using var csv = new CsvReader(textReader, CultureInfo.InvariantCulture); CsvHelperUtils.Config(errors, csv, false); csv.Configuration.RegisterClassMap <RockfallReportCsvDtoMap>(); var rows = csv.GetRecords <RockfallReportCsvDto>().ToList(); for (var i = 0; i < rows.Count; i++) { rows[i].RowNum = i + 2; rows[i].ServiceArea = _serviceArea.ConvertToServiceAreaString(rows[i].ServiceArea); } return(rows, string.Join(',', csv.Context.HeaderRecord).Replace("\"", "")); }