Index: Riskeer/Piping/src/Riskeer.Piping.Forms/PropertyClasses/Probabilistic/ProbabilisticPipingInputContextProperties.cs
===================================================================
diff -u -rd4d2f77068728d99a7336ef1251c24a5c7c05224 -r1985d614b8779c0b94e032296f68cb518d527375
--- Riskeer/Piping/src/Riskeer.Piping.Forms/PropertyClasses/Probabilistic/ProbabilisticPipingInputContextProperties.cs (.../ProbabilisticPipingInputContextProperties.cs) (revision d4d2f77068728d99a7336ef1251c24a5c7c05224)
+++ Riskeer/Piping/src/Riskeer.Piping.Forms/PropertyClasses/Probabilistic/ProbabilisticPipingInputContextProperties.cs (.../ProbabilisticPipingInputContextProperties.cs) (revision 1985d614b8779c0b94e032296f68cb518d527375)
@@ -24,6 +24,7 @@
using System.ComponentModel;
using System.Drawing.Design;
using System.Linq;
+using Core.Common.Base;
using Core.Common.Base.Data;
using Core.Common.Base.Geometry;
using Core.Common.Util.Attributes;
@@ -54,7 +55,8 @@
IHasHydraulicBoundaryLocationProperty,
IHasSurfaceLineProperty,
IHasStochasticSoilModel,
- IHasStochasticSoilProfile
+ IHasStochasticSoilProfile,
+ IDisposable
{
private const int selectedHydraulicBoundaryLocationPropertyIndex = 0;
private const int dampingFactorExitPropertyIndex = 1;
@@ -83,6 +85,11 @@
private readonly IObservablePropertyChangeHandler propertyChangeHandler;
+ private readonly Observer sectionConfigurationObserver;
+ private readonly Observer inputObserver;
+
+ private PipingFailureMechanismSectionConfiguration sectionConfiguration;
+
///
/// Creates a new instance of .
///
@@ -104,7 +111,15 @@
Data = data;
+ sectionConfigurationObserver = new Observer(OnRefreshRequired);
+ inputObserver = new Observer(UpdateSectionConfiguration)
+ {
+ Observable = data
+ };
+
this.propertyChangeHandler = propertyChangeHandler;
+
+ UpdateSectionConfiguration();
}
[DynamicReadOnlyValidationMethod]
@@ -138,6 +153,12 @@
return false;
}
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
///
/// Gets the available selectable hydraulic boundary locations on .
///
@@ -180,6 +201,21 @@
return data.AvailablePipingSurfaceLines;
}
+ protected virtual void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ sectionConfigurationObserver.Dispose();
+ inputObserver.Dispose();
+ }
+ }
+
+ private void UpdateSectionConfiguration()
+ {
+ sectionConfiguration = GetSectionConfiguration();
+ sectionConfigurationObserver.Observable = sectionConfiguration;
+ }
+
private PipingFailureMechanismSectionConfiguration GetSectionConfiguration()
{
PipingFailureMechanismSectionConfiguration[] sectionConfigurations =
@@ -485,7 +521,6 @@
{
get
{
- PipingFailureMechanismSectionConfiguration sectionConfiguration = GetSectionConfiguration();
return sectionConfiguration == null ? "-" : sectionConfiguration.Section.Name;
}
}
@@ -498,7 +533,6 @@
{
get
{
- PipingFailureMechanismSectionConfiguration sectionConfiguration = GetSectionConfiguration();
return sectionConfiguration == null ? new RoundedDouble(2) : new RoundedDouble(2, sectionConfiguration.GetFailureMechanismSensitiveSectionLength());
}
}
Index: Riskeer/Piping/test/Riskeer.Piping.Forms.Test/PropertyClasses/Probabilistic/ProbabilisticPipingInputContextPropertiesTest.cs
===================================================================
diff -u -r008df28f8430dcd5c954d441a562792b92700838 -r1985d614b8779c0b94e032296f68cb518d527375
--- Riskeer/Piping/test/Riskeer.Piping.Forms.Test/PropertyClasses/Probabilistic/ProbabilisticPipingInputContextPropertiesTest.cs (.../ProbabilisticPipingInputContextPropertiesTest.cs) (revision 008df28f8430dcd5c954d441a562792b92700838)
+++ Riskeer/Piping/test/Riskeer.Piping.Forms.Test/PropertyClasses/Probabilistic/ProbabilisticPipingInputContextPropertiesTest.cs (.../ProbabilisticPipingInputContextPropertiesTest.cs) (revision 1985d614b8779c0b94e032296f68cb518d527375)
@@ -148,6 +148,7 @@
// Assert
Assert.IsInstanceOf>(properties);
+ Assert.IsInstanceOf(properties);
Assert.IsInstanceOf(properties);
Assert.IsInstanceOf(properties);
Assert.IsInstanceOf(properties);
@@ -638,6 +639,107 @@
}
[Test]
+ public void GivenPropertyControlWithData_WhenFailureMechanismSectionConfigurationUpdated_ThenRefreshRequiredEventRaised()
+ {
+ // Given
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ var handler = mocks.Stub();
+ mocks.ReplayAll();
+
+ var section = new FailureMechanismSection("Section1", new[]
+ {
+ new Point2D(0.0, 0.0),
+ new Point2D(0.5, 0.0)
+ });
+
+ var failureMechanism = new PipingFailureMechanism();
+ FailureMechanismTestHelper.SetSections(failureMechanism, new[]
+ {
+ section
+ });
+ var calculation = ProbabilisticPipingCalculationTestFactory.CreateCalculation(section);
+
+ var context = new ProbabilisticPipingInputContext(calculation.InputParameters, calculation,
+ Enumerable.Empty(),
+ Enumerable.Empty(),
+ failureMechanism, assessmentSection);
+
+ var properties = new ProbabilisticPipingInputContextProperties(context, handler);
+ {
+ var refreshRequiredRaised = 0;
+ properties.RefreshRequired += (sender, args) => refreshRequiredRaised++;
+
+ // When
+ PipingFailureMechanismSectionConfiguration sectionConfiguration = failureMechanism.SectionConfigurations.First();
+ sectionConfiguration.NotifyObservers();
+
+ // Then
+ Assert.AreEqual(1, refreshRequiredRaised);
+ }
+ }
+
+ [Test]
+ public void GivenPropertyControlWithData_WhenSectionChangedAndOldFailureMechanismSectionConfigurationUpdated_ThenNoRefreshRequiredEventRaised()
+ {
+ // Given
+ var mocks = new MockRepository();
+ var assessmentSection = mocks.Stub();
+ var handler = mocks.Stub();
+ mocks.ReplayAll();
+
+ var oldSection = new FailureMechanismSection("Section1", new[]
+ {
+ new Point2D(0.0, 0.0),
+ new Point2D(0.5, 0.0)
+ });
+ var newSection = new FailureMechanismSection("Section1", new[]
+ {
+ new Point2D(0.5, 0.0),
+ new Point2D(10.0, 0.0)
+ });
+
+ var newSurfaceLine = new PipingSurfaceLine(string.Empty)
+ {
+ ReferenceLineIntersectionWorldPoint = new Point2D(5.0, 0.0)
+ };
+ newSurfaceLine.SetGeometry(new[]
+ {
+ new Point3D(2.5, 0.0, 0.0),
+ new Point3D(4.5, 0.0, 0.0)
+ });
+
+ var failureMechanism = new PipingFailureMechanism();
+ FailureMechanismTestHelper.SetSections(failureMechanism, new[]
+ {
+ oldSection,
+ newSection
+ });
+ var calculation = ProbabilisticPipingCalculationTestFactory.CreateCalculation(oldSection);
+
+ var context = new ProbabilisticPipingInputContext(calculation.InputParameters, calculation,
+ Enumerable.Empty(),
+ Enumerable.Empty(),
+ failureMechanism, assessmentSection);
+
+ var properties = new ProbabilisticPipingInputContextProperties(context, handler);
+ {
+ // When
+ calculation.InputParameters.SurfaceLine = newSurfaceLine;
+ calculation.InputParameters.NotifyObservers();
+
+ var refreshRequiredRaised = 0;
+ properties.RefreshRequired += (sender, args) => refreshRequiredRaised++;
+
+ PipingFailureMechanismSectionConfiguration sectionConfiguration = failureMechanism.SectionConfigurations.First();
+ sectionConfiguration.NotifyObservers();
+
+ // Then
+ Assert.AreEqual(0, refreshRequiredRaised);
+ }
+ }
+
+ [Test]
public void GivenPropertiesWithData_WhenChangingProperties_ThenPropertiesSetOnInput()
{
// Given