// 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.Linq; using Application.Ringtoets.Storage.DbContext; using Application.Ringtoets.Storage.Serializers; using Core.Common.Base.Geometry; using Core.Common.Utils.Extensions; using Ringtoets.MacroStabilityInwards.Primitives; namespace Application.Ringtoets.Storage.Create.MacroStabilityInwards { /// /// Extensions methods for related to creating /// a . /// internal static class MacroStabilityInwardsSurfaceLineCreateExtensions { /// /// Creates a based on the information of the . /// /// The surface line 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. internal static SurfaceLineEntity Create(this MacroStabilityInwardsSurfaceLine surfaceLine, PersistenceRegistry registry, int order) { if (surfaceLine == null) { throw new ArgumentNullException(nameof(surfaceLine)); } if (registry == null) { throw new ArgumentNullException(nameof(registry)); } if (registry.Contains(surfaceLine)) { return registry.Get(surfaceLine); } var entity = new SurfaceLineEntity { Name = surfaceLine.Name.DeepClone(), ReferenceLineIntersectionX = surfaceLine.ReferenceLineIntersectionWorldPoint.X.ToNaNAsNull(), ReferenceLineIntersectionY = surfaceLine.ReferenceLineIntersectionWorldPoint.Y.ToNaNAsNull(), PointsXml = new Point3DXmlSerializer().ToXml(surfaceLine.Points), Order = order }; CreateCharacteristicPointEntities(surfaceLine, entity); registry.Register(entity, surfaceLine); return entity; } private static void CreateCharacteristicPointEntities(MacroStabilityInwardsSurfaceLine surfaceLine, SurfaceLineEntity entity) { var characteristicPointAssociations = new[] { Tuple.Create(surfaceLine.SurfaceLevelOutside, MacroStabilityInwardsCharacteristicPointType.SurfaceLevelOutside), Tuple.Create(surfaceLine.TrafficLoadOutside, MacroStabilityInwardsCharacteristicPointType.TrafficLoadOutside), Tuple.Create(surfaceLine.TrafficLoadInside, MacroStabilityInwardsCharacteristicPointType.TrafficLoadInside), Tuple.Create(surfaceLine.DikeTopAtPolder, MacroStabilityInwardsCharacteristicPointType.DikeTopAtPolder), Tuple.Create(surfaceLine.DikeTopAtRiver, MacroStabilityInwardsCharacteristicPointType.DikeTopAtRiver), Tuple.Create(surfaceLine.ShoulderBaseInside, MacroStabilityInwardsCharacteristicPointType.ShoulderBaseInside), Tuple.Create(surfaceLine.ShoulderTopInside, MacroStabilityInwardsCharacteristicPointType.ShoulderTopInside), Tuple.Create(surfaceLine.BottomDitchDikeSide, MacroStabilityInwardsCharacteristicPointType.BottomDitchDikeSide), Tuple.Create(surfaceLine.BottomDitchPolderSide, MacroStabilityInwardsCharacteristicPointType.BottomDitchPolderSide), Tuple.Create(surfaceLine.DikeToeAtPolder, MacroStabilityInwardsCharacteristicPointType.DikeToeAtPolder), Tuple.Create(surfaceLine.DikeToeAtRiver, MacroStabilityInwardsCharacteristicPointType.DikeToeAtRiver), Tuple.Create(surfaceLine.DitchDikeSide, MacroStabilityInwardsCharacteristicPointType.DitchDikeSide), Tuple.Create(surfaceLine.DitchPolderSide, MacroStabilityInwardsCharacteristicPointType.DitchPolderSide), Tuple.Create(surfaceLine.SurfaceLevelInside, MacroStabilityInwardsCharacteristicPointType.SurfaceLevelInside) }; foreach (Tuple characteristicPointToSave in characteristicPointAssociations.Where(t => t.Item1 != null)) { MacroStabilityInwardsCharacteristicPointEntity characteristicPointEntity = CreateCharacteristicPointEntity(characteristicPointToSave.Item1, characteristicPointToSave.Item2); entity.MacroStabilityInwardsCharacteristicPointEntities.Add(characteristicPointEntity); } } private static MacroStabilityInwardsCharacteristicPointEntity CreateCharacteristicPointEntity(Point3D point, MacroStabilityInwardsCharacteristicPointType type) { var entity = new MacroStabilityInwardsCharacteristicPointEntity { Type = (byte) type, X = point.X.ToNaNAsNull(), Y = point.Y.ToNaNAsNull(), Z = point.Z.ToNaNAsNull() }; return entity; } } }