// 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.Collections.Generic; using System.IO; using System.Linq; using Core.Common.Base.Geometry; using Core.Common.Base.Service; using Core.Common.Gui.Commands; using Core.Common.Utils.IO; using Rhino.Mocks; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Hydraulics; using Ringtoets.Common.IO.FileImporters; using Ringtoets.Common.IO.FileImporters.MessageProviders; using Ringtoets.Common.IO.ReferenceLines; using Ringtoets.Common.IO.SoilProfile; using Ringtoets.Common.IO.SurfaceLines; using Ringtoets.Integration.Data; using Ringtoets.Integration.Plugin.Handlers; using Ringtoets.MacroStabilityInwards.Data; using Ringtoets.MacroStabilityInwards.Data.SoilProfile; using Ringtoets.MacroStabilityInwards.IO.Importers; using Ringtoets.MacroStabilityInwards.Plugin.FileImporter; using Ringtoets.MacroStabilityInwards.Primitives; using Ringtoets.Piping.Data; using Ringtoets.Piping.Data.SoilProfile; using Ringtoets.Piping.Plugin.FileImporter; using Ringtoets.Piping.Primitives; using PipingSurfaceLinesCsvImporterConfigurationFactory = Ringtoets.Piping.Plugin.FileImporter.SurfaceLinesCsvImporterConfigurationFactory; using MacroStabilityInwardsSurfaceLinesCsvImporterConfigurationFactory = Ringtoets.MacroStabilityInwards.Plugin.FileImporter.SurfaceLinesCsvImporterConfigurationFactory; namespace Ringtoets.Integration.TestUtils { /// /// Helper methods related to importing data for integration tests. /// public static class DataImportHelper { /// /// Imports the on the . /// /// The to import the reference line on. public static void ImportReferenceLine(AssessmentSection assessmentSection) { using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(typeof(DataImportHelper).Assembly, true, "traject_6-3.shp", "traject_6-3.dbf", "traject_6-3.prj", "traject_6-3.shx")) { string filePath = Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "traject_6-3.shp"); var mocks = new MockRepository(); var viewCommands = mocks.Stub(); mocks.ReplayAll(); var activity = new FileImportActivity(new ReferenceLineImporter(assessmentSection, new ReferenceLineReplacementHandler(viewCommands), filePath), "ReferenceLineImporter"); activity.Run(); activity.Finish(); mocks.VerifyAll(); } } /// /// Imports the data for a given . /// /// The to import on. /// The to import on. /// /// This will import 283 failure mechanism sections. /// Imports using . /// /// public static void ImportFailureMechanismSections(AssessmentSection assessmentSection, IFailureMechanism failureMechanism) { using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(typeof(DataImportHelper).Assembly, true, "traject_6-3_vakken.shp", "traject_6-3_vakken.dbf", "traject_6-3_vakken.prj", "traject_6-3_vakken.shx")) { string filePath = Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "traject_6-3_vakken.shp"); var activity = new FileImportActivity(new FailureMechanismSectionsImporter(failureMechanism, assessmentSection.ReferenceLine, filePath), "FailureMechanismSectionsImporter"); activity.Run(); activity.Finish(); } } /// /// Imports the data for a given . /// /// The to import on. /// The to import on. /// /// This will import the same 283 failure mechanism sections on all failure mechanisms. /// Does not import using . /// /// public static void ImportFailureMechanismSections(AssessmentSection assessmentSection, IEnumerable targetFailureMechanisms) { using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(typeof(DataImportHelper).Assembly, true, "traject_6-3_vakken.shp", "traject_6-3_vakken.dbf", "traject_6-3_vakken.prj", "traject_6-3_vakken.shx")) { IFailureMechanism[] failureMechanisms = targetFailureMechanisms.ToArray(); for (var i = 0; i < failureMechanisms.Length; i++) { if (i == 0) { string filePath = Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "traject_6-3_vakken.shp"); var importer = new FailureMechanismSectionsImporter(failureMechanisms[i], assessmentSection.ReferenceLine, filePath); importer.Import(); } else { // Copy same FailureMechanismSection instances to other failure mechanisms foreach (FailureMechanismSection section in failureMechanisms[0].Sections) { FailureMechanismSection clonedSection = DeepCloneSection(section); failureMechanisms[i].AddSection(clonedSection); } } } } } /// /// Imports the for the given . /// /// The to import on. /// This will import 19 Hydraulic boundary locations. public static void ImportHydraulicBoundaryDatabase(AssessmentSection assessmentSection) { using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(typeof(DataImportHelper).Assembly, false, "HRD dutch coast south.sqlite", "HLCD.sqlite", "HRD dutch coast south.config.sqlite")) using (var hydraulicBoundaryDatabaseImporter = new HydraulicBoundaryDatabaseImporter()) { string filePath = Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "HRD dutch coast south.sqlite"); hydraulicBoundaryDatabaseImporter.Import(assessmentSection, filePath); } } private static FailureMechanismSection DeepCloneSection(FailureMechanismSection section) { return new FailureMechanismSection(section.Name, section.Points.Select(p => new Point2D(p))); } #region Piping Specific Imports /// /// Imports the data for the /// of the given . /// /// The to import on. /// This will import 4 surface lines. public static void ImportPipingSurfaceLines(AssessmentSection assessmentSection) { using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(typeof(DataImportHelper).Assembly, true, "DR6_surfacelines.csv", "DR6_surfacelines.krp.csv")) { string filePath = Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "DR6_surfacelines.csv"); var activity = new FileImportActivity(new SurfaceLinesCsvImporter( assessmentSection.PipingFailureMechanism.SurfaceLines, filePath, new ImportMessageProvider(), PipingSurfaceLinesCsvImporterConfigurationFactory.CreateReplaceStrategyConfiguration(assessmentSection.PipingFailureMechanism, assessmentSection.ReferenceLine)), "PipingSurfaceLinesCsvImporter") ; activity.Run(); activity.Finish(); } } /// /// Imports the data for the /// of the given . /// /// The to import on. /// This will import 4 soil models with one profile each. public static void ImportPipingStochasticSoilModels(AssessmentSection assessmentSection) { using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(typeof(DataImportHelper).Assembly, true, "DR6.soil")) { string filePath = Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "DR6.soil"); var activity = new FileImportActivity( new StochasticSoilModelImporter( assessmentSection.PipingFailureMechanism.StochasticSoilModels, filePath, new ImportMessageProvider(), StochasticSoilModelImporterConfigurationFactory.CreateReplaceStrategyConfiguration(assessmentSection.PipingFailureMechanism)), "StochasticSoilModelImporter"); activity.Run(); activity.Finish(); } } #endregion #region MacroStabilityInwards Specific Imports /// /// Imports the data for the /// of the given . /// /// The to import on. /// This will import 4 surface lines. public static void ImportMacroStabilityInwardsSurfaceLines(AssessmentSection assessmentSection) { using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(typeof(DataImportHelper).Assembly, true, "DR6_surfacelines.csv", "DR6_surfacelines.krp.csv")) { string filePath = Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "DR6_surfacelines.csv"); var activity = new FileImportActivity(new SurfaceLinesCsvImporter( assessmentSection.MacroStabilityInwards.SurfaceLines, filePath, new ImportMessageProvider(), MacroStabilityInwardsSurfaceLinesCsvImporterConfigurationFactory.CreateReplaceStrategyConfiguration(assessmentSection.MacroStabilityInwards, assessmentSection.ReferenceLine)), "MacroStabilityInwardsSurfaceLinesCsvImporter"); activity.Run(); activity.Finish(); } } /// /// Imports the data for the /// of the given . /// /// The to import on. /// This will import 4 soil models with one profile each. public static void ImportMacroStabilityInwardsStochasticSoilModels(AssessmentSection assessmentSection) { using (var embeddedResourceFileWriter = new EmbeddedResourceFileWriter(typeof(DataImportHelper).Assembly, true, "DR6.soil")) { string filePath = Path.Combine(embeddedResourceFileWriter.TargetFolderPath, "DR6.soil"); var activity = new FileImportActivity(new StochasticSoilModelImporter( assessmentSection.MacroStabilityInwards.StochasticSoilModels, filePath, new ImportMessageProvider(), new StochasticSoilModelReplaceDataStrategy(assessmentSection.MacroStabilityInwards)), "StochasticSoilModelImporter"); activity.Run(); activity.Finish(); } } #endregion } }