// 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 System.Collections.Generic;
using Application.Ringtoets.Storage.DbContext;
using Core.Common.Base.Geometry;
using Core.Common.Utils;
using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.HydraRing.Data;
using Ringtoets.Piping.Data;
using Ringtoets.Piping.Primitives;
namespace Application.Ringtoets.Storage.Read
{
///
/// Class that can be used to keep track of data model objects which were initialized during a read operation
/// from the database. Can be used to reuse objects when reading an already read entity.
///
internal class ReadConversionCollector
{
private readonly Dictionary stochasticSoilModels = new Dictionary(new ReferenceEqualityComparer());
private readonly Dictionary stochasticSoilProfiles = new Dictionary(new ReferenceEqualityComparer());
private readonly Dictionary soilProfiles = new Dictionary(new ReferenceEqualityComparer());
private readonly Dictionary surfaceLines = new Dictionary(new ReferenceEqualityComparer());
private readonly Dictionary surfaceLineGeometryPoints = new Dictionary(new ReferenceEqualityComparer());
private readonly Dictionary hydraulicBoundaryLocations = new Dictionary(new ReferenceEqualityComparer());
private readonly Dictionary failureMechanismSections = new Dictionary(new ReferenceEqualityComparer());
#region StochasticSoilModelEntity: Read, Contains, Get
///
/// Registers a read operation for and the
/// that was constructed with the information.
///
/// The that was read.
/// The that was constructed.
/// Thrown when either:
///
/// - is null
/// - is null
///
internal void Read(StochasticSoilModelEntity entity, StochasticSoilModel model)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
if (model == null)
{
throw new ArgumentNullException("model");
}
stochasticSoilModels[entity] = model;
}
///
/// Checks whether a read operations has been registered for the given .
///
/// The to check for.
/// true if the was read before, false otherwise.
/// Thrown when is null.
internal bool Contains(StochasticSoilModelEntity entity)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
return stochasticSoilModels.ContainsKey(entity);
}
///
/// Obtains the which was read for the given .
///
/// The for which a
/// read operation has been registered.
/// The constructed .
/// Thrown when is null.
/// Thrown when no read operation has been registered for
/// .
/// Use to find out
/// whether a read operation has been registered for .
internal StochasticSoilModel Get(StochasticSoilModelEntity entity)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
try
{
return stochasticSoilModels[entity];
}
catch (KeyNotFoundException e)
{
throw new InvalidOperationException(e.Message, e);
}
}
#endregion
#region StochasticSoilProfileEntity: Read, Contains, Get
///
/// Registers a read operation for and
/// the that was constructed with the information.
///
/// The that was read.
/// The that was constructed.
/// Thrown when either:
///
/// - is null
/// - is null
///
internal void Read(StochasticSoilProfileEntity entity, StochasticSoilProfile model)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
if (model == null)
{
throw new ArgumentNullException("model");
}
stochasticSoilProfiles[entity] = model;
}
///
/// Checks whether a read operations has been registered for the given .
///
/// The to check for.
/// true if the was read before, false otherwise.
/// Thrown when is null.
internal bool Contains(StochasticSoilProfileEntity entity)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
return stochasticSoilProfiles.ContainsKey(entity);
}
///
/// Obtains the which was read for the given
/// .
///
/// The for which
/// a read operation has been registered.
/// The constructed .
/// Thrown when is null.
/// Thrown when no read operation has been registered for
/// .
/// Use to find out whether a read operation has been registered for
/// .
internal StochasticSoilProfile Get(StochasticSoilProfileEntity entity)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
try
{
return stochasticSoilProfiles[entity];
}
catch (KeyNotFoundException e)
{
throw new InvalidOperationException(e.Message, e);
}
}
#endregion
#region SoilProfileEntity: Read, Contains, Get
///
/// Registers a read operation for and the that
/// was constructed with the information.
///
/// The that was read.
/// The that was constructed.
/// Thrown when either:
///
/// - is null
/// - is null
///
internal void Read(SoilProfileEntity entity, PipingSoilProfile model)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
if (model == null)
{
throw new ArgumentNullException("model");
}
soilProfiles[entity] = model;
}
///
/// Checks whether a read operations has been registered for the given .
///
/// The to check for.
/// true if the was read before, false otherwise.
/// Thrown when is null.
internal bool Contains(SoilProfileEntity entity)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
return soilProfiles.ContainsKey(entity);
}
///
/// Obtains the which was read for the given .
///
/// The for which a read operation has been registered.
/// The constructed .
/// Thrown when is null.
/// Thrown when no read operation has been registered for
/// .
/// Use to find out whether a read operation has been registered for
/// .
internal PipingSoilProfile Get(SoilProfileEntity entity)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
try
{
return soilProfiles[entity];
}
catch (KeyNotFoundException e)
{
throw new InvalidOperationException(e.Message, e);
}
}
#endregion
#region SurfaceLineEntity: Read, Contains, Get
///
/// Registers a read operation for and the
/// that was constructed with the information.
///
/// The that was read.
/// The that was constructed.
/// Thrown when either:
///
/// - is null
/// - is null
///
internal void Read(SurfaceLineEntity entity, RingtoetsPipingSurfaceLine model)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
if (model == null)
{
throw new ArgumentNullException("model");
}
surfaceLines[entity] = model;
}
///
/// Checks whether a read operation has been registered for a given .
///
/// The to check for.
/// true if the was read before, false otherwise.
/// Thrown when is null.
internal bool Contains(SurfaceLineEntity entity)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
return surfaceLines.ContainsKey(entity);
}
///
/// Obtains the which was read for the
/// given .
///
/// The for which a read operation
/// has been registered.
/// The constructed .
/// Thrown when is null.
/// Thrown when no read operation has
/// been registered for .
/// Use to find out whether a
/// read operation has been registered for .
internal RingtoetsPipingSurfaceLine Get(SurfaceLineEntity entity)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
try
{
return surfaceLines[entity];
}
catch (KeyNotFoundException e)
{
throw new InvalidOperationException(e.Message, e);
}
}
#endregion
#region SurfaceLinePointEntity: Read, Contains, Get
///
/// Registers a read operation for and the
/// (that is part of )
/// that was constructed with the information.
///
/// The that was read.
/// The that was constructed.
/// Thrown when either:
///
/// - is null
/// - is null
///
internal void Read(SurfaceLinePointEntity entity, Point3D model)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
if (model == null)
{
throw new ArgumentNullException("model");
}
surfaceLineGeometryPoints[entity] = model;
}
///
/// Checks whether a read operation has been registered for a given .
///
/// The to check for.
/// true if the was read before, false otherwise.
/// Thrown when is null.
internal bool Contains(SurfaceLinePointEntity entity)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
return surfaceLineGeometryPoints.ContainsKey(entity);
}
///
/// Obtains the that is part of
/// which was read for the given .
///
/// The for which a read
/// operation has been registered.
/// The constructed .
/// Thrown when is null.
/// Thrown when no read operation has
/// been registered for .
/// Use to find out whether a
/// read operation has been registered for .
internal Point3D Get(SurfaceLinePointEntity entity)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
try
{
return surfaceLineGeometryPoints[entity];
}
catch (KeyNotFoundException e)
{
throw new InvalidOperationException(e.Message, e);
}
}
#endregion
#region HydraulicLocationEntity: Read, Contains, Get
///
/// Registers a read operation for and the
/// that was constructed with the information.
///
/// The that was read.
/// The that was constructed.
/// Thrown when either:
///
/// - is null
/// - is null
///
internal void Read(HydraulicLocationEntity entity, HydraulicBoundaryLocation model)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
if (model == null)
{
throw new ArgumentNullException("model");
}
hydraulicBoundaryLocations[entity] = model;
}
///
/// Checks whether a read operation has been registered for a given .
///
/// The to check for.
/// true if the was read before, false otherwise.
/// Thrown when is null.
internal bool Contains(HydraulicLocationEntity entity)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
return hydraulicBoundaryLocations.ContainsKey(entity);
}
///
/// Obtains the which was read for the
/// given .
///
/// The for which a read
/// operation has been registered.
/// The constructed .
/// Thrown when is null.
/// Thrown when no read operation has
/// been registered for .
/// Use to find out whether a
/// read operation has been registered for .
internal HydraulicBoundaryLocation Get(HydraulicLocationEntity entity)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
try
{
return hydraulicBoundaryLocations[entity];
}
catch (KeyNotFoundException e)
{
throw new InvalidOperationException(e.Message, e);
}
}
#endregion
#region FailureMechanismSectionEntity: Read, Contains, Get
///
/// Registers a read operation for and the
/// that was constructed with the information.
///
/// The that was read.
/// The that was constructed.
/// Thrown when either:
///
/// - is null
/// - is null
///
internal void Read(FailureMechanismSectionEntity entity, FailureMechanismSection model)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
if (model == null)
{
throw new ArgumentNullException("model");
}
failureMechanismSections[entity] = model;
}
///
/// Checks whether a read operation has been registered for a given .
///
/// The to check for.
/// true if the was read before, false otherwise.
/// Thrown when is null.
internal bool Contains(FailureMechanismSectionEntity entity)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
return failureMechanismSections.ContainsKey(entity);
}
///
/// Obtains the which was read for the
/// given .
///
/// The for which a read
/// operation has been registered.
/// The constructed .
/// Thrown when is null.
/// Thrown when no read operation has
/// been registered for .
/// Use to find out whether a
/// read operation has been registered for .
internal FailureMechanismSection Get(FailureMechanismSectionEntity entity)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
try
{
return failureMechanismSections[entity];
}
catch (KeyNotFoundException e)
{
throw new InvalidOperationException(e.Message, e);
}
}
#endregion
}
}