// Copyright (C) Stichting Deltares 2016. 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 Application.Ringtoets.Storage.DbContext;
using Core.Common.Utils.Extensions;
using Ringtoets.ClosingStructures.Data;
using Ringtoets.Common.Data.Structures;
namespace Application.Ringtoets.Storage.Create.ClosingStructures
{
///
/// Extension methods for related
/// to creating a .
///
internal static class ClosingStructureCalculationCreateExtensions
{
///
/// Creates a based
/// on the information of the .
///
/// The calculation to create a database entity for.
/// The object keeping track of create operations.
/// The index at where resides
/// in its parent container.
/// A new .
/// Thrown when is null.
internal static ClosingStructuresCalculationEntity Create(this StructuresCalculation calculation, PersistenceRegistry registry, int order)
{
if (registry == null)
{
throw new ArgumentNullException("registry");
}
var entity = new ClosingStructuresCalculationEntity
{
Name = calculation.Name.DeepClone(),
Comments = calculation.Comments.DeepClone(),
Order = order
};
SetInputValues(entity, calculation.InputParameters, registry);
return entity;
}
private static void SetInputValues(ClosingStructuresCalculationEntity entity, ClosingStructuresInput input, PersistenceRegistry registry)
{
SetBaseStructureInputValues(entity, input, registry);
SetClosingStructureSpecificInputValues(entity, input);
}
private static void SetBaseStructureInputValues(ClosingStructuresCalculationEntity entity, StructuresInputBase input, PersistenceRegistry registry)
{
entity.StormDurationMean = input.StormDuration.Mean.Value.ToNaNAsNull();
entity.StructureNormalOrientation = input.StructureNormalOrientation.Value.ToNaNAsNull();
entity.FailureProbabilityStructureWithErosion = input.FailureProbabilityStructureWithErosion;
if (input.Structure != null)
{
entity.ClosingStructureEntity = registry.Get(input.Structure);
}
if (input.HydraulicBoundaryLocation != null)
{
entity.HydraulicLocationEntity = registry.Get(input.HydraulicBoundaryLocation);
}
if (input.ForeshoreProfile != null)
{
entity.ForeshoreProfileEntity = registry.Get(input.ForeshoreProfile);
}
entity.UseForeshore = Convert.ToByte(input.UseForeshore);
entity.UseBreakWater = Convert.ToByte(input.UseBreakWater);
entity.BreakWaterType = Convert.ToInt16(input.BreakWater.Type);
entity.BreakWaterHeight = input.BreakWater.Height.Value.ToNaNAsNull();
entity.AllowedLevelIncreaseStorageMean = input.AllowedLevelIncreaseStorage.Mean.Value.ToNaNAsNull();
entity.AllowedLevelIncreaseStorageStandardDeviation = input.AllowedLevelIncreaseStorage.StandardDeviation.Value.ToNaNAsNull();
entity.StorageStructureAreaMean = input.StorageStructureArea.Mean.Value.ToNaNAsNull();
entity.StorageStructureAreaCoefficientOfVariation = input.StorageStructureArea.CoefficientOfVariation.Value.ToNaNAsNull();
entity.FlowWidthAtBottomProtectionMean = input.FlowWidthAtBottomProtection.Mean.Value.ToNaNAsNull();
entity.FlowWidthAtBottomProtectionStandardDeviation = input.FlowWidthAtBottomProtection.StandardDeviation.Value.ToNaNAsNull();
entity.CriticalOvertoppingDischargeMean = input.CriticalOvertoppingDischarge.Mean.Value.ToNaNAsNull();
entity.CriticalOvertoppingDischargeCoefficientOfVariation = input.CriticalOvertoppingDischarge.CoefficientOfVariation.Value.ToNaNAsNull();
entity.ModelFactorSuperCriticalFlowMean = input.ModelFactorSuperCriticalFlow.Mean.Value.ToNaNAsNull();
entity.WidthFlowAperturesMean = input.WidthFlowApertures.Mean.Value.ToNaNAsNull();
entity.WidthFlowAperturesCoefficientOfVariation = input.WidthFlowApertures.CoefficientOfVariation.Value.ToNaNAsNull();
}
private static void SetClosingStructureSpecificInputValues(ClosingStructuresCalculationEntity entity, ClosingStructuresInput input)
{
entity.InflowModelType = Convert.ToByte(input.InflowModelType);
entity.InsideWaterLevelMean = input.InsideWaterLevel.Mean.Value.ToNaNAsNull();
entity.InsideWaterLevelStandardDeviation = input.InsideWaterLevel.StandardDeviation.Value.ToNaNAsNull();
entity.DeviationWaveDirection = input.DeviationWaveDirection.Value.ToNaNAsNull();
entity.DrainCoefficientMean = input.DrainCoefficient.Mean.Value.ToNaNAsNull();
entity.FactorStormDurationOpenStructure = input.FactorStormDurationOpenStructure.Value.ToNaNAsNull();
entity.ThresholdHeightOpenWeirMean = input.ThresholdHeightOpenWeir.Mean.Value.ToNaNAsNull();
entity.ThresholdHeightOpenWeirStandardDeviation = input.ThresholdHeightOpenWeir.StandardDeviation.Value.ToNaNAsNull();
entity.AreaFlowAperturesMean = input.AreaFlowApertures.Mean.Value.ToNaNAsNull();
entity.AreaFlowAperturesStandardDeviation = input.AreaFlowApertures.StandardDeviation.Value.ToNaNAsNull();
entity.FailureProbabilityOpenStructure = input.FailureProbabilityOpenStructure;
entity.FailureProbablityReparation = input.FailureProbabilityReparation;
entity.IdenticalApertures = input.IdenticalApertures;
entity.LevelCrestStructureNotClosingMean = input.LevelCrestStructureNotClosing.Mean.Value.ToNaNAsNull();
entity.LevelCrestStructureNotClosingStandardDeviation = input.LevelCrestStructureNotClosing.StandardDeviation.Value.ToNaNAsNull();
entity.ProbabilityOpenStructureBeforeFlooding = input.ProbabilityOpenStructureBeforeFlooding;
}
}
}