// 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.Xml; namespace Ringtoets.Common.IO.Configurations.Helpers { /// /// Extension methods for an , for writing generic data components in XML format /// to file. /// public static class XmlWriterExtensions { /// /// Writes a single as a stochast element in file. /// /// The writer to use to write the distribution. /// The name of the distribution to write. /// The distribution to write. /// Thrown when any of the input parameters is null. /// Thrown when the /// is closed. public static void WriteDistribution(this XmlWriter writer, string name, StochastConfiguration distribution) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } if (name == null) { throw new ArgumentNullException(nameof(name)); } if (distribution == null) { throw new ArgumentNullException(nameof(distribution)); } writer.WriteStartElement(ConfigurationSchemaIdentifiers.StochastElement); writer.WriteAttributeString(ConfigurationSchemaIdentifiers.NameAttribute, name); if (distribution.Mean.HasValue) { writer.WriteElementString(ConfigurationSchemaIdentifiers.MeanElement, XmlConvert.ToString(distribution.Mean.Value)); } if (distribution.StandardDeviation.HasValue) { writer.WriteElementString(ConfigurationSchemaIdentifiers.StandardDeviationElement, XmlConvert.ToString(distribution.StandardDeviation.Value)); } if (distribution.VariationCoefficient.HasValue) { writer.WriteElementString(ConfigurationSchemaIdentifiers.VariationCoefficientElement, XmlConvert.ToString(distribution.VariationCoefficient.Value)); } writer.WriteEndElement(); } /// /// Writes a single as a wave reduction element in file. /// /// The writer to use to write the wave reduction. /// The wave reduction to write. /// Thrown when any of the input parameters is null. /// Thrown when the /// is closed. public static void WriteWaveReduction(this XmlWriter writer, WaveReductionConfiguration waveReduction) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } if (waveReduction == null) { throw new ArgumentNullException(nameof(waveReduction)); } writer.WriteStartElement(ConfigurationSchemaIdentifiers.WaveReduction); if (waveReduction.UseBreakWater.HasValue) { writer.WriteElementString(ConfigurationSchemaIdentifiers.UseBreakWater, XmlConvert.ToString(waveReduction.UseBreakWater.Value)); } if (waveReduction.BreakWaterType.HasValue) { writer.WriteElementString(ConfigurationSchemaIdentifiers.BreakWaterType, new ConfigurationBreakWaterTypeConverter().ConvertToInvariantString(waveReduction.BreakWaterType.Value)); } if (waveReduction.BreakWaterHeight.HasValue) { writer.WriteElementString(ConfigurationSchemaIdentifiers.BreakWaterHeight, XmlConvert.ToString(waveReduction.BreakWaterHeight.Value)); } if (waveReduction.UseForeshoreProfile.HasValue) { writer.WriteElementString(ConfigurationSchemaIdentifiers.UseForeshore, XmlConvert.ToString(waveReduction.UseForeshoreProfile.Value)); } writer.WriteEndElement(); } /// /// Writes a single as a scenario element in file. /// /// The writer to use to write the scenario. /// The scenario to write. /// Thrown when any of the input parameters is null. /// Thrown when the /// is closed. public static void WriteScenario(this XmlWriter writer, ScenarioConfiguration scenarioConfiguration) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } if (scenarioConfiguration == null) { throw new ArgumentNullException(nameof(scenarioConfiguration)); } writer.WriteStartElement(ConfigurationSchemaIdentifiers.ScenarioElement); if (scenarioConfiguration.IsRelevant.HasValue) { writer.WriteElementString(ConfigurationSchemaIdentifiers.IsRelevantForScenario, XmlConvert.ToString(scenarioConfiguration.IsRelevant.Value)); } if (scenarioConfiguration.Contribution.HasValue) { writer.WriteElementString(ConfigurationSchemaIdentifiers.ScenarioContribution, XmlConvert.ToString(scenarioConfiguration.Contribution.Value)); } writer.WriteEndElement(); } /// /// Writes the start tag of a folder element. /// /// The writer to use to write the folder. /// The name of the folder. /// Thrown when any of the input parameters is null. /// Thrown when the /// is closed. public static void WriteStartFolder(this XmlWriter writer, string name) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } if (name == null) { throw new ArgumentNullException(nameof(name)); } writer.WriteStartElement(ConfigurationSchemaIdentifiers.FolderElement); writer.WriteAttributeString(ConfigurationSchemaIdentifiers.NameAttribute, name); } } }