// 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 Application.Ringtoets.Storage.DbContext;
using Ringtoets.MacroStabilityInwards.Data.SoilProfile;
using Ringtoets.MacroStabilityInwards.Primitives;
namespace Application.Ringtoets.Storage.Create.MacroStabilityInwards
{
///
/// Extension methods for related to
/// creating a .
///
internal static class MacroStabilityInwardsStochasticSoilProfileCreateExtensions
{
///
/// Creates a based on
/// the information of the .
///
/// The stochastic soil profile to create a database entity for.
/// The object keeping track of create operations.
/// Index at which this instance resides inside its parent container.
/// A new .
/// Thrown when any input parameter is null.
/// Thrown when is
/// not of type or .
public static MacroStabilityInwardsStochasticSoilProfileEntity Create(this MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile,
PersistenceRegistry registry,
int order)
{
if (stochasticSoilProfile == null)
{
throw new ArgumentNullException(nameof(stochasticSoilProfile));
}
if (registry == null)
{
throw new ArgumentNullException(nameof(registry));
}
if (registry.Contains(stochasticSoilProfile))
{
return registry.Get(stochasticSoilProfile);
}
var entity = new MacroStabilityInwardsStochasticSoilProfileEntity
{
Probability = stochasticSoilProfile.Probability,
Order = order
};
AddEntityForProfile(stochasticSoilProfile.SoilProfile, entity, registry);
registry.Register(entity, stochasticSoilProfile);
return entity;
}
///
/// Adds the entity representation of to the .
///
/// The soil profile to store.
/// The entity to update.
/// The registry to use for persisting entities.
/// Thrown when is
/// not of type or .
private static void AddEntityForProfile(IMacroStabilityInwardsSoilProfile soilProfile,
MacroStabilityInwardsStochasticSoilProfileEntity entity,
PersistenceRegistry registry)
{
var soilProfile1D = soilProfile as MacroStabilityInwardsSoilProfile1D;
if (soilProfile1D != null)
{
entity.MacroStabilityInwardsSoilProfileOneDEntity = soilProfile1D.Create(registry);
return;
}
var soilProfile2D = soilProfile as MacroStabilityInwardsSoilProfile2D;
if (soilProfile2D != null)
{
entity.MacroStabilityInwardsSoilProfileTwoDEntity = soilProfile2D.Create(registry);
return;
}
string exceptionMessage = $"{soilProfile.GetType().Name} is not supported. " +
$"Supported types are: {nameof(MacroStabilityInwardsSoilProfile1D)} and {nameof(MacroStabilityInwardsSoilProfile2D)}.";
throw new NotSupportedException(exceptionMessage);
}
}
}