// 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.Export
{
///
/// Writer for writing in XML format to file.
///
public abstract class StructureCalculationConfigurationWriter : CalculationConfigurationWriter
where T : StructuresCalculationConfiguration
{
///
/// Creates a new instance of .
///
/// The path of the file to write to.
/// Thrown when is invalid.
/// A valid path:
///
/// - is not empty or null,
/// - does not consist out of only whitespace characters,
/// - does not contain an invalid character,
/// - does not end with a directory or path separator (empty file name).
///
protected StructureCalculationConfigurationWriter(string filePath) : base(filePath) {}
protected override void WriteCalculation(T configuration, XmlWriter writer)
{
writer.WriteStartElement(ConfigurationSchemaIdentifiers.CalculationElement);
writer.WriteAttributeString(ConfigurationSchemaIdentifiers.NameAttribute, configuration.Name);
WriteParameters(configuration, writer);
WriteWaveReductionWhenAvailable(writer, configuration.WaveReduction);
WriteStochasts(configuration, writer);
if (configuration.ShouldIllustrationPointsBeCalculated.HasValue)
{
WriteElementWhenContentAvailable(
writer,
ConfigurationSchemaIdentifiers.ShouldIllustrationPointsBeCalculatedElement,
XmlConvert.ToString(configuration.ShouldIllustrationPointsBeCalculated.Value));
}
writer.WriteEndElement();
}
///
/// Writes properties specific for a structure of type .
///
/// The instance of type for which
/// to write the input.
/// The writer that should be used to write the parameters.
/// Thrown when the
/// is closed.
/// Thrown when the conversion of
/// cannot be performed.
protected virtual void WriteSpecificStructureParameters(T configuration, XmlWriter writer) {}
///
/// Writes stochasts definitions specific for a structure of type .
///
/// The instance of type for which
/// to write the stochasts.
/// The writer that should be used to write the parameters.
/// Thrown when the
/// is closed.
protected abstract void WriteSpecificStochasts(T configuration, XmlWriter writer);
///
/// Writes properties that are applicable for all structure configurations.
///
/// The structure configuration for which to write the input.
/// The writer that should be used to write the parameters.
/// Thrown when the
/// is closed.
/// Thrown when the conversion of
/// cannot be performed.
private void WriteParameters(T configuration, XmlWriter writer)
{
WriteElementWhenContentAvailable(writer,
ConfigurationSchemaIdentifiers.HydraulicBoundaryLocationElementOld,
configuration.HydraulicBoundaryLocationName);
WriteElementWhenContentAvailable(writer,
ConfigurationSchemaIdentifiers.StructureElement,
configuration.StructureId);
WriteElementWhenContentAvailable(writer,
ConfigurationSchemaIdentifiers.Orientation,
configuration.StructureNormalOrientation);
WriteElementWhenContentAvailable(writer,
ConfigurationSchemaIdentifiers.FailureProbabilityStructureWithErosionElement,
configuration.FailureProbabilityStructureWithErosion);
WriteElementWhenContentAvailable(writer,
ConfigurationSchemaIdentifiers.ForeshoreProfileNameElement,
configuration.ForeshoreProfileId);
WriteSpecificStructureParameters(configuration, writer);
}
///
/// Writes stochasts definitions that are applicable for all structure configurations.
///
/// The structure configuration for which to write the input.
/// The writer that should be used to write the stochasts.
/// Thrown when the
/// is closed.
private void WriteStochasts(T configuration, XmlWriter writer)
{
writer.WriteStartElement(ConfigurationSchemaIdentifiers.StochastsElement);
WriteDistributionWhenAvailable(writer,
ConfigurationSchemaIdentifiers.FlowWidthAtBottomProtectionStochastName,
configuration.FlowWidthAtBottomProtection);
WriteDistributionWhenAvailable(writer,
ConfigurationSchemaIdentifiers.WidthFlowAperturesStochastName,
configuration.WidthFlowApertures);
WriteDistributionWhenAvailable(writer,
ConfigurationSchemaIdentifiers.StorageStructureAreaStochastName,
configuration.StorageStructureArea);
WriteDistributionWhenAvailable(writer,
ConfigurationSchemaIdentifiers.CriticalOvertoppingDischargeStochastName,
configuration.CriticalOvertoppingDischarge);
WriteDistributionWhenAvailable(writer,
ConfigurationSchemaIdentifiers.ModelFactorSuperCriticalFlowStochastName,
configuration.ModelFactorSuperCriticalFlow);
WriteDistributionWhenAvailable(writer,
ConfigurationSchemaIdentifiers.AllowedLevelIncreaseStorageStochastName,
configuration.AllowedLevelIncreaseStorage);
WriteDistributionWhenAvailable(writer,
ConfigurationSchemaIdentifiers.StormDurationStochastName,
configuration.StormDuration);
WriteSpecificStochasts(configuration, writer);
writer.WriteEndElement();
}
}
}