// Copyright (C) Stichting Deltares 2017. 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.Common.Data.Structures;
using Ringtoets.Common.Util;
namespace Ringtoets.ClosingStructures.Util
{
///
/// Class holds helper methods to match objects
/// with objects.
///
public static class ClosingStructuresHelper
{
///
/// Updates the for each element
/// of if required due to a change.
///
/// The failure mechanism which contains the
/// and calculations to update with.
/// All affected objects by the update.
/// Thrown when is null.
public static IEnumerable UpdateCalculationToSectionResultAssignments(ClosingStructuresFailureMechanism failureMechanism)
{
if (failureMechanism == null)
{
throw new ArgumentNullException(nameof(failureMechanism));
}
IObservableEnumerable sectionResults = failureMechanism.SectionResults;
IEnumerable> calculations = failureMechanism.Calculations
.Cast>();
return AssignUnassignCalculations.Update(sectionResults.Select(AsCalculationAssignment),
AsCalculationsWithLocations(calculations))
.Cast()
.ToArray();
}
private static IEnumerable AsCalculationsWithLocations(
IEnumerable> calculations)
{
var calculationsWithLocation = new List();
foreach (StructuresCalculation calculation in calculations)
{
if (calculation.InputParameters.Structure != null)
{
calculationsWithLocation.Add(new CalculationWithLocation(calculation,
calculation.InputParameters.Structure.Location));
}
}
return calculationsWithLocation;
}
private static SectionResultWithCalculationAssignment AsCalculationAssignment(
ClosingStructuresFailureMechanismSectionResult failureMechanismSectionResult)
{
return new SectionResultWithCalculationAssignment(
failureMechanismSectionResult,
result => ((ClosingStructuresFailureMechanismSectionResult) result).Calculation,
(result, calculation) => ((ClosingStructuresFailureMechanismSectionResult) result).Calculation = (StructuresCalculation) calculation);
}
}
}