// 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 System.Linq; using Core.Common.Base; using Ringtoets.ClosingStructures.Data; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.IO; using Ringtoets.Common.IO.FileImporters; using Ringtoets.Common.IO.Structures; using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources; namespace Ringtoets.ClosingStructures.IO { /// /// Imports point shapefiles containing closing structure locations and csv files containing closing structure schematizations. /// public class ClosingStructuresImporter : StructuresImporter> { private readonly ObservableList importTarget; /// /// Creates a new instance of . /// /// The closing structures to import on. /// The reference line used to check if the /// objects found in the file are intersecting it. /// The path to the file to import from. /// Thrown when , /// or is null. public ClosingStructuresImporter(ObservableList importTarget, ReferenceLine referenceLine, string filePath) : base(importTarget, referenceLine, filePath) { this.importTarget = importTarget; } protected override void CreateSpecificStructures(ICollection structureLocations, Dictionary> groupedStructureParameterRows) { IEnumerable importedClosingStructures = CreateClosingStructures(structureLocations.ToList(), groupedStructureParameterRows); foreach (ClosingStructure closingStructure in importedClosingStructures) { importTarget.Add(closingStructure); } } private IEnumerable CreateClosingStructures(IList structureLocations, Dictionary> groupedStructureParameterRows) { var closingStructures = new List(); for (int i = 0; i < structureLocations.Count; i++) { StructureLocation structureLocation = structureLocations[i]; string id = structureLocation.Id; if (!groupedStructureParameterRows.ContainsKey(id)) { log.WarnFormat(RingtoetsCommonIOResources.StructuresImporter_CreateSpecificStructures_no_structuresdata_for_location_0_, id); log.ErrorFormat("Kunstwerk nummer {0} wordt overgeslagen.", i + 1); continue; } List structureParameterRows = groupedStructureParameterRows[id]; ValidationResult parameterRowsValidationResult = StructuresParameterRowsValidator.ValidateClosingStructuresParameters(structureParameterRows); if (!parameterRowsValidationResult.IsValid) { LogMessages(parameterRowsValidationResult, i + 1); continue; } ClosingStructure closingStructure = CreateClosingStructure(structureLocation, structureParameterRows); closingStructures.Add(closingStructure); } return closingStructures; } private static ClosingStructure CreateClosingStructure(StructureLocation structureLocation, List structureParameterRows) { var closingStructure = new ClosingStructure( structureLocation.Name, structureLocation.Id, structureLocation.Point, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE1").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE1").VarianceValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE2").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE2").VarianceValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE3").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE4").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE4").VarianceValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE5").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE5").VarianceValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE6").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE6").VarianceValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE7").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE7").VarianceValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE8").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE8").VarianceValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE9").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE9").VarianceValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE10").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE10").VarianceValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE11").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE12").NumericalValue, (int) structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE13").NumericalValue, structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE14").NumericalValue, (int) structureParameterRows.First(row => row.ParameterId == "KW_HOOGTE15").NumericalValue); return closingStructure; } } }