Index: Ringtoets/Common/src/Ringtoets.Common.IO/Readers/XElementExtensions.cs =================================================================== diff -u -r04a0742040ae09f8839510470014d2b273e67a78 -r1fea24f00be5ae78cf5ceba066bae1056c0e5a2e --- Ringtoets/Common/src/Ringtoets.Common.IO/Readers/XElementExtensions.cs (.../XElementExtensions.cs) (revision 04a0742040ae09f8839510470014d2b273e67a78) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Readers/XElementExtensions.cs (.../XElementExtensions.cs) (revision 1fea24f00be5ae78cf5ceba066bae1056c0e5a2e) @@ -24,6 +24,9 @@ using System.Linq; using System.Xml; using System.Xml.Linq; +using Core.Common.Base.IO; +using Ringtoets.Common.IO.Configurations; +using Ringtoets.Common.IO.Properties; using Ringtoets.Common.IO.Schema; namespace Ringtoets.Common.IO.Readers @@ -202,5 +205,77 @@ return parentElement.Descendants(descendantElementName).FirstOrDefault(); } + + /// Thrown when any parameter is null. + /// Thrown when the value isn't in the correct format. + /// Thrown when the value for mean or standard deviation represents a + /// number less than or greater than . + public static MeanStandardDeviationStochastConfiguration GetStandardDeviationStochastParameters(this XElement calculationElement, string stochastName) + { + if (calculationElement == null) + { + throw new ArgumentNullException(nameof(calculationElement)); + } + if (stochastName == null) + { + throw new ArgumentNullException(nameof(stochastName)); + } + + XElement element = calculationElement.GetStochastElement(stochastName); + + if (element != null) + { + if (element.Element(ConfigurationSchemaIdentifiers.VariationCoefficientElement) != null) + { + string calculationName = calculationElement.Attribute(ConfigurationSchemaIdentifiers.NameAttribute)?.Value; + string message = string.Format( + Resources.XElementExtensions_GetStandardDeviationStochastParameters_Stochast_0_defines_VariationCoefficient_instead_of_StandardDeviation_in_Calculation_1_, + stochastName, + calculationName); + throw new CriticalFileReadException(message); + } + + return new MeanStandardDeviationStochastConfiguration + { + Mean = element.GetDoubleValueFromDescendantElement(ConfigurationSchemaIdentifiers.MeanElement), + StandardDeviation = element.GetDoubleValueFromDescendantElement(ConfigurationSchemaIdentifiers.StandardDeviationElement) + }; + } + return null; + } + + public static MeanVariationCoefficientStochastConfiguration GetVariationCoefficientStochastParameters(this XElement calculationElement, string stochastName) + { + if (calculationElement == null) + { + throw new ArgumentNullException(nameof(calculationElement)); + } + if (stochastName == null) + { + throw new ArgumentNullException(nameof(stochastName)); + } + + XElement element = calculationElement.GetStochastElement(stochastName); + + if (element != null) + { + if (element.Element(ConfigurationSchemaIdentifiers.StandardDeviationElement) != null) + { + string calculationName = calculationElement.Attribute(ConfigurationSchemaIdentifiers.NameAttribute)?.Value; + string message = string.Format( + Resources.XElementExtensions_GetVariationCoefficientStochastParameters_Stochast_0_defines_StandardDeviation_instead_of_VariationCoefficient_in_Calculation_1_, + stochastName, + calculationName); + throw new CriticalFileReadException(message); + } + + return new MeanVariationCoefficientStochastConfiguration + { + Mean = element.GetDoubleValueFromDescendantElement(ConfigurationSchemaIdentifiers.MeanElement), + VariationCoefficient = element.GetDoubleValueFromDescendantElement(ConfigurationSchemaIdentifiers.VariationCoefficientElement) + }; + } + return null; + } } } \ No newline at end of file