// Copyright (C) Stichting Deltares 2016. All rights reserved.
//
// This file is part of Ringtoets.
//
// Ringtoets is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using Core.Common.Base.Service;
using Ringtoets.HydraRing.Calculation.Services;
namespace Ringtoets.HydraRing.Calculation.Activities
{
///
/// Base implementation of an for running calculations via Hydra-Ring.
///
public abstract class HydraRingActivityBase : Activity
{
protected override void OnCancel()
{
HydraRingCalculationService.CancelRunningCalculation();
}
protected override void OnRun()
{
if (!Validate())
{
State = ActivityState.Failed;
}
else
{
PerformCalculation();
}
}
///
/// Updates the progress text using the parameters in a predefined format.
///
/// A short description of the current step.
/// The number of the current step.
/// The total numbers of steps.
protected void UpdateProgressText(string currentStepName, int currentStep, int totalSteps)
{
ProgressText = string.Format("Stap {0} van {1} | {2}", currentStep, totalSteps, currentStepName);
}
///
/// Performs the calculation. May throw exceptions, which will result in a
/// state for the .
///
protected abstract void PerformCalculation();
///
/// Performs validation over the input of the . If the input is not valid
/// then false is returned and the problems are logged.
///
/// true if no validation problems were found, false otherwise.
protected virtual bool Validate()
{
return true;
}
}
}