Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/PipingSoilProfileReader.cs =================================================================== diff -u -r33d4f4e7e5404dcc6470dd3d34168b30410109eb -ra3934ff3a7c84cc1734049e904c9635b79b6cf5c --- Ringtoets/Piping/src/Ringtoets.Piping.IO/PipingSoilProfileReader.cs (.../PipingSoilProfileReader.cs) (revision 33d4f4e7e5404dcc6470dd3d34168b30410109eb) +++ Ringtoets/Piping/src/Ringtoets.Piping.IO/PipingSoilProfileReader.cs (.../PipingSoilProfileReader.cs) (revision a3934ff3a7c84cc1734049e904c9635b79b6cf5c) @@ -17,6 +17,7 @@ { private const string pipingMechanismName = "Piping"; + private const string profileCountColumn = "ProfileCount"; private const string dimensionColumn = "Dimension"; private const string isAquiferColumn = "IsAquifer"; private const string profileNameColumn = "ProfileName"; @@ -33,12 +34,12 @@ private const string layerCountColumn = "LayerCount"; private const string mechanismParameterName = "mechanism"; - private SQLiteConnection connection; - private SQLiteDataReader dataReader; - private readonly string databaseFileName; private readonly string databaseRequiredVersion = "15.0.5.0"; + private SQLiteConnection connection; + private SQLiteDataReader dataReader; + /// /// Creates a new instance of which will use the /// as its source. The reader will not point to any record at the start. Use to start reading @@ -62,6 +63,11 @@ } /// + /// Gets the total number of profiles that can be read from the database. + /// + public int Count { get; private set; } + + /// /// Gets the value true if profiles can be read using the . /// false otherwise. /// @@ -106,7 +112,7 @@ var profileName = Read(profileNameColumn); var layerCount = Read(layerCountColumn); var bottom = Read(bottomColumn); - + var soilProfileBuilder = new SoilProfileBuilder1D(profileName, bottom); for (var i = 1; i <= layerCount; i++) @@ -123,7 +129,7 @@ var profileName = Read(profileNameColumn); var layerCount = Read(layerCountColumn); var intersectionX = Read(intersectionXColumn); - + var soilProfileBuilder = new SoilProfileBuilder2D(profileName, intersectionX); for (int i = 1; i <= layerCount; i++) @@ -136,7 +142,7 @@ { var exception = new PipingSoilProfileReadException( string.Format(Resources.PipingSoilProfileReader_CouldNotParseGeometryOfLayer_0_InProfile_1_, i, profileName), e); - + while (i++ <= layerCount) { MoveNext(); @@ -170,7 +176,7 @@ private T Read(string columnName) { - return (T)dataReader[columnName]; + return (T) dataReader[columnName]; } private void OpenConnection(string dbFile) @@ -233,11 +239,24 @@ /// private void InitializeDataReader() { + string versionQuery = string.Format( "SELECT Value FROM _Metadata WHERE Key = 'VERSION' AND Value = '{0}';", databaseRequiredVersion ); + string countQuery = string.Format(string.Join( + " ", + "SELECT", + "(SELECT COUNT(*)", + "FROM Mechanism as m", + "JOIN MechanismPointLocation as mpl ON mpl.ME_ID = m.ME_ID", + "JOIN SoilProfile2D as p2 ON p2.SP2D_ID = mpl.SP2D_ID", + "WHERE m.ME_Name = @{0})", + " + ", + "(SELECT COUNT(*)", + "FROM SoilProfile1D) as {1};"), mechanismParameterName, profileCountColumn); + string materialPropertiesQuery = string.Format( string.Join(" ", "(SELECT", @@ -368,7 +387,7 @@ layer2DPropertiesQuery, mechanismParameterName); - CreateDataReader(versionQuery + query2D + query1D, new SQLiteParameter + CreateDataReader(versionQuery + countQuery + query2D + query1D, new SQLiteParameter { DbType = DbType.String, Value = pipingMechanismName, @@ -392,6 +411,7 @@ { dataReader = query.ExecuteReader(); CheckVersion(); + GetCount(); } catch (SQLiteException e) { @@ -405,11 +425,18 @@ { if (!dataReader.HasRows) { - throw new PipingSoilProfileReadException(String.Format( + throw new PipingSoilProfileReadException(string.Format( Resources.PipingSoilProfileReader_DatabaseFileIncorrectVersions_Requires_0, databaseRequiredVersion)); } dataReader.NextResult(); } + + private void GetCount() + { + dataReader.Read(); + Count = (int)Read(profileCountColumn); + dataReader.NextResult(); + } } } \ No newline at end of file Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs =================================================================== diff -u -rd514ce187a1ce571355fd92ca1edf822d943ba39 -ra3934ff3a7c84cc1734049e904c9635b79b6cf5c --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs (.../PipingSoilProfilesImporter.cs) (revision d514ce187a1ce571355fd92ca1edf822d943ba39) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/FileImporter/PipingSoilProfilesImporter.cs (.../PipingSoilProfilesImporter.cs) (revision a3934ff3a7c84cc1734049e904c9635b79b6cf5c) @@ -5,6 +5,8 @@ using Core.Common.BaseDelftTools; using System.Linq; +using System.Threading; +using Core.Common.Utils.Collections.Extensions; using log4net; using Ringtoets.Piping.Data; using Ringtoets.Piping.IO; @@ -92,8 +94,6 @@ public object ImportItem(string path, object target = null) { - NotifyProgress(ApplicationResources.PipingSoilProfilesImporter_ReadingDatabase, 1, 2); - var importResult = ReadSoilProfiles(path); if (!importResult.CriticalErrorOccurred) @@ -111,28 +111,12 @@ return target; } - private void AddImportedDataToModel(object target, SoilProfilesReadResult importedSoilProfiles) - { - NotifyProgress(ApplicationResources.PipingSoilProfilesImporter_AddingImportedDataToModel, 2, 2); - - var targetCollection = (ICollection)target; - foreach (var soilProfile in importedSoilProfiles.ImportedSoilProfiles) - { - targetCollection.Add(soilProfile); - } - - var observableTarget = targetCollection as IObservable; - if (observableTarget != null) - { - observableTarget.NotifyObservers(); - } - } - private SoilProfilesReadResult ReadSoilProfiles(string path) { - var profiles = new Collection(); PipingSoilProfileReader soilProfileReader = null; + NotifyProgress(ApplicationResources.PipingSoilProfilesImporter_ReadingDatabase, 1, 1); + try { soilProfileReader = new PipingSoilProfileReader(path); @@ -145,10 +129,27 @@ return new SoilProfilesReadResult(true); } + return GetProfileReadResult(path, soilProfileReader); + + } + + private SoilProfilesReadResult GetProfileReadResult(string path, PipingSoilProfileReader soilProfileReader) + { + var totalNumberOfSteps = soilProfileReader.Count; + var currentStep = 1; + + NotifyProgress(ApplicationResources.PipingSoilProfilesImporter_ReadingSoilProfiles, currentStep, totalNumberOfSteps); + + var profiles = new Collection(); while (soilProfileReader.HasNext) { + if (ShouldCancel) + { + return new SoilProfilesReadResult(false); + } try { + NotifyProgress(ApplicationResources.PipingSoilProfilesImporter_ReadingSoilProfiles, currentStep++, totalNumberOfSteps); profiles.Add(soilProfileReader.ReadProfile()); } catch (PipingSoilProfileReadException e) @@ -164,11 +165,23 @@ }; } + private void AddImportedDataToModel(object target, SoilProfilesReadResult importedSoilProfiles) + { + var targetCollection = (ObservableList)target; + + int totalProfileCount = importedSoilProfiles.ImportedSoilProfiles.Count; + NotifyProgress(ApplicationResources.PipingSoilProfilesImporter_AddingImportedDataToModel, totalProfileCount, totalProfileCount); + + targetCollection.AddRange(importedSoilProfiles.ImportedSoilProfiles); + + targetCollection.NotifyObservers(); + } + private void NotifyProgress(string currentStepName, int currentStep, int totalNumberOfSteps) { if (ProgressChanged != null) { - ProgressChanged(currentStepName, currentStep, totalNumberOfSteps); + ProgressChanged(currentStepName, currentStep, totalNumberOfSteps); } } Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs =================================================================== diff -u -rd514ce187a1ce571355fd92ca1edf822d943ba39 -ra3934ff3a7c84cc1734049e904c9635b79b6cf5c --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision d514ce187a1ce571355fd92ca1edf822d943ba39) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision a3934ff3a7c84cc1734049e904c9635b79b6cf5c) @@ -97,7 +97,7 @@ } /// - /// Looks up a localized string similar to Inlezen van de D-SoilModel database.... + /// Looks up a localized string similar to Inlezen van de D-Soil Model database.... /// public static string PipingSoilProfilesImporter_ReadingDatabase { get { @@ -106,6 +106,15 @@ } /// + /// Looks up a localized string similar to Inlezen van de grondprofielen uit de D-Soil Model database.... + /// + public static string PipingSoilProfilesImporter_ReadingSoilProfiles { + get { + return ResourceManager.GetString("PipingSoilProfilesImporter_ReadingSoilProfiles", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Er is een leesfout opgetreden bij ondergrondprofiel van bestand '{0}' en is overgeslagen: {1}. /// public static string PipingSoilProfilesImporter_ReadSoilProfiles_File_0_Message_1_ { Index: Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx =================================================================== diff -u -rd514ce187a1ce571355fd92ca1edf822d943ba39 -ra3934ff3a7c84cc1734049e904c9635b79b6cf5c --- Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx (.../Resources.resx) (revision d514ce187a1ce571355fd92ca1edf822d943ba39) +++ Ringtoets/Piping/src/Ringtoets.Piping.Plugin/Properties/Resources.resx (.../Resources.resx) (revision a3934ff3a7c84cc1734049e904c9635b79b6cf5c) @@ -163,12 +163,15 @@ Grondprofielen importeren afgebroken. Geen data ingelezen. - Inlezen van de D-SoilModel database... + Inlezen van de D-Soil Model database... Er is een fout opgetreden tijdens het inlezen van '{0}' waardoor import niet uitgevoerd kan worden: {1} Er is een leesfout opgetreden bij ondergrondprofiel van bestand '{0}' en is overgeslagen: {1} + + Inlezen van de grondprofielen uit de D-Soil Model database... + \ No newline at end of file