// 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.Base.Data; using Ringtoets.Piping.Data; namespace Application.Ringtoets.Storage.Create { /// /// Extension methods for related to creating /// an . /// internal static class PipingCalculationScenarioCreateExtensions { /// /// Creates a based on the information of the . /// /// The piping calculation to create a database entity for. /// The object keeping track of create operations. /// The index at which resides within its parent. /// A new . /// Thrown when is null. internal static PipingCalculationEntity Create(this PipingCalculationScenario calculation, PersistenceRegistry registry, int order) { if (registry == null) { throw new ArgumentNullException("registry"); } var entity = new PipingCalculationEntity { RelevantForScenario = Convert.ToByte(calculation.IsRelevant), ScenarioContribution = Convert.ToDecimal(calculation.Contribution), Name = calculation.Name, Comments = calculation.Comments, Order = order }; SetInputParametersToEntity(entity, calculation.InputParameters, registry); registry.Register(entity, calculation); return entity; } private static void SetInputParametersToEntity(PipingCalculationEntity entity, PipingInput inputParameters, PersistenceRegistry registry) { if (inputParameters.SurfaceLine != null) { entity.SurfaceLineEntity = inputParameters.SurfaceLine.Create(registry); } if (inputParameters.HydraulicBoundaryLocation != null) { entity.HydraulicLocationEntity = inputParameters.HydraulicBoundaryLocation.Create(registry); } if (inputParameters.StochasticSoilProfile != null) { inputParameters.StochasticSoilModel.Create(registry); entity.StochasticSoilProfileEntity = registry.Get(inputParameters.StochasticSoilProfile); } entity.ExitPointL = ToNullableDecimal(inputParameters.ExitPointL); entity.EntryPointL = ToNullableDecimal(inputParameters.EntryPointL); entity.PhreaticLevelExitMean = Convert.ToDecimal(inputParameters.PhreaticLevelExit.Mean); entity.PhreaticLevelExitStandardDeviation = Convert.ToDecimal(inputParameters.PhreaticLevelExit.StandardDeviation); entity.DampingFactorExitMean = Convert.ToDecimal(inputParameters.DampingFactorExit.Mean); entity.DampingFactorExitStandardDeviation = Convert.ToDecimal(inputParameters.DampingFactorExit.StandardDeviation); entity.SaturatedVolumicWeightOfCoverageLayerMean = Convert.ToDecimal(inputParameters.SaturatedVolumicWeightOfCoverageLayer.Mean); entity.SaturatedVolumicWeightOfCoverageLayerStandardDeviation = Convert.ToDecimal(inputParameters.SaturatedVolumicWeightOfCoverageLayer.StandardDeviation); entity.SaturatedVolumicWeightOfCoverageLayerShift = Convert.ToDecimal(inputParameters.SaturatedVolumicWeightOfCoverageLayer.Shift); entity.Diameter70Mean = Convert.ToDecimal(inputParameters.Diameter70.Mean); entity.Diameter70StandardDeviation = Convert.ToDecimal(inputParameters.Diameter70.StandardDeviation); entity.DarcyPermeabilityMean = Convert.ToDecimal(inputParameters.DarcyPermeability.Mean); entity.DarcyPermeabilityStandardDeviation = Convert.ToDecimal(inputParameters.DarcyPermeability.StandardDeviation); } private static decimal? ToNullableDecimal(RoundedDouble parameter) { if (double.IsNaN(parameter)) { return null; } return Convert.ToDecimal(parameter); } } }