// 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 System;
using System.Collections.Generic;
using System.Linq;
using Core.Common.Base;
using Ringtoets.ClosingStructures.Data;
using Ringtoets.ClosingStructures.Service;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.Calculation;
using Ringtoets.Common.Data.DikeProfiles;
using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.Common.Data.Hydraulics;
using Ringtoets.Common.Data.Structures;
using Ringtoets.Common.Service;
using Ringtoets.DuneErosion.Data;
using Ringtoets.DuneErosion.Service;
using Ringtoets.GrassCoverErosionInwards.Data;
using Ringtoets.GrassCoverErosionInwards.Service;
using Ringtoets.GrassCoverErosionInwards.Utils;
using Ringtoets.GrassCoverErosionOutwards.Data;
using Ringtoets.GrassCoverErosionOutwards.Service;
using Ringtoets.HeightStructures.Data;
using Ringtoets.HeightStructures.Service;
using Ringtoets.Piping.Data;
using Ringtoets.Piping.Service;
using Ringtoets.Revetment.Data;
using Ringtoets.StabilityPointStructures.Data;
using Ringtoets.StabilityPointStructures.Service;
using Ringtoets.StabilityStoneCover.Data;
using Ringtoets.StabilityStoneCover.Service;
using Ringtoets.WaveImpactAsphaltCover.Data;
using Ringtoets.WaveImpactAsphaltCover.Service;
namespace Ringtoets.Integration.Service
{
///
/// Service for synchronizing ringtoets.
///
public static class RingtoetsDataSynchronizationService
{
///
/// Clears all the output data and hydraulic boundary locations within the .
///
/// The to clear the data for.
/// An of calculations which are affected by
/// removing data.
/// /// Thrown when is null.
public static IEnumerable ClearAllCalculationOutputAndHydraulicBoundaryLocations(IAssessmentSection assessmentSection)
{
if (assessmentSection == null)
{
throw new ArgumentNullException(nameof(assessmentSection));
}
var changedObservables = new List();
foreach (var failureMechanism in assessmentSection.GetFailureMechanisms())
{
var pipingFailureMechanism = failureMechanism as PipingFailureMechanism;
var grassCoverErosionInwardsFailureMechanism = failureMechanism as GrassCoverErosionInwardsFailureMechanism;
var stabilityStoneCoverFailureMechanism = failureMechanism as StabilityStoneCoverFailureMechanism;
var heightStructuresFailureMechanism = failureMechanism as HeightStructuresFailureMechanism;
var closingStructuresFailureMechanism = failureMechanism as ClosingStructuresFailureMechanism;
var stabilityPointStructuresFailureMechanism = failureMechanism as StabilityPointStructuresFailureMechanism;
var grassCoverErosionOutwardsFailureMechanism = failureMechanism as GrassCoverErosionOutwardsFailureMechanism;
var waveImpactAsphaltCoverFailureMechanism = failureMechanism as WaveImpactAsphaltCoverFailureMechanism;
if (pipingFailureMechanism != null)
{
changedObservables.AddRange(PipingDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(pipingFailureMechanism));
}
if (grassCoverErosionInwardsFailureMechanism != null)
{
changedObservables.AddRange(GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(grassCoverErosionInwardsFailureMechanism));
}
if (stabilityStoneCoverFailureMechanism != null)
{
changedObservables.AddRange(StabilityStoneCoverDataSynchronizationService.ClearAllWaveConditionsCalculationOutputAndHydraulicBoundaryLocations(stabilityStoneCoverFailureMechanism));
}
if (waveImpactAsphaltCoverFailureMechanism != null)
{
changedObservables.AddRange(WaveImpactAsphaltCoverDataSynchronizationService.ClearAllWaveConditionsCalculationOutputAndHydraulicBoundaryLocations(waveImpactAsphaltCoverFailureMechanism));
}
if (grassCoverErosionOutwardsFailureMechanism != null)
{
changedObservables.AddRange(GrassCoverErosionOutwardsDataSynchronizationService.ClearAllWaveConditionsCalculationOutputAndHydraulicBoundaryLocations(grassCoverErosionOutwardsFailureMechanism));
}
if (heightStructuresFailureMechanism != null)
{
changedObservables.AddRange(HeightStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(heightStructuresFailureMechanism));
}
if (closingStructuresFailureMechanism != null)
{
changedObservables.AddRange(ClosingStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(closingStructuresFailureMechanism));
}
if (stabilityPointStructuresFailureMechanism != null)
{
changedObservables.AddRange(StabilityPointStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(stabilityPointStructuresFailureMechanism));
}
}
return changedObservables;
}
///
/// Clears the output of all calculations in the .
///
/// The which contains the calculations.
/// An of calculations which are affected by clearing the output.
/// Thrown when is null.
public static IEnumerable ClearFailureMechanismCalculationOutputs(IAssessmentSection assessmentSection)
{
if (assessmentSection == null)
{
throw new ArgumentNullException(nameof(assessmentSection));
}
return ClearFailureMechanismCalculationOutputs(assessmentSection.GetFailureMechanisms());
}
///
/// Clears the output of all calculations of the given .
///
/// The failure mechanisms that contains the calculations.
/// An of calculations that are affected by clearing the output.
/// Thrown when is null.
public static IEnumerable ClearFailureMechanismCalculationOutputs(IEnumerable failureMechanisms)
{
if (failureMechanisms == null)
{
throw new ArgumentNullException(nameof(failureMechanisms));
}
var changedObservables = new List();
foreach (var failureMechanism in failureMechanisms)
{
var pipingFailureMechanism = failureMechanism as PipingFailureMechanism;
var grassCoverErosionInwardsFailureMechanism = failureMechanism as GrassCoverErosionInwardsFailureMechanism;
var stabilityStoneCoverFailureMechanism = failureMechanism as StabilityStoneCoverFailureMechanism;
var heightStructuresFailureMechanism = failureMechanism as HeightStructuresFailureMechanism;
var closingStructuresFailureMechanism = failureMechanism as ClosingStructuresFailureMechanism;
var stabilityPointStructuresFailureMechanism = failureMechanism as StabilityPointStructuresFailureMechanism;
var grassCoverErosionOutwardsFailureMechanism = failureMechanism as GrassCoverErosionOutwardsFailureMechanism;
var waveImpactAsphaltCoverFailureMechanism = failureMechanism as WaveImpactAsphaltCoverFailureMechanism;
if (pipingFailureMechanism != null)
{
changedObservables.AddRange(PipingDataSynchronizationService.ClearAllCalculationOutput(pipingFailureMechanism));
}
if (grassCoverErosionInwardsFailureMechanism != null)
{
changedObservables.AddRange(GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutput(grassCoverErosionInwardsFailureMechanism));
}
if (stabilityStoneCoverFailureMechanism != null)
{
changedObservables.AddRange(StabilityStoneCoverDataSynchronizationService.ClearAllWaveConditionsCalculationOutput(stabilityStoneCoverFailureMechanism));
}
if (waveImpactAsphaltCoverFailureMechanism != null)
{
changedObservables.AddRange(WaveImpactAsphaltCoverDataSynchronizationService.ClearAllWaveConditionsCalculationOutput(waveImpactAsphaltCoverFailureMechanism));
}
if (grassCoverErosionOutwardsFailureMechanism != null)
{
changedObservables.AddRange(GrassCoverErosionOutwardsDataSynchronizationService.ClearAllWaveConditionsCalculationOutput(grassCoverErosionOutwardsFailureMechanism));
}
if (heightStructuresFailureMechanism != null)
{
changedObservables.AddRange(HeightStructuresDataSynchronizationService.ClearAllCalculationOutput(heightStructuresFailureMechanism));
}
if (closingStructuresFailureMechanism != null)
{
changedObservables.AddRange(ClosingStructuresDataSynchronizationService.ClearAllCalculationOutput(closingStructuresFailureMechanism));
}
if (stabilityPointStructuresFailureMechanism != null)
{
changedObservables.AddRange(StabilityPointStructuresDataSynchronizationService.ClearAllCalculationOutput(stabilityPointStructuresFailureMechanism));
}
}
return changedObservables;
}
///
/// Clears the output of the hydraulic boundary locations within the and the
/// hydraulic boundary locations that are contained within specific failure mechanisms of the .
///
/// The wich contains the locations.
/// The which contains the failure mechanisms.
/// All objects affected by the operation.
/// Thrown when any parameter is null.
public static IEnumerable ClearHydraulicBoundaryLocationOutput(HydraulicBoundaryDatabase hydraulicBoundaryDatabase, IAssessmentSection assessmentSection)
{
if (hydraulicBoundaryDatabase == null)
{
throw new ArgumentNullException(nameof(hydraulicBoundaryDatabase));
}
if (assessmentSection == null)
{
throw new ArgumentNullException(nameof(assessmentSection));
}
IEnumerable affectedLocations = ClearHydraulicBoundaryLocationOutputOfFailureMechanisms(assessmentSection);
return RingtoetsCommonDataSynchronizationService.ClearHydraulicBoundaryLocationOutput(hydraulicBoundaryDatabase.Locations)
.Concat(affectedLocations)
.ToArray();
}
///
/// Clears the output of the hydraulic boundary locations that are contained within specific failure mechanisms
/// of the .
///
/// The which contains the failure mechanisms.
/// All objects affected by the operation.
/// Thrown when is null.
public static IEnumerable ClearHydraulicBoundaryLocationOutputOfFailureMechanisms(IAssessmentSection assessmentSection)
{
if (assessmentSection == null)
{
throw new ArgumentNullException(nameof(assessmentSection));
}
return ClearHydraulicBoundaryLocationOutputOfFailureMechanisms(assessmentSection.GetFailureMechanisms());
}
///
/// Clears the output of the hydraulic boundary locations that are contained within specific .
///
/// The failure mechanisms to clear the hydraulic boundary locations for.
/// All objects affected by the operation.
/// Thrown when is null.
public static IEnumerable ClearHydraulicBoundaryLocationOutputOfFailureMechanisms(IEnumerable failureMechanisms)
{
if (failureMechanisms == null)
{
throw new ArgumentNullException(nameof(failureMechanisms));
}
var changedObservables = new List();
foreach (IFailureMechanism failureMechanism in failureMechanisms)
{
var grassCoverErosionOutwardsFailureMechanism = failureMechanism as GrassCoverErosionOutwardsFailureMechanism;
var duneErosionFailureMechanism = failureMechanism as DuneErosionFailureMechanism;
if (grassCoverErosionOutwardsFailureMechanism != null)
{
changedObservables.AddRange(RingtoetsCommonDataSynchronizationService.ClearHydraulicBoundaryLocationOutput(grassCoverErosionOutwardsFailureMechanism.HydraulicBoundaryLocations));
}
if (duneErosionFailureMechanism != null)
{
changedObservables.AddRange(DuneErosionDataSynchronizationService.ClearDuneLocationOutput(duneErosionFailureMechanism.DuneLocations));
}
}
return changedObservables;
}
///
/// Returns the hydraulic boundary location collections within the failure mechanisms of the .
///
/// The assessment section that contains failure
/// mechanisms with hydraulic boundary location collections.
/// All collections that contain hydraulic boundary locations.
/// Thrown when is null.
public static IEnumerable GetHydraulicBoundaryLocationCollectionsOfFailureMechanisms(IAssessmentSection assessmentSection)
{
if (assessmentSection == null)
{
throw new ArgumentNullException(nameof(assessmentSection));
}
return GetHydraulicBoundaryLocationCollectionsOfFailureMechanisms(assessmentSection.GetFailureMechanisms());
}
///
/// Returns the hydraulic boundary location collections within the .
///
/// The failure mechanisms with hydraulic boundary location collections.
/// All collections that contain hydraulic boundary locations.
/// Thrown when is null.
public static IEnumerable GetHydraulicBoundaryLocationCollectionsOfFailureMechanisms(IEnumerable failureMechanisms)
{
if (failureMechanisms == null)
{
throw new ArgumentNullException(nameof(failureMechanisms));
}
var changedObservables = new List();
foreach (IFailureMechanism failureMechanism in failureMechanisms)
{
var grassCoverErosionOutwardsFailureMechanism = failureMechanism as GrassCoverErosionOutwardsFailureMechanism;
var duneErosionFailureMechanism = failureMechanism as DuneErosionFailureMechanism;
if (grassCoverErosionOutwardsFailureMechanism != null)
{
changedObservables.Add(grassCoverErosionOutwardsFailureMechanism.HydraulicBoundaryLocations);
}
if (duneErosionFailureMechanism != null)
{
changedObservables.Add(duneErosionFailureMechanism.DuneLocations);
}
}
return changedObservables;
}
///
/// Clears the reference line and all data that depends on it, either directly or indirectly.
///
/// The assessment section.
/// The results of the clear action.
/// Thrown when
/// is null.
public static ClearResults ClearReferenceLine(IAssessmentSection assessmentSection)
{
if (assessmentSection == null)
{
throw new ArgumentNullException(nameof(assessmentSection));
}
var changedObjects = new List();
var removedObjects = new List