Index: Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/StochasticSoilModelReader.cs =================================================================== diff -u -r28064349855037e892288c81383f1413f4e84f4c -rd79bb06ea81984ab9741f0b3ec8adba380b80d0a --- Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/StochasticSoilModelReader.cs (.../StochasticSoilModelReader.cs) (revision 28064349855037e892288c81383f1413f4e84f4c) +++ Ringtoets/Common/src/Ringtoets.Common.IO/SoilProfile/StochasticSoilModelReader.cs (.../StochasticSoilModelReader.cs) (revision d79bb06ea81984ab9741f0b3ec8adba380b80d0a) @@ -39,8 +39,10 @@ { private readonly Dictionary soilProfile1Ds = new Dictionary(); private readonly Dictionary soilProfile2Ds = new Dictionary(); + private IDataReader dataReader; private SegmentPointReader segmentPointReader; + private long currentStochasticSoilModelId = -1; /// /// Creates a new instance of @@ -207,24 +209,40 @@ } StochasticSoilModel stochasticSoilModel = CreateStochasticSoilModel(); - long currentSoilModelId = ReadStochasticSoilModelId(); + currentStochasticSoilModelId = ReadStochasticSoilModelId(); SetGeometry(stochasticSoilModel); - stochasticSoilModel.StochasticSoilProfiles.AddRange(ReadStochasticSoilProfiles(currentSoilModelId)); + SetStochasticSoilProfiles(stochasticSoilModel); return stochasticSoilModel; } /// + /// Sets objects that belong to soil model. + /// + /// The stochastic soil model of which the profiles to set. + /// Thrown when: + /// + /// No stochastic soil profiles could be read; + /// The read failure mechanism type is not supported. + /// + /// + private void SetStochasticSoilProfiles(StochasticSoilModel stochasticSoilModel) + { + if (MoveToStochasticSoilModel(currentStochasticSoilModelId)) + { + stochasticSoilModel.StochasticSoilProfiles.AddRange(ReadStochasticSoilProfiles()); + } + } + + /// /// Sets the geometry points of from the database. /// /// The stochastic soil model of which the geometry to set. /// Thrown when the geometry could not be read. private void SetGeometry(StochasticSoilModel stochasticSoilModel) { - long currentSoilModelId = ReadStochasticSoilModelId(); - - if (!segmentPointReader.MoveToStochasticSoilModel(currentSoilModelId)) + if (!segmentPointReader.MoveToStochasticSoilModel(currentStochasticSoilModelId)) { throw new StochasticSoilModelException( string.Format(Resources.SegmentPointReader_ReadSegmentPoint_StochasticSoilModel_0_must_contain_geometry, @@ -235,20 +253,38 @@ } /// - /// Reads and returns objects that belong to soil model - /// with id . + /// Moves the reader to the stochastic soil model with id . /// - /// The database identifier of the soil model. + /// The id of the stochastic soil model. + /// true if the reader was moved to the stochastic soil model with id + /// successfully, false otherwise. + private bool MoveToStochasticSoilModel(long stochasticSoilModelId) + { + while (HasNext && ReadStochasticSoilModelId() <= stochasticSoilModelId) + { + if (ReadStochasticSoilModelId() == stochasticSoilModelId) + { + currentStochasticSoilModelId = stochasticSoilModelId; + return true; + } + MoveNext(); + } + return false; + } + + /// + /// Reads and returns objects that belong to soil model. + /// /// The read stochastic soil profiles. /// Thrown when: /// /// No stochastic soil profiles could be read; /// The read failure mechanism type is not supported. /// /// - private IEnumerable ReadStochasticSoilProfiles(long stochasticSoilModelId) + private IEnumerable ReadStochasticSoilProfiles() { - while (HasNext && ReadStochasticSoilModelId() == stochasticSoilModelId) + while (HasNext && ReadStochasticSoilModelId() == currentStochasticSoilModelId) { double? probability = ReadStochasticSoilProfileProbability();