// 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.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 soilProfiles = new Dictionary(new ReferenceEqualityComparer());
private readonly Dictionary surfaceLineGeometryPoints = new Dictionary(new ReferenceEqualityComparer());
#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 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
}
}