Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvParser.cs =================================================================== diff -u -r4259 -r4277 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvParser.cs (.../CsvParser.cs) (revision 4259) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvParser.cs (.../CsvParser.cs) (revision 4277) @@ -221,19 +221,4 @@ } } } - - public static IEnumerable Lines(this StreamReader source) - { - string line; - - if (source == null) - { - throw new ArgumentNullException("source"); - } - - while ((line = source.ReadLine()) != null) - { - yield return line; - } - } } \ No newline at end of file Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvImporters/CsvImporterSurfaceLines.cs =================================================================== diff -u -r4098 -r4277 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvImporters/CsvImporterSurfaceLines.cs (.../CsvImporterSurfaceLines.cs) (revision 4098) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvImporters/CsvImporterSurfaceLines.cs (.../CsvImporterSurfaceLines.cs) (revision 4277) @@ -53,23 +53,15 @@ try { Thread.CurrentThread.CurrentCulture = CsvReaderUtilities.DetermineCultureForFile(tempFilename); - using (var csv = new CsvReader(new StreamReader(tempFilename), true, ';') - { - MissingFieldAction = MissingFieldAction.ReplaceByNull - }) + using (var csv = new CsvReader(new StreamReader(tempFilename), true, ';')) { + csv.MissingFieldAction = MissingFieldAction.ReplaceByNull; string[] headers = CsvImporterHelper.GetFieldHeaders(this, csv); - int colIndexSurfaceLineId = CsvReaderUtilities.GetHeaderIndexByString(headers, SurfaceLineCsvColumnNames.LocationColumnName); - if (colIndexSurfaceLineId < 0) - { - // colIndexSurfaceLineId can be defined with 2 identifiers (ProfileNameColumnName is deprecated, LocationColumnName is the new one) - colIndexSurfaceLineId = CsvReaderUtilities.GetHeaderIndexByString(headers, SurfaceLineCsvColumnNames.LocationColumnName); - if (colIndexSurfaceLineId < 0) - { - colIndexSurfaceLineId = CsvReaderUtilities.GetHeaderIndexByString(headers, SurfaceLineCsvColumnNames.ProfileNameColumnName); - } - } + int colIndexSurfaceLineId = FetchSurfaceLineId(headers); + + + CheckColumn(colIndexSurfaceLineId, tempFilename, SurfaceLineCsvColumnNames.LocationColumnName); int colIndexFirstX = CsvReaderUtilities.GetHeaderIndexByString(headers, SurfaceLineCsvColumnNames.FirstXColumnName); CheckColumn(colIndexFirstX, tempFilename, SurfaceLineCsvColumnNames.FirstXColumnName); @@ -136,9 +128,9 @@ } } - public List ImportedItems { get; } = new List(); + public List ImportedItems { get; } = new (); - public List ErrorMessages { get; set; } = new List(); + public List ErrorMessages { get; set; } = new (); private void CheckColumn(int index, string fileName, string fieldName) { @@ -148,7 +140,23 @@ throw new CsvImporterSurfaceLinesException($"{fileName} : {csvHeaderFieldError} {fieldName}"); } } + + private int FetchSurfaceLineId(string [] headers) + { + int colIndexSurfaceLineId = CsvReaderUtilities.GetHeaderIndexByString(headers, SurfaceLineCsvColumnNames.LocationColumnName); + if (colIndexSurfaceLineId < 0) + { + // colIndexSurfaceLineId can be defined with 2 identifiers (ProfileNameColumnName is deprecated, LocationColumnName is the new one) + colIndexSurfaceLineId = CsvReaderUtilities.GetHeaderIndexByString(headers, SurfaceLineCsvColumnNames.LocationColumnName); + if (colIndexSurfaceLineId < 0) + { + colIndexSurfaceLineId = CsvReaderUtilities.GetHeaderIndexByString(headers, SurfaceLineCsvColumnNames.ProfileNameColumnName); + } + } + return colIndexSurfaceLineId; + } + /// /// Copies to temporary file. /// Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvImporters/CsvImporterScenarios.cs =================================================================== diff -u -r4070 -r4277 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvImporters/CsvImporterScenarios.cs (.../CsvImporterScenarios.cs) (revision 4070) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvImporters/CsvImporterScenarios.cs (.../CsvImporterScenarios.cs) (revision 4277) @@ -40,6 +40,8 @@ public class CsvImporterScenarios { + private int currentColIndex = -1; // Keep track of column for error message + public CsvImporterScenarios(string fileName) { ErrorMessages.Clear(); @@ -96,7 +98,6 @@ while (csv.ReadNextRecord()) { var scenario = new ScenarioRecord(); - int colIndex = -1; // Keep track of column for error message try { scenario.ScenarioRecordId = index; @@ -108,147 +109,32 @@ string value = csv[colIndexLocationScenarioId]; scenario.LocationScenarioId = string.IsNullOrWhiteSpace(value) ? null : value; - if (colIndexRiverLevel > -1) - { - colIndex = colIndexRiverLevel; - scenario.RiverLevel = Convert.ToDouble(csv[colIndexRiverLevel]); - } + scenario.RiverLevel = FetchOptionalColumnToDouble(colIndexRiverLevel, csv); + scenario.RiverLevelLow = FetchOptionalColumnToDouble(colIndexRiverLevelLow, csv); + scenario.DikeTableHeight = FetchOptionalColumnToDouble(colIndexDikeTableHeight, csv); + scenario.RequiredSafetyFactorPiping = FetchOptionalColumnToDouble(colIndexSafetyFactorPiping, csv); + scenario.RequiredSafetyFactorStabilityInnerSlope = FetchOptionalColumnToDouble(colIndexSafetyFactorStabilityInnerSlope, csv); + scenario.RequiredSafetyFactorStabilityOuterSlope = FetchOptionalColumnToDouble(colIndexSafetyFactorStabilityOuterSlope, csv); + scenario.UpliftCriterionPiping = FetchOptionalColumnToDouble(colIndexUpliftCriterionPiping, csv); + scenario.UpliftCriterionStability = FetchOptionalColumnToDouble(colIndexUpliftCriterionStability, csv); + scenario.PlLineOffsetBelowDikeTopAtRiver = FetchOptionalColumnToDouble(colIndexPlLineOffsetBelowDikeTopAtRiver, csv); + scenario.PlLineOffsetBelowDikeTopAtPolder = FetchOptionalColumnToDouble(colIndexPlLineOffsetBelowDikeTopAtPolder, csv); + scenario.PlLineOffsetBelowShoulderBaseInside = FetchOptionalColumnToDouble(colIndexPlLineOffsetBelowShoulderBaseInside, csv); + scenario.PlLineOffsetBelowDikeToeAtPolder = FetchOptionalColumnToDouble(colIndexPlLineOffsetBelowDikeToeAtPolder, csv); + scenario.PlLineOffsetBelowDikeCrestMiddle = FetchOptionalColumnToDouble(colIndexPlLineOffsetBelowDikeCrestMiddle, csv); + scenario.PlLineOffsetFactorBelowShoulderCrest = FetchOptionalColumnToDouble(colIndexPlLineOffsetFactorBelowShoulderCrest, csv); + scenario.UsePlLineOffsetBelowDikeCrestMiddle = FetchOptionalColumnToBoolean(colIndexUsePlLineOffsetBelowDikeCrestMiddle, csv); + scenario.UsePlLineOffsetFactorBelowShoulderCrest = FetchOptionalColumnToBoolean(colIndexUsePlLineOffsetFactorBelowShoulderCrest, csv); + scenario.HeadPl3 = FetchOptionalColumnToDouble(colIndexHeadPl3, csv) ?? FetchOptionalColumnToDouble(colIndexHeadPl3OldFormat, csv); + scenario.HeadPl4 = FetchOptionalColumnToDouble(colIndexHeadPl4, csv) ?? FetchOptionalColumnToDouble(colIndexHeadPl4OldFormat, csv); + scenario.PolderLevel = FetchOptionalColumnToDouble(colIndexPolderLevel, csv); + scenario.HeadPl2 = FetchOptionalColumnToDouble(colIndexHeadPl2, csv); - if (colIndexRiverLevelLow > -1) - { - colIndex = colIndexRiverLevelLow; - scenario.RiverLevelLow = Convert.ToDouble(csv[colIndex]); - } - - if (colIndexDikeTableHeight > -1) - { - colIndex = colIndexDikeTableHeight; - scenario.DikeTableHeight = Convert.ToDouble(csv[colIndexDikeTableHeight]); - } - - if (colIndexSafetyFactorPiping > -1) - { - colIndex = colIndexSafetyFactorPiping; - scenario.RequiredSafetyFactorPiping = Convert.ToDouble(csv[colIndex]); - } - - if (colIndexSafetyFactorStabilityInnerSlope > -1) - { - colIndex = colIndexSafetyFactorStabilityInnerSlope; - scenario.RequiredSafetyFactorStabilityInnerSlope = Convert.ToDouble(csv[colIndex]); - } - - if (colIndexSafetyFactorStabilityOuterSlope > -1) - { - colIndex = colIndexSafetyFactorStabilityOuterSlope; - scenario.RequiredSafetyFactorStabilityOuterSlope = Convert.ToDouble(csv[colIndex]); - } - - if (colIndexUpliftCriterionPiping > -1) - { - colIndex = colIndexUpliftCriterionPiping; - scenario.UpliftCriterionPiping = Convert.ToDouble(csv[colIndex]); - } - - if (colIndexUpliftCriterionStability > -1) - { - colIndex = colIndexUpliftCriterionStability; - scenario.UpliftCriterionStability = Convert.ToDouble(csv[colIndex]); - } - - if (colIndexPlLineOffsetBelowDikeTopAtRiver > -1) - { - colIndex = colIndexPlLineOffsetBelowDikeTopAtRiver; - scenario.PlLineOffsetBelowDikeTopAtRiver = Convert.ToDouble(csv[colIndex]); - } - - if (colIndexPlLineOffsetBelowDikeTopAtPolder > -1) - { - colIndex = colIndexPlLineOffsetBelowDikeTopAtPolder; - scenario.PlLineOffsetBelowDikeTopAtPolder = Convert.ToDouble(csv[colIndex]); - } - - if (colIndexPlLineOffsetBelowShoulderBaseInside > -1) - { - colIndex = colIndexPlLineOffsetBelowShoulderBaseInside; - scenario.PlLineOffsetBelowShoulderBaseInside = Convert.ToDouble(csv[colIndex]); - } - - if (colIndexPlLineOffsetBelowDikeToeAtPolder > -1) - { - colIndex = colIndexPlLineOffsetBelowDikeToeAtPolder; - scenario.PlLineOffsetBelowDikeToeAtPolder = Convert.ToDouble(csv[colIndex]); - } - - if (colIndexPlLineOffsetBelowDikeCrestMiddle > -1) - { - colIndex = colIndexPlLineOffsetBelowDikeCrestMiddle; - scenario.PlLineOffsetBelowDikeCrestMiddle = Convert.ToDouble(csv[colIndex]); - } - - if (colIndexPlLineOffsetFactorBelowShoulderCrest > -1) - { - colIndex = colIndexPlLineOffsetFactorBelowShoulderCrest; - scenario.PlLineOffsetFactorBelowShoulderCrest = Convert.ToDouble(csv[colIndex]); - } - - if (colIndexUsePlLineOffsetBelowDikeCrestMiddle > -1) - { - colIndex = colIndexUsePlLineOffsetBelowDikeCrestMiddle; - scenario.UsePlLineOffsetBelowDikeCrestMiddle = Convert.ToBoolean(csv[colIndex]); - } - - if (colIndexUsePlLineOffsetFactorBelowShoulderCrest > -1) - { - colIndex = colIndexUsePlLineOffsetFactorBelowShoulderCrest; - scenario.UsePlLineOffsetFactorBelowShoulderCrest = Convert.ToBoolean(csv[colIndex]); - } - - if (colIndexHeadPl3 > -1) - { - colIndex = colIndexHeadPl3; - scenario.HeadPl3 = Convert.ToDouble(csv[colIndex]); - } - else - { - if (colIndexHeadPl3OldFormat > -1) - { - colIndex = colIndexHeadPl3OldFormat; - scenario.HeadPl3 = Convert.ToDouble(csv[colIndex]); - } - } - - if (colIndexHeadPl4 > -1) - { - colIndex = colIndexHeadPl4; - scenario.HeadPl4 = Convert.ToDouble(csv[colIndex]); - } - else - { - if (colIndexHeadPl4OldFormat > -1) - { - colIndex = colIndexHeadPl4OldFormat; - scenario.HeadPl4 = Convert.ToDouble(csv[colIndex]); - } - } - - if (colIndexPolderLevel > -1) - { - colIndex = colIndexPolderLevel; - scenario.PolderLevel = Convert.ToDouble(csv[colIndex]); - } - - if (colIndexHeadPl2 > -1) - { - colIndex = colIndexHeadPl2; - scenario.HeadPl2 = Convert.ToDouble(csv[colIndex]); - } - ImportedItems.Add(scenario); } catch (Exception e) { - string csvScenarioError = String.Format(LocalizationManager.GetTranslatedText(GetType(), "csvScenarioError"), scenario.LocationId, colIndex + 1); + string csvScenarioError = string.Format(LocalizationManager.GetTranslatedText(GetType(), "csvScenarioError"), scenario.LocationId, currentColIndex + 1); ErrorMessages.Add(csvScenarioError + e.Message); } } @@ -260,10 +146,32 @@ } } - public List ImportedItems { get; } = new List(); + public List ImportedItems { get; } = new (); - public List ErrorMessages { get; set; } = new List(); + public List ErrorMessages { get; set; } = new (); + + private double? FetchOptionalColumnToDouble(int colIndex, CsvReader csv) + { + if (colIndex > -1) + { + currentColIndex = colIndex; + return Convert.ToDouble(csv[colIndex]); + } + return null; + } + + private bool? FetchOptionalColumnToBoolean(int colIndex, CsvReader csv) + { + if (colIndex > -1) + { + currentColIndex = colIndex; + return Convert.ToBoolean(csv[colIndex]); + } + + return null; + } + private void CheckColumn(int index, string fileName, string fieldName) { if (index < 0) Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvImporters/CsvImporterLocations.cs =================================================================== diff -u -r4070 -r4277 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvImporters/CsvImporterLocations.cs (.../CsvImporterLocations.cs) (revision 4070) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvImporters/CsvImporterLocations.cs (.../CsvImporterLocations.cs) (revision 4277) @@ -23,7 +23,6 @@ using System.Collections.Generic; using System.Globalization; using System.IO; -using System.Linq; using System.Threading; using Deltares.Dam.Data.Importers; using Deltares.Standard.IO; @@ -34,6 +33,8 @@ public class CsvImporterLocations { + private int currentColIndex = -1; // Keep track of column for error message + public CsvImporterLocations(string fileName) { ErrorMessages.Clear(); @@ -47,7 +48,7 @@ using (var csv = new CsvReader(new StreamReader(fileName), true, ';')) { string[] headers = CsvImporterHelper.GetFieldHeaders(this, csv); - if (headers.Count() < 3) + if (headers.Length < 3) { string csvHeaderError = LocalizationManager.GetTranslatedText(GetType(), "csvHeaderError"); throw new CsvImporterSegmentsException($"{fileName} : {csvHeaderError}"); @@ -124,404 +125,108 @@ while (csv.ReadNextRecord()) { var locationRecord = new LocationRecord(); - int colIndex = -1; // Keep track of column for error message try { locationRecord.LocationRecordId = index++; - /* - * Required columns - */ + // Required columns locationRecord.LocationId = csv[colIndexLocationId]; locationRecord.SurfaceLineId = csv[colIndexSurfacelineId]; locationRecord.SegmentId = csv[colIndexSegmentId]; - /* - * Optional columns - */ - if (colIndexDikeRingId > -1) - { - colIndex = colIndexDikeRingId; - locationRecord.DikeRingId = csv[colIndexDikeRingId]; - } + // Optional columns + locationRecord.DikeRingId = FetchOptionalColumnToString(colIndexDikeRingId, csv); + locationRecord.GeoX = FetchOptionalColumnToDouble(colIndexGeoX, csv); + locationRecord.GeoY = FetchOptionalColumnToDouble(colIndexGeoY, csv); + locationRecord.XSoilGeometry2DOrigin = FetchOptionalColumnToDouble(colIndexXSoilgeometry2DOrigin, csv); + locationRecord.PolderLevel = FetchOptionalColumnToDouble(colIndexPolderlevel, csv); + locationRecord.HeadPl2 = FetchOptionalColumnToDouble(colIndexHeadPl2, csv); + locationRecord.HeadPl3 = FetchOptionalColumnToDouble(colIndexHeadPl3, csv); + locationRecord.HeadPl4 = FetchOptionalColumnToDouble(colIndexHeadPl4, csv); + locationRecord.DikeEmbankmentMaterial = FetchOptionalColumnToString(colIndexOphoogmateriaaldijk, csv); + locationRecord.ShoulderEmbankmentMaterial = FetchOptionalColumnToString(colIndexOphoogmateriaalberm, csv); + locationRecord.PenetrationLength = FetchOptionalColumnToDouble(colIndexPenetrationLength, csv); + locationRecord.TrafficLoad = FetchOptionalColumnToDouble(colIndexTrafficLoad, csv); + locationRecord.TL_DegreeOfConsolidation = FetchOptionalColumnToDouble(colIndexTL_DegreeOfConsolidation, csv); + locationRecord.MinimalCircleDepth = FetchOptionalColumnToDouble(colIndexMinimalCircleDepth, csv); + locationRecord.DampingFactorPl3 = FetchOptionalColumnToDouble(colIndexDempingsfactorPl3, csv); + locationRecord.DampingFactorPl4 = FetchOptionalColumnToDouble(colIndexDempingsfactorPl4, csv); - if (colIndexGeoX > -1) - { - colIndex = colIndexGeoX; - locationRecord.GeoX = Convert.ToDouble(csv[colIndexGeoX]); - } - - if (colIndexGeoY > -1) - { - colIndex = colIndexGeoY; - locationRecord.GeoY = Convert.ToDouble(csv[colIndexGeoY]); - } - - if (colIndexXSoilgeometry2DOrigin > -1) - { - colIndex = colIndexXSoilgeometry2DOrigin; - locationRecord.XSoilGeometry2DOrigin = Convert.ToDouble(csv[colIndexXSoilgeometry2DOrigin]); - } - - if (colIndexPolderlevel > -1) - { - colIndex = colIndexPolderlevel; - locationRecord.PolderLevel = Convert.ToDouble(csv[colIndexPolderlevel]); - } - - if (colIndexHeadPl2 > -1) - { - colIndex = colIndexHeadPl2; - locationRecord.HeadPl2 = Convert.ToDouble(csv[colIndexHeadPl2]); - } - - if (colIndexHeadPl3 > -1) - { - colIndex = colIndexHeadPl3; - locationRecord.HeadPl3 = Convert.ToDouble(csv[colIndexHeadPl3]); - } - - if (colIndexHeadPl4 > -1) - { - colIndex = colIndexHeadPl4; - locationRecord.HeadPl4 = Convert.ToDouble(csv[colIndexHeadPl4]); - } - - if (colIndexOphoogmateriaaldijk > -1) - { - colIndex = colIndexOphoogmateriaaldijk; - locationRecord.DikeEmbankmentMaterial = csv[colIndexOphoogmateriaaldijk]; - } - - if (colIndexOphoogmateriaalberm > -1) - { - colIndex = colIndexOphoogmateriaalberm; - locationRecord.ShoulderEmbankmentMaterial = csv[colIndexOphoogmateriaalberm]; - } - - if (colIndexPenetrationLength > -1) - { - colIndex = colIndexPenetrationLength; - locationRecord.PenetrationLength = Convert.ToDouble(csv[colIndexPenetrationLength]); - } - - if (colIndexTrafficLoad > -1) - { - colIndex = colIndexTrafficLoad; - locationRecord.TrafficLoad = Convert.ToDouble(csv[colIndexTrafficLoad]); - } - - if (colIndexTL_DegreeOfConsolidation > -1) - { - colIndex = colIndexTL_DegreeOfConsolidation; - locationRecord.TL_DegreeOfConsolidation = Convert.ToDouble(csv[colIndexTL_DegreeOfConsolidation]); - } - - if (colIndexMinimalCircleDepth > -1) - { - colIndex = colIndexMinimalCircleDepth; - locationRecord.MinimalCircleDepth = Convert.ToDouble(csv[colIndexMinimalCircleDepth]); - } - - if (colIndexDempingsfactorPl3 > -1) - { - colIndex = colIndexDempingsfactorPl3; - locationRecord.DampingFactorPl3 = Convert.ToDouble(csv[colIndexDempingsfactorPl3]); - } - - if (colIndexDempingsfactorPl4 > -1) - { - colIndex = colIndexDempingsfactorPl4; - locationRecord.DampingFactorPl4 = Convert.ToDouble(csv[colIndexDempingsfactorPl4]); - } - if (colIndexPLLineCreationMethod > -1) { - colIndex = colIndexPLLineCreationMethod; + currentColIndex = colIndexPLLineCreationMethod; locationRecord.PLLineCreationMethod = LocationImportHelper.ToPLLineCreationMethod(csv[colIndexPLLineCreationMethod]); } - if (colIndexSafetyFactorPiping > -1) - { - colIndex = colIndexSafetyFactorPiping; - locationRecord.RequiredSafetyFactorPiping = Convert.ToDouble(csv[colIndexSafetyFactorPiping]); - } + locationRecord.RequiredSafetyFactorPiping = FetchOptionalColumnToDouble(colIndexSafetyFactorPiping, csv); + locationRecord.RequiredSafetyFactorStabilityInnerSlope = FetchOptionalColumnToDouble(colIndexSafetyFactorStabilityInnerSlope, csv); + locationRecord.RequiredSafetyFactorStabilityOuterSlope = FetchOptionalColumnToDouble(colIndexSafetyFactorStabilityOuterSlope, csv); + locationRecord.UpliftCriterionPiping = FetchOptionalColumnToDouble(colIndexUpliftCriterionPiping, csv); + locationRecord.UpliftCriterionStability = FetchOptionalColumnToDouble(colIndexUpliftCriterionStability, csv); + locationRecord.DistanceToEntryPoint = FetchOptionalColumnToDouble(colIndexDistanceToEntryPoint, csv); + locationRecord.PlLineOffsetBelowDikeTopAtRiver = FetchOptionalColumnToDouble(colIndexPLLineOffsetBelowDikeTopAtRiver, csv); + locationRecord.PlLineOffsetBelowDikeTopAtPolder = FetchOptionalColumnToDouble(colIndexPLLineOffsetBelowDikeTopAtPolder, csv); + locationRecord.PlLineOffsetBelowShoulderBaseInside = FetchOptionalColumnToDouble(colIndexPLLineOffsetBelowShoulderBaseInside, csv); + locationRecord.PlLineOffsetBelowDikeToeAtPolder = FetchOptionalColumnToDouble(colIndexPLLineOffsetBelowDikeToeAtPolder, csv); + locationRecord.PlLineOffsetBelowDikeCrestMiddle = FetchOptionalColumnToDouble(colIndexPlLineOffsetBelowDikeCrestMiddle, csv); + locationRecord.PlLineOffsetFactorBelowShoulderCrest = FetchOptionalColumnToDouble(colIndexPlLineOffsetFactorBelowShoulderCrest, csv); + locationRecord.UsePlLineOffsetBelowDikeCrestMiddle = FetchOptionalColumnToBoolean(colIndexUsePlLineOffsetBelowDikeCrestMiddle, csv); + locationRecord.UsePlLineOffsetFactorBelowShoulderCrest = FetchOptionalColumnToBoolean(colIndexUsePlLineOffsetFactorBelowShoulderCrest, csv); - if (colIndexSafetyFactorStabilityInnerSlope > -1) - { - colIndex = colIndexSafetyFactorStabilityInnerSlope; - locationRecord.RequiredSafetyFactorStabilityInnerSlope = Convert.ToDouble(csv[colIndexSafetyFactorStabilityInnerSlope]); - } - - if (colIndexSafetyFactorStabilityOuterSlope > -1) - { - colIndex = colIndexSafetyFactorStabilityOuterSlope; - locationRecord.RequiredSafetyFactorStabilityOuterSlope = Convert.ToDouble(csv[colIndexSafetyFactorStabilityOuterSlope]); - } - - if (colIndexUpliftCriterionPiping > -1) - { - colIndex = colIndexUpliftCriterionPiping; - locationRecord.UpliftCriterionPiping = Convert.ToDouble(csv[colIndexUpliftCriterionPiping]); - } - - if (colIndexUpliftCriterionStability > -1) - { - colIndex = colIndexUpliftCriterionStability; - locationRecord.UpliftCriterionStability = Convert.ToDouble(csv[colIndexUpliftCriterionStability]); - } - - if (colIndexDistanceToEntryPoint > -1) - { - colIndex = colIndexDistanceToEntryPoint; - locationRecord.DistanceToEntryPoint = Convert.ToDouble(csv[colIndexDistanceToEntryPoint]); - } - - if (colIndexPLLineOffsetBelowDikeTopAtRiver > -1) - { - colIndex = colIndexPLLineOffsetBelowDikeTopAtRiver; - locationRecord.PlLineOffsetBelowDikeTopAtRiver = Convert.ToDouble(csv[colIndexPLLineOffsetBelowDikeTopAtRiver]); - } - - if (colIndexPLLineOffsetBelowDikeTopAtPolder > -1) - { - colIndex = colIndexPLLineOffsetBelowDikeTopAtPolder; - locationRecord.PlLineOffsetBelowDikeTopAtPolder = Convert.ToDouble(csv[colIndexPLLineOffsetBelowDikeTopAtPolder]); - } - - if (colIndexPLLineOffsetBelowShoulderBaseInside > -1) - { - colIndex = colIndexPLLineOffsetBelowShoulderBaseInside; - locationRecord.PlLineOffsetBelowShoulderBaseInside = Convert.ToDouble(csv[colIndexPLLineOffsetBelowShoulderBaseInside]); - } - - if (colIndexPLLineOffsetBelowDikeToeAtPolder > -1) - { - colIndex = colIndexPLLineOffsetBelowDikeToeAtPolder; - locationRecord.PlLineOffsetBelowDikeToeAtPolder = Convert.ToDouble(csv[colIndexPLLineOffsetBelowDikeToeAtPolder]); - } - - if (colIndexPlLineOffsetBelowDikeCrestMiddle > -1) - { - colIndex = colIndexPlLineOffsetBelowDikeCrestMiddle; - locationRecord.PlLineOffsetBelowDikeCrestMiddle = Convert.ToDouble(csv[colIndex]); - } - - if (colIndexPlLineOffsetFactorBelowShoulderCrest > -1) - { - colIndex = colIndexPlLineOffsetFactorBelowShoulderCrest; - locationRecord.PlLineOffsetFactorBelowShoulderCrest = Convert.ToDouble(csv[colIndex]); - } - - if (colIndexUsePlLineOffsetBelowDikeCrestMiddle > -1) - { - colIndex = colIndexUsePlLineOffsetBelowDikeCrestMiddle; - locationRecord.UsePlLineOffsetBelowDikeCrestMiddle = Convert.ToBoolean(csv[colIndex]); - } - - if (colIndexUsePlLineOffsetFactorBelowShoulderCrest > -1) - { - colIndex = colIndexUsePlLineOffsetFactorBelowShoulderCrest; - locationRecord.UsePlLineOffsetFactorBelowShoulderCrest = Convert.ToBoolean(csv[colIndex]); - } - if (colIndexIntrusionVerticalWaterPressure > -1) { - colIndex = colIndexIntrusionVerticalWaterPressure; - locationRecord.IntrusionVerticalWaterPressure = LocationImportHelper.ToIntrusionVerticalWaterPressure(csv[colIndex]); + currentColIndex = colIndexIntrusionVerticalWaterPressure; + locationRecord.IntrusionVerticalWaterPressure = LocationImportHelper.ToIntrusionVerticalWaterPressure(csv[currentColIndex]); } - if (colIndexStabilityShoulderGrowSlope > -1) - { - colIndex = colIndexStabilityShoulderGrowSlope; - locationRecord.StabilityShoulderGrowSlope = Convert.ToDouble(csv[colIndexStabilityShoulderGrowSlope]); - } + locationRecord.StabilityShoulderGrowSlope = FetchOptionalColumnToDouble(colIndexStabilityShoulderGrowSlope, csv); + locationRecord.StabilityShoulderGrowDeltaX = FetchOptionalColumnToDouble(colIndexStabilityShoulderGrowDeltaX, csv); + locationRecord.StabilitySlopeAdaptionDeltaX = FetchOptionalColumnToDouble(colIndexStabilitySlopeAdaptionDeltaX, csv); - if (colIndexStabilityShoulderGrowDeltaX > -1) - { - colIndex = colIndexStabilityShoulderGrowDeltaX; - locationRecord.StabilityShoulderGrowDeltaX = Convert.ToDouble(csv[colIndexStabilityShoulderGrowDeltaX]); - } - - if (colIndexStabilitySlopeAdaptionDeltaX > -1) - { - colIndex = colIndexStabilitySlopeAdaptionDeltaX; - locationRecord.StabilitySlopeAdaptionDeltaX = Convert.ToDouble(csv[colIndexStabilitySlopeAdaptionDeltaX]); - } - if (colIndexStabilityDesignMethod > -1) { - colIndex = colIndexStabilityDesignMethod; + currentColIndex = colIndexStabilityDesignMethod; locationRecord.StabilityDesignMethod = LocationImportHelper.ToStabilityDesignMethod(csv[colIndexStabilityDesignMethod]); } if (colIndexStabilityZoneType > -1) { - colIndex = colIndexStabilityZoneType; + currentColIndex = colIndexStabilityZoneType; locationRecord.StabilityZoneType = LocationImportHelper.ToMStabZonesTypeMethod(csv[colIndexStabilityZoneType]); } - if (colIndexForbiddenZoneFactor > -1) - { - colIndex = colIndexForbiddenZoneFactor; - locationRecord.ForbiddenZoneFactor = Convert.ToDouble(csv[colIndexForbiddenZoneFactor]); - } + locationRecord.ForbiddenZoneFactor = FetchOptionalColumnToDouble(colIndexForbiddenZoneFactor, csv); + locationRecord.SlopeAdaptionStartCotangent = FetchOptionalColumnToDouble(colIndexSlopeAdaptionStartCotangent, csv); + locationRecord.SlopeAdaptionEndCotangent = FetchOptionalColumnToDouble(colIndexSlopeAdaptionEndCotangent, csv); + locationRecord.SlopeAdaptionStepCotangent = FetchOptionalColumnToDouble(colIndexSlopeAdaptionStepCotangent, csv); + locationRecord.SlopeDampingPiezometricHeightPolderSide = FetchOptionalColumnToDouble(colIndexSlopeDampingPiezometricHeightPolderSide, csv); + locationRecord.NewDikeTopWidth = FetchOptionalColumnToDouble(colIndexNewDikeTopWidth, csv); + locationRecord.NewDikeSlopeInside = FetchOptionalColumnToDouble(colIndexNewDikeSlopeInside, csv); + locationRecord.NewDikeSlopeOutside = FetchOptionalColumnToDouble(colIndexNewDikeSlopeOutside, csv); + locationRecord.NewShoulderTopSlope = FetchOptionalColumnToDouble(colIndexNewShoulderTopSlope, csv); + locationRecord.NewShoulderBaseSlope = FetchOptionalColumnToDouble(colIndexNewShoulderBaseSlope, csv); + locationRecord.NewMaxHeightShoulderAsFraction = FetchOptionalColumnToDouble(colIndexNewMaxHeightShoulderAsFraction, csv); + locationRecord.NewMinDistanceDikeToeStartDitch = FetchOptionalColumnToDouble(colIndexNewMinDistanceDikeToeStartDitch, csv); + locationRecord.NewWidthDitchBottom = FetchOptionalColumnToDouble(colIndexNewWidthDitchBottom, csv); + locationRecord.NewSlopeAngleDitch = FetchOptionalColumnToDouble(colIndexNewSlopeAngleDitch, csv); + locationRecord.NewDepthDitch = FetchOptionalColumnToDouble(colIndexNewDepthDitch, csv); + locationRecord.UseNewDikeTopWidth = FetchOptionalColumnToBoolean(colIndexUseNewDikeTopWidth, csv); + locationRecord.UseNewDikeSlopeInside = FetchOptionalColumnToBoolean(colIndexUseNewDikeSlopeInside, csv); + locationRecord.UseNewDikeSlopeOutside = FetchOptionalColumnToBoolean(colIndexUseNewDikeSlopeOutside, csv); + locationRecord.UseNewShoulderTopSlope = FetchOptionalColumnToBoolean(colIndexUseNewShoulderTopSlope, csv); + locationRecord.UseNewShoulderBaseSlope = FetchOptionalColumnToBoolean(colIndexUseNewShoulderBaseSlope, csv); + locationRecord.UseNewMaxHeightShoulderAsFraction = FetchOptionalColumnToBoolean(colIndexUseNewMaxHeightShoulderAsFraction, csv); + locationRecord.UseNewMinDistanceDikeToeStartDitch = FetchOptionalColumnToBoolean(colIndexUseNewMinDistanceDikeToeStartDitch, csv); + locationRecord.UseNewDitchDefinition = FetchOptionalColumnToBoolean(colIndexUseNewDitchDefinition, csv); + locationRecord.DikeTableHeight = FetchOptionalColumnToDouble(colIndexDikeTableHeight, csv); + locationRecord.RiverLevel = FetchOptionalColumnToDouble(colIndexRiverLevel, csv); + locationRecord.RiverLevelLow = FetchOptionalColumnToDouble(colIndexRiverLevelLow, csv); - if (colIndexSlopeAdaptionStartCotangent > -1) - { - colIndex = colIndexSlopeAdaptionStartCotangent; - locationRecord.SlopeAdaptionStartCotangent = Convert.ToDouble(csv[colIndexSlopeAdaptionStartCotangent]); - } - - if (colIndexSlopeAdaptionEndCotangent > -1) - { - colIndex = colIndexSlopeAdaptionEndCotangent; - locationRecord.SlopeAdaptionEndCotangent = Convert.ToDouble(csv[colIndexSlopeAdaptionEndCotangent]); - } - - if (colIndexSlopeAdaptionStepCotangent > -1) - { - colIndex = colIndexSlopeAdaptionStepCotangent; - locationRecord.SlopeAdaptionStepCotangent = Convert.ToDouble(csv[colIndexSlopeAdaptionStepCotangent]); - } - - if (colIndexSlopeDampingPiezometricHeightPolderSide > -1) - { - colIndex = colIndexSlopeDampingPiezometricHeightPolderSide; - locationRecord.SlopeDampingPiezometricHeightPolderSide = Convert.ToDouble(csv[colIndexSlopeDampingPiezometricHeightPolderSide]); - } - - if (colIndexNewDikeTopWidth > -1) - { - colIndex = colIndexNewDikeTopWidth; - locationRecord.NewDikeTopWidth = Convert.ToDouble(csv[colIndexNewDikeTopWidth]); - } - - if (colIndexNewDikeSlopeInside > -1) - { - colIndex = colIndexNewDikeSlopeInside; - locationRecord.NewDikeSlopeInside = Convert.ToDouble(csv[colIndexNewDikeSlopeInside]); - } - - if (colIndexNewDikeSlopeOutside > -1) - { - colIndex = colIndexNewDikeSlopeOutside; - locationRecord.NewDikeSlopeOutside = Convert.ToDouble(csv[colIndexNewDikeSlopeOutside]); - } - - if (colIndexNewShoulderTopSlope > -1) - { - colIndex = colIndexNewShoulderTopSlope; - locationRecord.NewShoulderTopSlope = Convert.ToDouble(csv[colIndexNewShoulderTopSlope]); - } - - if (colIndexNewShoulderBaseSlope > -1) - { - colIndex = colIndexNewShoulderBaseSlope; - locationRecord.NewShoulderBaseSlope = Convert.ToDouble(csv[colIndexNewShoulderBaseSlope]); - } - - if (colIndexNewMaxHeightShoulderAsFraction > -1) - { - colIndex = colIndexNewMaxHeightShoulderAsFraction; - locationRecord.NewMaxHeightShoulderAsFraction = Convert.ToDouble(csv[colIndexNewMaxHeightShoulderAsFraction]); - } - - if (colIndexNewMinDistanceDikeToeStartDitch > -1) - { - colIndex = colIndexNewMinDistanceDikeToeStartDitch; - locationRecord.NewMinDistanceDikeToeStartDitch = Convert.ToDouble(csv[colIndexNewMinDistanceDikeToeStartDitch]); - } - - if (colIndexNewWidthDitchBottom > -1) - { - colIndex = colIndexNewWidthDitchBottom; - locationRecord.NewWidthDitchBottom = Convert.ToDouble(csv[colIndexNewWidthDitchBottom]); - } - - if (colIndexNewSlopeAngleDitch > -1) - { - colIndex = colIndexNewSlopeAngleDitch; - locationRecord.NewSlopeAngleDitch = Convert.ToDouble(csv[colIndexNewSlopeAngleDitch]); - } - - if (colIndexNewDepthDitch > -1) - { - colIndex = colIndexNewDepthDitch; - locationRecord.NewDepthDitch = Convert.ToDouble(csv[colIndexNewDepthDitch]); - } - - if (colIndexUseNewDikeTopWidth > -1) - { - colIndex = colIndexUseNewDikeTopWidth; - locationRecord.UseNewDikeTopWidth = Convert.ToBoolean(csv[colIndexUseNewDikeTopWidth]); - } - - if (colIndexUseNewDikeSlopeInside > -1) - { - colIndex = colIndexUseNewDikeSlopeInside; - locationRecord.UseNewDikeSlopeInside = Convert.ToBoolean(csv[colIndexUseNewDikeSlopeInside]); - } - - if (colIndexUseNewDikeSlopeOutside > -1) - { - colIndex = colIndexUseNewDikeSlopeOutside; - locationRecord.UseNewDikeSlopeOutside = Convert.ToBoolean(csv[colIndexUseNewDikeSlopeOutside]); - } - - if (colIndexUseNewShoulderTopSlope > -1) - { - colIndex = colIndexUseNewShoulderTopSlope; - locationRecord.UseNewShoulderTopSlope = Convert.ToBoolean(csv[colIndexUseNewShoulderTopSlope]); - } - - if (colIndexUseNewShoulderBaseSlope > -1) - { - colIndex = colIndexUseNewShoulderBaseSlope; - locationRecord.UseNewShoulderBaseSlope = Convert.ToBoolean(csv[colIndexUseNewShoulderBaseSlope]); - } - - if (colIndexUseNewMaxHeightShoulderAsFraction > -1) - { - colIndex = colIndexUseNewMaxHeightShoulderAsFraction; - locationRecord.UseNewMaxHeightShoulderAsFraction = Convert.ToBoolean(csv[colIndexUseNewMaxHeightShoulderAsFraction]); - } - - if (colIndexUseNewMinDistanceDikeToeStartDitch > -1) - { - colIndex = colIndexUseNewMinDistanceDikeToeStartDitch; - locationRecord.UseNewMinDistanceDikeToeStartDitch = Convert.ToBoolean(csv[colIndexUseNewMinDistanceDikeToeStartDitch]); - } - - if (colIndexUseNewDitchDefinition > -1) - { - colIndex = colIndexUseNewDitchDefinition; - locationRecord.UseNewDitchDefinition = Convert.ToBoolean(csv[colIndexUseNewDitchDefinition]); - } - - if (colIndexDikeTableHeight > -1) - { - colIndex = colIndexDikeTableHeight; - locationRecord.DikeTableHeight = Convert.ToDouble(csv[colIndexDikeTableHeight]); - } - - if (colIndexRiverLevel > -1) - { - colIndex = colIndexRiverLevel; - locationRecord.RiverLevel = Convert.ToDouble(csv[colIndexRiverLevel]); - } - - if (colIndexRiverLevelLow > -1) - { - colIndex = colIndexRiverLevelLow; - locationRecord.RiverLevelLow = Convert.ToDouble(csv[colIndexRiverLevelLow]); - } - ImportedItems.Add(locationRecord); } catch (Exception e) { - string csvLocationError = String.Format(LocalizationManager.GetTranslatedText(GetType(), "csvLocationError"), locationRecord.LocationId, colIndex + 1); + string csvLocationError = string.Format(LocalizationManager.GetTranslatedText(GetType(), "csvLocationError"), locationRecord.LocationId, currentColIndex + 1); ErrorMessages.Add(csvLocationError + e.Message); } } @@ -533,18 +238,50 @@ } } - public List ImportedItems { get; } = new List(); + public List ImportedItems { get; } = new (); - public List ErrorMessages { get; set; } = new List(); + public List ErrorMessages { get; set; } = new (); + + private double? FetchOptionalColumnToDouble(int colIndex, CsvReader csv) + { + if (colIndex > -1) + { + currentColIndex = colIndex; + return Convert.ToDouble(csv[colIndex]); + } + return null; + } + + private bool? FetchOptionalColumnToBoolean(int colIndex, CsvReader csv) + { + if (colIndex > -1) + { + currentColIndex = colIndex; + return Convert.ToBoolean(csv[colIndex]); + } + + return null; + } + + private string FetchOptionalColumnToString(int colIndex, CsvReader csv) + { + if (colIndex > -1) + { + currentColIndex = colIndex; + return csv[colIndex]; + } + + return null; + } + public class LocationRecord { public IntrusionVerticalWaterPressureType? IntrusionVerticalWaterPressure; public int LocationRecordId { get; set; } public string LocationId { get; set; } public string SurfaceLineId { get; set; } public string SegmentId { get; set; } - public string DikeRingId { get; set; } public double? GeoX { get; set; } public double? GeoY { get; set; }