using Deltares.Standard;
using Deltares.Standard.EventPublisher;
using Deltares.Standard.Validation;
namespace Deltares.AssessmentMechanism
{
///
/// Replaces the originally generated validation message.
/// To be used when validating across different scenarios.
///
public class ScenarioValidationResult : ValidationResult
{
private readonly ScenarioSubject reroutedSubject;
private readonly AssessmentScenario scenario;
private readonly bool changeScenario;
private readonly DikeLocationInfo scenarioParent;
///
/// Initializes a new instance of the class.
///
/// The original validation result.
/// The owner of the scenarios.
/// The scenario for which is generated.
/// Optional flag, indicating if calling should
/// cause a to be selected instead of the actual subject. By default false.
/// Optional flag, indicating if calling
/// or should cause the
/// of to be changed when true, or kept unaffected when false.
public ScenarioValidationResult(IValidationResult originalResult, DikeLocationInfo scenarioParent, AssessmentScenario scenario, bool reRouteSelectionToScenarioOwner = false, bool changeScenario = true) :
base(originalResult.MessageType, originalResult.Text, originalResult.Subject)
{
ID.AddRange(originalResult.ID);
InvalidProperties.AddRange(originalResult.InvalidProperties);
Repairer = originalResult.Repairer;
this.scenarioParent = scenarioParent;
this.scenario = scenario;
this.changeScenario = changeScenario;
if (reRouteSelectionToScenarioOwner)
{
reroutedSubject = new ScenarioSubject
{
ActualSelectedObject = scenarioParent
};
}
}
public override void Select()
{
if (changeScenario)
{
scenarioParent.CurrentScenario = scenario;
}
DataEventPublisher.SelectionChanged(reroutedSubject ?? Subject);
}
public override void Repair()
{
if (Repairer != null)
{
if (changeScenario)
{
scenarioParent.CurrentScenario = scenario;
}
base.Repair();
}
}
protected override string GetSelectName()
{
return Subject != null ?
string.Format("{0} - {1}: {2}", scenarioParent, scenario.Name, Subject) :
"";
}
}
}