// 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.Utils; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.HeightStructures.Data; 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 = CreateDictionary(); private readonly Dictionary stochasticSoilProfiles = CreateDictionary(); private readonly Dictionary soilProfiles = CreateDictionary(); private readonly Dictionary surfaceLines = CreateDictionary(); private readonly Dictionary hydraulicBoundaryLocations = CreateDictionary(); private readonly Dictionary grassCoverErosionOutwardsHydraulicBoundaryLocations = CreateDictionary(); private readonly Dictionary failureMechanismSections = CreateDictionary(); private readonly Dictionary dikeProfiles = CreateDictionary(); private readonly Dictionary foreshoreProfiles = CreateDictionary(); private readonly Dictionary grassCoverErosionInwardsCalculations = CreateDictionary(); private readonly Dictionary heightStructures = CreateDictionary(); private static Dictionary CreateDictionary() { return 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 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 #region DikeProfileEntity: 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(DikeProfileEntity entity, DikeProfile model) { if (entity == null) { throw new ArgumentNullException("entity"); } if (model == null) { throw new ArgumentNullException("model"); } dikeProfiles[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(DikeProfileEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } return dikeProfiles.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 DikeProfile Get(DikeProfileEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } try { return dikeProfiles[entity]; } catch (KeyNotFoundException e) { throw new InvalidOperationException(e.Message, e); } } #endregion #region ForeshoreProfileEntity: 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(ForeshoreProfileEntity entity, ForeshoreProfile model) { if (entity == null) { throw new ArgumentNullException("entity"); } if (model == null) { throw new ArgumentNullException("model"); } foreshoreProfiles[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(ForeshoreProfileEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } return foreshoreProfiles.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 ForeshoreProfile Get(ForeshoreProfileEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } try { return foreshoreProfiles[entity]; } catch (KeyNotFoundException e) { throw new InvalidOperationException(e.Message, e); } } #endregion #region GrassCoverErosionInwardsCalculationEntity: 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(GrassCoverErosionInwardsCalculationEntity entity, GrassCoverErosionInwardsCalculation model) { if (entity == null) { throw new ArgumentNullException("entity"); } if (model == null) { throw new ArgumentNullException("model"); } grassCoverErosionInwardsCalculations[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(GrassCoverErosionInwardsCalculationEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } return grassCoverErosionInwardsCalculations.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 GrassCoverErosionInwardsCalculation Get(GrassCoverErosionInwardsCalculationEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } try { return grassCoverErosionInwardsCalculations[entity]; } catch (KeyNotFoundException e) { throw new InvalidOperationException(e.Message, e); } } #endregion #region GrassCoverErosionOutwardsHydraulicLocationEntity: 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(GrassCoverErosionOutwardsHydraulicLocationEntity entity, HydraulicBoundaryLocation model) { if (entity == null) { throw new ArgumentNullException("entity"); } if (model == null) { throw new ArgumentNullException("model"); } grassCoverErosionOutwardsHydraulicBoundaryLocations[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(GrassCoverErosionOutwardsHydraulicLocationEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } return grassCoverErosionOutwardsHydraulicBoundaryLocations.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(GrassCoverErosionOutwardsHydraulicLocationEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } try { return grassCoverErosionOutwardsHydraulicBoundaryLocations[entity]; } catch (KeyNotFoundException e) { throw new InvalidOperationException(e.Message, e); } } #endregion #region HeightStructureEntity: 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(HeightStructureEntity entity, HeightStructure model) { if (entity == null) { throw new ArgumentNullException("entity"); } if (model == null) { throw new ArgumentNullException("model"); } heightStructures[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(HeightStructureEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } return heightStructures.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 HeightStructure Get(HeightStructureEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } try { return heightStructures[entity]; } catch (KeyNotFoundException e) { throw new InvalidOperationException(e.Message, e); } } #endregion } }