// 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.ComponentModel; using System.Linq; using Core.Common.Base; using Core.Common.Base.Data; using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Data.Hydraulics; namespace Ringtoets.Common.Data.AssessmentSection { /// /// Extension methods for . /// public static class AssessmentSectionExtensions { /// /// Gets the normative assessment level for a . /// /// The assessment section to get the normative assessment /// level from. /// The hydraulic boundary location to get the normative /// assessment level for. /// The normative assessment level or when: /// /// is null; /// is not part of . /// contains no corresponding calculation output. /// /// /// Thrown when /// is null. /// Thrown when /// contains an invalid value of . /// Thrown when /// contains a valid value of , but unsupported. public static RoundedDouble GetNormativeAssessmentLevel(this IAssessmentSection assessmentSection, HydraulicBoundaryLocation hydraulicBoundaryLocation) { if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } NormType normType = assessmentSection.FailureMechanismContribution.NormativeNorm; if (!Enum.IsDefined(typeof(NormType), normType)) { throw new InvalidEnumArgumentException(nameof(normType), (int) normType, typeof(NormType)); } IObservableEnumerable calculations; switch (normType) { case NormType.Signaling: calculations = assessmentSection.WaterLevelCalculationsForSignalingNorm; break; case NormType.LowerLimit: calculations = assessmentSection.WaterLevelCalculationsForLowerLimitNorm; break; default: throw new NotSupportedException(); } HydraulicBoundaryLocationCalculation calculation = calculations.FirstOrDefault(calc => ReferenceEquals(calc.HydraulicBoundaryLocation, hydraulicBoundaryLocation)); return calculation?.Output?.Result ?? RoundedDouble.NaN; } } }