// 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 Core.Common.Base.Geometry;
using log4net;
using Ringtoets.Common.IO.Exceptions;
using Ringtoets.Common.IO.SurfaceLines;
using Ringtoets.MacroStabilityInwards.Primitives;
using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources;
using RingtoetsCommonIoResources = Ringtoets.Common.IO.Properties.Resources;
using MacroStabilityInwardsIOResources = Ringtoets.MacroStabilityInwards.IO.Properties.Resources;
namespace Ringtoets.MacroStabilityInwards.IO.SurfaceLines
{
///
/// Extension methods for the class.
///
public static class MacroStabilityInwardsSurfaceLineExtensions
{
private static readonly ILog log = LogManager.GetLogger(typeof(MacroStabilityInwardsSurfaceLineExtensions));
///
/// Tries to set the relevant characteristic points from the
/// on the .
///
/// The surface line to set the characteristic points for.
/// The characteristic points to set, if the collection is valid.
/// Thrown when is null.
/// Thrown when a mandatory characteristic point is not
/// present or not on the given .
public static void SetCharacteristicPoints(this MacroStabilityInwardsSurfaceLine surfaceLine, CharacteristicPoints characteristicPoints)
{
if (surfaceLine == null)
{
throw new ArgumentNullException(nameof(surfaceLine));
}
if (characteristicPoints == null)
{
throw new ImportedDataTransformException($"Karakteristieke punten definitie voor profielschematisatie '{surfaceLine.Name}' is verplicht.");
}
surfaceLine.TrySetSurfaceLevelOutside(characteristicPoints.SurfaceLevelOutside);
surfaceLine.TrySetDikeToeAtRiver(characteristicPoints.DikeToeAtRiver);
surfaceLine.TrySetDikeTopAtPolder(characteristicPoints.DikeTopAtPolder);
surfaceLine.TrySetDikeTopAtRiver(characteristicPoints.DikeTopAtRiver);
surfaceLine.TrySetDikeToeAtPolder(characteristicPoints.DikeToeAtPolder);
surfaceLine.TrySetSurfaceLevelInside(characteristicPoints.SurfaceLevelInside);
surfaceLine.TrySetShoulderBaseInside(characteristicPoints.ShoulderBaseInside);
surfaceLine.TrySetShoulderTopInside(characteristicPoints.ShoulderTopInside);
surfaceLine.TrySetDitchDikeSide(characteristicPoints.DitchDikeSide);
surfaceLine.TrySetBottomDitchDikeSide(characteristicPoints.BottomDitchDikeSide);
surfaceLine.TrySetBottomDitchPolderSide(characteristicPoints.BottomDitchPolderSide);
surfaceLine.TrySetDitchPolderSide(characteristicPoints.DitchPolderSide);
}
///
/// Tries to set the at the location of
/// .
///
/// The to set the
/// for.
/// The point at which to set the .
private static void TrySetDitchPolderSide(this MacroStabilityInwardsSurfaceLine surfaceLine, Point3D point)
{
if (point != null)
{
try
{
surfaceLine.SetDitchPolderSideAt(point);
}
catch (ArgumentException e)
{
LogOptionalCharacteristicPointError(surfaceLine, e);
}
}
}
///
/// Tries to set the at the location of
/// .
///
/// The to set the
/// for.
/// The point at which to set the .
private static void TrySetBottomDitchPolderSide(this MacroStabilityInwardsSurfaceLine surfaceLine, Point3D point)
{
if (point != null)
{
try
{
surfaceLine.SetBottomDitchPolderSideAt(point);
}
catch (ArgumentException e)
{
LogOptionalCharacteristicPointError(surfaceLine, e);
}
}
}
///
/// Tries to set the at the location of
/// .
///
/// The to set the
/// for.
/// The point at which to set the .
private static void TrySetBottomDitchDikeSide(this MacroStabilityInwardsSurfaceLine surfaceLine, Point3D point)
{
if (point != null)
{
try
{
surfaceLine.SetBottomDitchDikeSideAt(point);
}
catch (ArgumentException e)
{
LogOptionalCharacteristicPointError(surfaceLine, e);
}
}
}
///
/// Tries to set the at the location of
/// .
///
/// The to set the
/// for.
/// The point at which to set the .
private static void TrySetDitchDikeSide(this MacroStabilityInwardsSurfaceLine surfaceLine, Point3D point)
{
if (point != null)
{
try
{
surfaceLine.SetDitchDikeSideAt(point);
}
catch (ArgumentException e)
{
LogOptionalCharacteristicPointError(surfaceLine, e);
}
}
}
///
/// Tries to set the at the location of
/// .
///
/// The to set the
/// for.
/// The point at which to set the .
/// Thrown when is null or
/// not on the .
private static void TrySetSurfaceLevelInside(this MacroStabilityInwardsSurfaceLine surfaceLine, Point3D point)
{
try
{
surfaceLine.SetSurfaceLevelInsideAt(point);
}
catch (ArgumentNullException)
{
throw CreateMandatoryCharacteristicPointException(CreateMissingMandatoryPointMessage(RingtoetsCommonDataResources.CharacteristicPoint_SurfaceLevelInside), surfaceLine.Name);
}
catch (ArgumentException e)
{
throw CreateMandatoryCharacteristicPointException(e.Message, surfaceLine.Name);
}
}
///
/// Tries to set the at the location of
/// .
///
/// The to set the
/// for.
/// The point at which to set the .
/// Thrown when is null or
/// not on the .
private static void TrySetSurfaceLevelOutside(this MacroStabilityInwardsSurfaceLine surfaceLine, Point3D point)
{
try
{
surfaceLine.SetSurfaceLevelOutsideAt(point);
}
catch (ArgumentNullException)
{
throw CreateMandatoryCharacteristicPointException(CreateMissingMandatoryPointMessage(RingtoetsCommonDataResources.CharacteristicPoint_SurfaceLevelOutside), surfaceLine.Name);
}
catch (ArgumentException e)
{
throw CreateMandatoryCharacteristicPointException(e.Message, surfaceLine.Name);
}
}
///
/// Tries to set the at the location of
/// .
///
/// The to set the
/// for.
/// The point at which to set the .
/// Thrown when is null or
/// not on the .
private static void TrySetDikeTopAtPolder(this MacroStabilityInwardsSurfaceLine surfaceLine, Point3D point)
{
try
{
surfaceLine.SetDikeTopAtPolderAt(point);
}
catch (ArgumentNullException)
{
throw CreateMandatoryCharacteristicPointException(CreateMissingMandatoryPointMessage(RingtoetsCommonDataResources.CharacteristicPoint_DikeTopAtPolder), surfaceLine.Name);
}
catch (ArgumentException e)
{
throw CreateMandatoryCharacteristicPointException(e.Message, surfaceLine.Name);
}
}
///
/// Tries to set the at the location of
/// .
///
/// The to set the
/// for.
/// The point at which to set the .
/// Thrown when is null or
/// not on the .
private static void TrySetDikeTopAtRiver(this MacroStabilityInwardsSurfaceLine surfaceLine, Point3D point)
{
try
{
surfaceLine.SetDikeTopAtRiverAt(point);
}
catch (ArgumentNullException)
{
throw CreateMandatoryCharacteristicPointException(CreateMissingMandatoryPointMessage(RingtoetsCommonDataResources.CharacteristicPoint_DikeTopAtRiver), surfaceLine.Name);
}
catch (ArgumentException e)
{
throw CreateMandatoryCharacteristicPointException(e.Message, surfaceLine.Name);
}
}
///
/// Tries to set the at the location of
/// .
///
/// The to set the
/// for.
/// The point at which to set the .
private static void TrySetShoulderBaseInside(this MacroStabilityInwardsSurfaceLine surfaceLine, Point3D point)
{
if (point != null)
{
try
{
surfaceLine.SetShoulderBaseInsideAt(point);
}
catch (ArgumentException e)
{
LogOptionalCharacteristicPointError(surfaceLine, e);
}
}
}
///
/// Tries to set the at the location of
/// .
///
/// The to set the
/// for.
/// The point at which to set the .
private static void TrySetShoulderTopInside(this MacroStabilityInwardsSurfaceLine surfaceLine, Point3D point)
{
if (point != null)
{
try
{
surfaceLine.SetShoulderTopInsideAt(point);
}
catch (ArgumentException e)
{
LogOptionalCharacteristicPointError(surfaceLine, e);
}
}
}
///
/// Tries to set the at the location of
/// .
///
/// The to set the
/// for.
/// The point at which to set the .
/// Thrown when is null or
/// not on the .
private static void TrySetDikeToeAtRiver(this MacroStabilityInwardsSurfaceLine surfaceLine, Point3D point)
{
try
{
surfaceLine.SetDikeToeAtRiverAt(point);
}
catch (ArgumentNullException)
{
throw CreateMandatoryCharacteristicPointException(CreateMissingMandatoryPointMessage(RingtoetsCommonDataResources.CharacteristicPoint_DikeToeAtRiver), surfaceLine.Name);
}
catch (ArgumentException e)
{
throw CreateMandatoryCharacteristicPointException(e.Message, surfaceLine.Name);
}
}
///
/// Tries to set the at the location of
/// .
///
/// The to set the
/// for.
/// The point at which to set the .
/// Thrown when is null or
/// not on the .
private static void TrySetDikeToeAtPolder(this MacroStabilityInwardsSurfaceLine surfaceLine, Point3D point)
{
try
{
surfaceLine.SetDikeToeAtPolderAt(point);
}
catch (ArgumentNullException)
{
throw CreateMandatoryCharacteristicPointException(CreateMissingMandatoryPointMessage(RingtoetsCommonDataResources.CharacteristicPoint_DikeToeAtPolder), surfaceLine.Name);
}
catch (ArgumentException e)
{
throw CreateMandatoryCharacteristicPointException(e.Message, surfaceLine.Name);
}
}
private static void LogOptionalCharacteristicPointError(MacroStabilityInwardsSurfaceLine surfaceLine, ArgumentException e)
{
log.ErrorFormat(RingtoetsCommonIoResources.SurfaceLinesCsvImporter_CharacteristicPoint_of_SurfaceLine_0_skipped_cause_1_,
surfaceLine.Name,
e.Message);
}
private static string CreateMissingMandatoryPointMessage(string surfaceLineName)
{
return string.Format(MacroStabilityInwardsIOResources.MacroStabilityInwardsSurfaceLineTransformer_CharacteristicPoint_0_is_undefined, surfaceLineName);
}
private static ImportedDataTransformException CreateMandatoryCharacteristicPointException(string exceptionMessage, string surfaceLineName)
{
string message = string.Format(MacroStabilityInwardsIOResources.SurfaceLinesCsvImporter_SurfaceLine_0_skipped_cause_1_CharacteristicPoint_mandatory, surfaceLineName, exceptionMessage);
return new ImportedDataTransformException(message);
}
}
}