Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Activities/HydraRingActivity.cs
===================================================================
diff -u -r636a79efa1f104b917c48d043151ada9fc4e69ac -r6ccc539ce58e63f0e0fbff0da189c87b65146129
--- Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Activities/HydraRingActivity.cs (.../HydraRingActivity.cs) (revision 636a79efa1f104b917c48d043151ada9fc4e69ac)
+++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.Calculation/Activities/HydraRingActivity.cs (.../HydraRingActivity.cs) (revision 6ccc539ce58e63f0e0fbff0da189c87b65146129)
@@ -20,32 +20,68 @@
// All rights reserved.
using System;
+using Core.Common.Base;
using Core.Common.Base.Service;
+using Ringtoets.HydraRing.Calculation.Services;
namespace Ringtoets.HydraRing.Calculation.Activities
{
///
/// for running calculations via Hydra-Ring.
///
- public abstract class HydraRingActivity : Activity
+ public abstract class HydraRingActivity : Activity
{
- private readonly Action beforeRunAction;
+ ///
+ /// The output of the activity.
+ ///
+ protected T Output;
+ protected abstract override void OnRun();
+
+ protected override void OnCancel()
+ {
+ HydraRingCalculationService.CancelRunningCalculation();
+ }
+
+ protected abstract override void OnFinish();
+
///
- /// Creates a new instance of the class.
+ /// Template method for performing the run of the activity.
///
- /// The action to perform before running a Hydra-Ring calculation (like clearing output, validation, etc.).
- protected HydraRingActivity(Action beforeRunAction)
+ /// The method to perform for validation.
+ /// The method to perform for clearing the data of the output to set.
+ /// The method to perform for the calculation.
+ protected void PerformRun(Func validationFunc, Action clearAction, Func calculationFunc)
{
- this.beforeRunAction = beforeRunAction;
+ if (!validationFunc())
+ {
+ State = ActivityState.Failed;
+ return;
+ }
+
+ LogMessages.Clear();
+ clearAction();
+
+ Output = calculationFunc();
+
+ if (Output == null)
+ {
+ State = ActivityState.Failed;
+ }
}
- protected override void OnRun()
+ ///
+ /// Template method for performing the finish of the activity.
+ ///
+ /// The method to set the output on the object.
+ /// The object to notify the observers upon.
+ protected void PerformFinish(Action setOutputAction, Observable observableObject)
{
- if (beforeRunAction != null)
+ if (State == ActivityState.Executed)
{
- beforeRunAction();
+ setOutputAction();
+ observableObject.NotifyObservers();
}
}
}
-}
+}
\ No newline at end of file