// 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.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("assessmentSection");
}
var affectedItems = 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)
{
affectedItems.AddRange(PipingDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(pipingFailureMechanism));
}
if (grassCoverErosionInwardsFailureMechanism != null)
{
affectedItems.AddRange(GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(grassCoverErosionInwardsFailureMechanism));
}
if (stabilityStoneCoverFailureMechanism != null)
{
affectedItems.AddRange(StabilityStoneCoverDataSynchronizationService.ClearAllWaveConditionsCalculationOutputAndHydraulicBoundaryLocations(stabilityStoneCoverFailureMechanism));
}
if (waveImpactAsphaltCoverFailureMechanism != null)
{
affectedItems.AddRange(WaveImpactAsphaltCoverDataSynchronizationService.ClearAllWaveConditionsCalculationOutputAndHydraulicBoundaryLocations(waveImpactAsphaltCoverFailureMechanism));
}
if (grassCoverErosionOutwardsFailureMechanism != null)
{
affectedItems.AddRange(GrassCoverErosionOutwardsDataSynchronizationService.ClearAllWaveConditionsCalculationOutputAndHydraulicBoundaryLocations(grassCoverErosionOutwardsFailureMechanism));
}
if (heightStructuresFailureMechanism != null)
{
affectedItems.AddRange(HeightStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(heightStructuresFailureMechanism));
}
if (closingStructuresFailureMechanism != null)
{
affectedItems.AddRange(ClosingStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(closingStructuresFailureMechanism));
}
if (stabilityPointStructuresFailureMechanism != null)
{
affectedItems.AddRange(StabilityPointStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(stabilityPointStructuresFailureMechanism));
}
}
return affectedItems;
}
///
/// 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("assessmentSection");
}
var affectedItems = 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)
{
affectedItems.AddRange(PipingDataSynchronizationService.ClearAllCalculationOutput(pipingFailureMechanism));
}
if (grassCoverErosionInwardsFailureMechanism != null)
{
affectedItems.AddRange(GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutput(grassCoverErosionInwardsFailureMechanism));
}
if (stabilityStoneCoverFailureMechanism != null)
{
affectedItems.AddRange(StabilityStoneCoverDataSynchronizationService.ClearAllWaveConditionsCalculationOutput(stabilityStoneCoverFailureMechanism));
}
if (waveImpactAsphaltCoverFailureMechanism != null)
{
affectedItems.AddRange(WaveImpactAsphaltCoverDataSynchronizationService.ClearAllWaveConditionsCalculationOutput(waveImpactAsphaltCoverFailureMechanism));
}
if (grassCoverErosionOutwardsFailureMechanism != null)
{
affectedItems.AddRange(GrassCoverErosionOutwardsDataSynchronizationService.ClearAllWaveConditionsCalculationOutput(grassCoverErosionOutwardsFailureMechanism));
}
if (heightStructuresFailureMechanism != null)
{
affectedItems.AddRange(HeightStructuresDataSynchronizationService.ClearAllCalculationOutput(heightStructuresFailureMechanism));
}
if (closingStructuresFailureMechanism != null)
{
affectedItems.AddRange(ClosingStructuresDataSynchronizationService.ClearAllCalculationOutput(closingStructuresFailureMechanism));
}
if (stabilityPointStructuresFailureMechanism != null)
{
affectedItems.AddRange(StabilityPointStructuresDataSynchronizationService.ClearAllCalculationOutput(stabilityPointStructuresFailureMechanism));
}
}
return affectedItems;
}
///
/// Clears the output of the hydraulic boundary locations within the
/// and .
///
/// The wich contains the locations.
/// The which contains the locations.
/// The which contains locations.
/// All objects affected by the operation.
/// Thrown when
/// or is null.
public static IEnumerable ClearHydraulicBoundaryLocationOutput(HydraulicBoundaryDatabase hydraulicBoundaryDatabase,
GrassCoverErosionOutwardsFailureMechanism grassCoverErosionOutwardsFailureMechanism,
DuneErosionFailureMechanism duneErosionFailureMechanism)
{
if (hydraulicBoundaryDatabase == null)
{
throw new ArgumentNullException("hydraulicBoundaryDatabase");
}
if (grassCoverErosionOutwardsFailureMechanism == null)
{
throw new ArgumentNullException("grassCoverErosionOutwardsFailureMechanism");
}
if (duneErosionFailureMechanism == null)
{
throw new ArgumentNullException("duneErosionFailureMechanism");
}
return RingtoetsCommonDataSynchronizationService.ClearHydraulicBoundaryLocationOutput(grassCoverErosionOutwardsFailureMechanism.HydraulicBoundaryLocations)
.Concat(RingtoetsCommonDataSynchronizationService.ClearHydraulicBoundaryLocationOutput(
hydraulicBoundaryDatabase.Locations))
.Concat(DuneErosionDataSynchronizationService.ClearDuneLocationOutput(
duneErosionFailureMechanism.DuneLocations))
.ToArray();
}
///
/// 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("assessmentSection");
}
var changedObjects = new List();
var removedObjects = new List