Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvImporters/CsvImporterAquifers.cs =================================================================== diff -u -r4951 -r4971 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvImporters/CsvImporterAquifers.cs (.../CsvImporterAquifers.cs) (revision 4951) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvImporters/CsvImporterAquifers.cs (.../CsvImporterAquifers.cs) (revision 4971) @@ -65,58 +65,63 @@ int colIndexLayerName = CsvReaderUtilities.GetHeaderIndexByString(headers, fieldLayerName); CheckColumn(colIndexLayerName, fileName, fieldLayerName); - var index = 1; - while (csv.ReadNextRecord()) - { - var aquiferRecord = new AquiferRecord(); - int colIndex = -1; // Keep track of column for error message - try - { - aquiferRecord.AquiferRecordId = index; - index++; + ReadRecords(csv, colIndexStixFilename, colIndexLayerName); + } + } + finally + { + Thread.CurrentThread.CurrentCulture = oldCultureInfo; + } + } - // Required columns - colIndex = colIndexStixFilename; - aquiferRecord.StixFileName = csv[colIndexStixFilename]; - colIndex = colIndexLayerName; - aquiferRecord.LayerName = csv[colIndexLayerName]; + private void ReadRecords(CsvReader csv, int colIndexStixFilename, int colIndexLayerName) + { + var index = 1; + while (csv.ReadNextRecord()) + { + var aquiferRecord = new AquiferRecord(); + int colIndex = -1; // Keep track of column for error message + try + { + aquiferRecord.AquiferRecordId = index; + index++; - if (string.IsNullOrEmpty(aquiferRecord.StixFileName) || string.IsNullOrEmpty(aquiferRecord.LayerName)) - { - if (string.IsNullOrEmpty(aquiferRecord.StixFileName) && string.IsNullOrEmpty(aquiferRecord.LayerName)) - { - continue; // ignore empty records - } + // Required columns + colIndex = colIndexStixFilename; + aquiferRecord.StixFileName = csv[colIndexStixFilename]; + colIndex = colIndexLayerName; + aquiferRecord.LayerName = csv[colIndexLayerName]; - string recordError; - if (string.IsNullOrEmpty(aquiferRecord.StixFileName)) - { - recordError = string.Format(LocalizationManager.GetTranslatedText(GetType(), "noStixFileNameForAquiferRecordError"), index - 1); - } - else - { - recordError = string.Format(LocalizationManager.GetTranslatedText(GetType(), "noLayerNameForAquiferRecordError"), index - 1); - } - ErrorMessages.Add($"{recordError}"); - } - else - { - ImportedItems.Add(aquiferRecord); - } + if (string.IsNullOrEmpty(aquiferRecord.StixFileName) || string.IsNullOrEmpty(aquiferRecord.LayerName)) + { + if (string.IsNullOrEmpty(aquiferRecord.StixFileName) && string.IsNullOrEmpty(aquiferRecord.LayerName)) + { + continue; // ignore empty records } - catch (Exception e) + + string recordError; + if (string.IsNullOrEmpty(aquiferRecord.StixFileName)) { - string csvAquiferError = string.Format(LocalizationManager.GetTranslatedText(GetType(), "csvAquiferError"), - colIndex + 1); - ErrorMessages.Add($"Record {index - 1}: {csvAquiferError + e.Message}"); + recordError = string.Format(LocalizationManager.GetTranslatedText(GetType(), "noStixFileNameForAquiferRecordError"), index - 1); } + else + { + recordError = string.Format(LocalizationManager.GetTranslatedText(GetType(), "noLayerNameForAquiferRecordError"), index - 1); + } + ErrorMessages.Add($"{recordError}"); } + else + { + ImportedItems.Add(aquiferRecord); + } } + catch (Exception e) + { + string csvAquiferError = string.Format(LocalizationManager.GetTranslatedText(GetType(), "csvAquiferError"), + colIndex + 1); + ErrorMessages.Add($"Record {index - 1}: {csvAquiferError + e.Message}"); + } } - finally - { - Thread.CurrentThread.CurrentCulture = oldCultureInfo; - } } public List ImportedItems { get; } = new();