Index: Core/Components/src/Core.Components.Gis.IO/Core.Components.Gis.IO.csproj =================================================================== diff -u -r437beb696991b6fbcdc58456f9d0c9361479a603 -r718ec8557636bd25dc37b11a836af2e6b3829be6 --- Core/Components/src/Core.Components.Gis.IO/Core.Components.Gis.IO.csproj (.../Core.Components.Gis.IO.csproj) (revision 437beb696991b6fbcdc58456f9d0c9361479a603) +++ Core/Components/src/Core.Components.Gis.IO/Core.Components.Gis.IO.csproj (.../Core.Components.Gis.IO.csproj) (revision 718ec8557636bd25dc37b11a836af2e6b3829be6) @@ -61,6 +61,7 @@ + Index: Core/Components/src/Core.Components.Gis.IO/Writers/PointShapeFileWriter.cs =================================================================== diff -u --- Core/Components/src/Core.Components.Gis.IO/Writers/PointShapeFileWriter.cs (revision 0) +++ Core/Components/src/Core.Components.Gis.IO/Writers/PointShapeFileWriter.cs (revision 718ec8557636bd25dc37b11a836af2e6b3829be6) @@ -0,0 +1,66 @@ +// 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 Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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.Linq; +using Core.Common.Base.Geometry; +using Core.Components.Gis.Features; +using Core.Components.Gis.Geometries; +using DotSpatial.Data; +using DotSpatial.Topology; + +namespace Core.Components.Gis.IO.Writers +{ + /// + /// Class to be used to write points to a shapefile. + /// + public class PointShapeFileWriter : ShapeFileWriterBase + { + /// + /// Initializes a new instance of the class. + /// + public PointShapeFileWriter() + { + ShapeFile = new PointShapefile + { + FeatureType = FeatureType.Point + }; + } + + protected override IFeature AddFeature(MapFeature mapFeature) + { + Point point = CreatePointFromMapFeature(mapFeature); + + return ShapeFile.AddFeature(point); + } + + private static Point CreatePointFromMapFeature(MapFeature mapFeature) + { + MapGeometry geometry = mapFeature.MapGeometries.First(); + + IEnumerable mapGeometryPointCollection = geometry.PointCollections.First(); + + Coordinate coordinate = mapGeometryPointCollection.Select(p => new Coordinate(p.X, p.Y)).First(); + + return new Point(coordinate); + } + } +} \ No newline at end of file Index: Core/Components/src/Core.Components.Gis.IO/Writers/PolylineShapeFileWriter.cs =================================================================== diff -u -r58e275211395fc690df2706ccdaff082ecf7b544 -r718ec8557636bd25dc37b11a836af2e6b3829be6 --- Core/Components/src/Core.Components.Gis.IO/Writers/PolylineShapeFileWriter.cs (.../PolylineShapeFileWriter.cs) (revision 58e275211395fc690df2706ccdaff082ecf7b544) +++ Core/Components/src/Core.Components.Gis.IO/Writers/PolylineShapeFileWriter.cs (.../PolylineShapeFileWriter.cs) (revision 718ec8557636bd25dc37b11a836af2e6b3829be6) @@ -19,12 +19,9 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; using System.Collections.Generic; -using System.Data; using System.Linq; using Core.Common.Base.Geometry; -using Core.Components.Gis.Data; using Core.Components.Gis.Features; using Core.Components.Gis.Geometries; using DotSpatial.Data; @@ -35,10 +32,8 @@ /// /// Class to be used to write polylines to a shapefile. /// - public class PolylineShapeFileWriter : ShapeFileWriterBase + public class PolylineShapeFileWriter : ShapeFileWriterBase { - private bool hasPropertyTable; - /// /// Initializes a new instance of the class. /// @@ -50,49 +45,15 @@ }; } - /// - /// Create a new feature from a object and store it in the shapefile. - /// - /// The which is to be stored as a feature. - /// Thrown when a contains different metadata keys - /// than the of the first call to this method. - public override void AddFeature(MapLineData mapData) + protected override IFeature AddFeature(MapFeature mapFeature) { - MapFeature mapFeature = mapData.Features.First(); + LineString lineString = CreateLineStringFromMapFeature(mapFeature); - if (!hasPropertyTable) - { - CreateAttributeTable(mapFeature); - hasPropertyTable = true; - } - - LineString lineString = CreateLineStringForMapFeature(mapFeature); - - IFeature lineFeature = ShapeFile.AddFeature(lineString); - - CopyMetaDataFromMapFeatureToAttributeTable(mapFeature, lineFeature); + return ShapeFile.AddFeature(lineString); } - private void CreateAttributeTable(MapFeature mapFeature) + private static LineString CreateLineStringFromMapFeature(MapFeature mapFeature) { - IDictionary metaData = mapFeature.MetaData; - List sortedKeys = metaData.Keys.ToList(); - sortedKeys.Sort(); - - var columns = ShapeFile.DataTable.Columns; - foreach (string key in sortedKeys) - { - var value = metaData[key]; - columns.Add(new DataColumn - { - DataType = value.GetType(), - ColumnName = key - }); - } - } - - private static LineString CreateLineStringForMapFeature(MapFeature mapFeature) - { MapGeometry geometry = mapFeature.MapGeometries.First(); IEnumerable mapGeometryPointCollection = geometry.PointCollections.First(); @@ -101,27 +62,5 @@ return new LineString(coordinates); } - - /// - /// Copy the content of a feature's metadata to the attribute table of the shapefile. - /// - /// The whose metadata is to be copied. - /// The shapefile feature to whose attribute table row the metadata is copied. - /// Thrown when a contains different metadata keys - /// than the of the first call to . - private static void CopyMetaDataFromMapFeatureToAttributeTable(MapFeature mapFeature, IFeature feature) - { - IDictionary metaData = mapFeature.MetaData; - List sortedKeys = metaData.Keys.ToList(); - sortedKeys.Sort(); - - foreach (string key in sortedKeys) - { - var value = metaData[key]; - feature.DataRow.BeginEdit(); - feature.DataRow[key] = value; - feature.DataRow.EndEdit(); - } - } } } \ No newline at end of file Index: Core/Components/src/Core.Components.Gis.IO/Writers/ShapeFileWriterBase.cs =================================================================== diff -u -r58e275211395fc690df2706ccdaff082ecf7b544 -r718ec8557636bd25dc37b11a836af2e6b3829be6 --- Core/Components/src/Core.Components.Gis.IO/Writers/ShapeFileWriterBase.cs (.../ShapeFileWriterBase.cs) (revision 58e275211395fc690df2706ccdaff082ecf7b544) +++ Core/Components/src/Core.Components.Gis.IO/Writers/ShapeFileWriterBase.cs (.../ShapeFileWriterBase.cs) (revision 718ec8557636bd25dc37b11a836af2e6b3829be6) @@ -20,9 +20,13 @@ // All rights reserved. using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; using Core.Common.IO.Exceptions; using Core.Common.Utils; using Core.Components.Gis.Data; +using Core.Components.Gis.Features; using DotSpatial.Data; using CoreCommonUtilsResources = Core.Common.Utils.Properties.Resources; @@ -31,18 +35,28 @@ /// /// The base class to write data to a shapefile. /// - public abstract class ShapeFileWriterBase : IDisposable where T : FeatureBasedMapData + public abstract class ShapeFileWriterBase : IDisposable { protected Shapefile ShapeFile; + private bool hasPropertyTable; /// - /// Adds a feature to the in-memory shapefile. + /// Creates a new feature from and adds it to the in-memory shapefile. /// - /// The to add to the in-memory shapefile as a feature. + /// The to add to the in-memory shapefile as a feature. /// Thrown when a contains different metadata keys - /// than the of the first call to . - public virtual void AddFeature(T mapData) {} + /// than the of the first call to . + public void CopyToFeature(FeatureBasedMapData mapData) + { + MapFeature mapFeature = mapData.Features.First(); + EnsureAttributeTableExists(mapFeature); + + IFeature feature = AddFeature(mapFeature); + + CopyMetaDataFromMapFeatureToAttributeTable(mapFeature, feature); + } + /// /// Saves the in-memory shapefile to a file, overwriting when necessary. /// @@ -70,5 +84,66 @@ ShapeFile.Close(); } } + + /// + /// Create a new feature from a . + /// + /// The from which to create a feature. + /// The created feature. + protected virtual IFeature AddFeature(MapFeature mapFeature) + { + return null; + } + + private void EnsureAttributeTableExists(MapFeature mapFeature) + { + if (hasPropertyTable) + { + return; + } + + CreateAttributeTable(mapFeature); + hasPropertyTable = true; + } + + /// + /// Copy the content of a feature's metadata to the attribute table of the shapefile. + /// + /// The whose metadata is to be copied. + /// The shapefile feature to whose attribute table row the metadata is copied. + /// Thrown when a contains different metadata keys + /// than the of the first call to . + private static void CopyMetaDataFromMapFeatureToAttributeTable(MapFeature mapFeature, IFeature feature) + { + IDictionary metaData = mapFeature.MetaData; + List sortedKeys = metaData.Keys.ToList(); + sortedKeys.Sort(); + + foreach (string key in sortedKeys) + { + var value = metaData[key]; + feature.DataRow.BeginEdit(); + feature.DataRow[key] = value; + feature.DataRow.EndEdit(); + } + } + + private void CreateAttributeTable(MapFeature mapFeature) + { + IDictionary metaData = mapFeature.MetaData; + List sortedKeys = metaData.Keys.ToList(); + sortedKeys.Sort(); + + var columns = ShapeFile.DataTable.Columns; + foreach (string key in sortedKeys) + { + var value = metaData[key]; + columns.Add(new DataColumn + { + DataType = value.GetType(), + ColumnName = key + }); + } + } } } \ No newline at end of file Index: Core/Components/test/Core.Components.Gis.IO.Test/Core.Components.Gis.IO.Test.csproj =================================================================== diff -u -r437beb696991b6fbcdc58456f9d0c9361479a603 -r718ec8557636bd25dc37b11a836af2e6b3829be6 --- Core/Components/test/Core.Components.Gis.IO.Test/Core.Components.Gis.IO.Test.csproj (.../Core.Components.Gis.IO.Test.csproj) (revision 437beb696991b6fbcdc58456f9d0c9361479a603) +++ Core/Components/test/Core.Components.Gis.IO.Test/Core.Components.Gis.IO.Test.csproj (.../Core.Components.Gis.IO.Test.csproj) (revision 718ec8557636bd25dc37b11a836af2e6b3829be6) @@ -54,6 +54,7 @@ + Index: Core/Components/test/Core.Components.Gis.IO.Test/Writers/PointShapeFileWriterTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.Gis.IO.Test/Writers/PointShapeFileWriterTest.cs (revision 0) +++ Core/Components/test/Core.Components.Gis.IO.Test/Writers/PointShapeFileWriterTest.cs (revision 718ec8557636bd25dc37b11a836af2e6b3829be6) @@ -0,0 +1,148 @@ +// 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 Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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.ObjectModel; +using System.IO; +using System.Linq; +using Core.Common.Base.Geometry; +using Core.Common.TestUtil; +using Core.Components.Gis.Data; +using Core.Components.Gis.Features; +using Core.Components.Gis.Geometries; +using Core.Components.Gis.IO.Writers; +using NUnit.Framework; + +namespace Core.Components.Gis.IO.Test.Writers +{ + [TestFixture] + public class PointShapeFileWriterTest + { + [Test] + public void DefaultConstructor_ExpectedValues() + { + // Call + using (var writer = new PointShapeFileWriter()) + { + // Assert + Assert.IsInstanceOf(writer); + } + } + + [Test] + public void CopyToFeature_InconsistentMetaDataBetweenMapPointDatas_ThrowArgumentException() + { + // Setup + MapFeature[] features1 = CreateFeatures(0.0); + var mapPointData1 = new MapPointData("test data 1") + { + Features = features1 + }; + mapPointData1.Features.First().MetaData["firstKey"] = 123; + mapPointData1.Features.First().MetaData["secondKey"] = "aValue"; + + MapFeature[] features2 = CreateFeatures(10.0); + var mapPointData2 = new MapPointData("test data 2") + { + Features = features2 + }; + mapPointData2.Features.First().MetaData["firstKey"] = 123; + mapPointData2.Features.First().MetaData["anotherKey"] = "anotherValue"; + + using (var writer = new PointShapeFileWriter()) + { + writer.CopyToFeature(mapPointData1); + + // Call + TestDelegate call = () => writer.CopyToFeature(mapPointData2); + + // Assert + Assert.Throws(call); + } + } + + [Test] + public void SaveAs_ValidMapPointData_WritesShapeFile() + { + // Setup + string directoryPath = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO, + "SaveAs_ValidMapPointData_WritesShapeFile"); + Directory.CreateDirectory(directoryPath); + string filePath = Path.Combine(directoryPath, "test.shp"); + var baseName = "test"; + + MapFeature[] features = CreateFeatures(0.0); + + var mapPointData = new MapPointData("test data") + { + Features = features + }; + + mapPointData.Features.First().MetaData[""] = 123; + + try + { + using (var writer = new PointShapeFileWriter()) + { + writer.CopyToFeature(mapPointData); + + // Precondition + AssertEssentialShapefileExists(directoryPath, baseName, false); + + // Call + writer.SaveAs(filePath); + + // Assert + AssertEssentialShapefileExists(directoryPath, baseName, true); + } + } + finally + { + Directory.Delete(directoryPath, true); + } + } + + private static MapFeature[] CreateFeatures(double seed) + { + return new[] + { + new MapFeature(new Collection + { + new MapGeometry(new[] + { + new[] + { + new Point2D(seed, seed) + } + }) + }) + }; + } + + private static void AssertEssentialShapefileExists(string directoryPath, string baseName, bool shouldExist) + { + string pathName = Path.Combine(directoryPath, baseName); + Assert.AreEqual(shouldExist, File.Exists(pathName + ".shp")); + Assert.AreEqual(shouldExist, File.Exists(pathName + ".shx")); + Assert.AreEqual(shouldExist, File.Exists(pathName + ".dbf")); + } + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.Gis.IO.Test/Writers/PolylineShapeFileWriterTest.cs =================================================================== diff -u -r58e275211395fc690df2706ccdaff082ecf7b544 -r718ec8557636bd25dc37b11a836af2e6b3829be6 --- Core/Components/test/Core.Components.Gis.IO.Test/Writers/PolylineShapeFileWriterTest.cs (.../PolylineShapeFileWriterTest.cs) (revision 58e275211395fc690df2706ccdaff082ecf7b544) +++ Core/Components/test/Core.Components.Gis.IO.Test/Writers/PolylineShapeFileWriterTest.cs (.../PolylineShapeFileWriterTest.cs) (revision 718ec8557636bd25dc37b11a836af2e6b3829be6) @@ -44,12 +44,12 @@ using (var writer = new PolylineShapeFileWriter()) { // Assert - Assert.IsInstanceOf>(writer); + Assert.IsInstanceOf(writer); } } [Test] - public void AddFeature_InconsistentMetaDataBetweenMapLineDatas_ThrowArgumentException() + public void CopyToFeature_InconsistentMetaDataBetweenMapLineDatas_ThrowArgumentException() { // Setup MapFeature[] features1 = CreateFeatures(0.0); @@ -70,10 +70,10 @@ using (var writer = new PolylineShapeFileWriter()) { - writer.AddFeature(mapLineData1); + writer.CopyToFeature(mapLineData1); // Call - TestDelegate call = () => writer.AddFeature(mapLineData2); + TestDelegate call = () => writer.CopyToFeature(mapLineData2); // Assert Assert.Throws(call); @@ -103,7 +103,7 @@ { using (var writer = new PolylineShapeFileWriter()) { - writer.AddFeature(mapLineData); + writer.CopyToFeature(mapLineData); // Precondition AssertEssentialShapefileExists(directoryPath, baseName, false); @@ -113,7 +113,6 @@ // Assert AssertEssentialShapefileExists(directoryPath, baseName, true); - AssertEssentialShapefileMd5Hashes(directoryPath, baseName); } } finally @@ -122,25 +121,6 @@ } } - private void AssertEssentialShapefileMd5Hashes(string directoryPath, string baseName) - { - string refPathName = Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO), "md5_reference"); - string pathName = Path.Combine(directoryPath, baseName); - - Assert.AreEqual(MD5.Create().ComputeHash(File.ReadAllBytes(refPathName + ".shp")), - MD5.Create().ComputeHash(File.ReadAllBytes(pathName + ".shp"))); - Assert.AreEqual(MD5.Create().ComputeHash(File.ReadAllBytes(refPathName + ".shx")), - MD5.Create().ComputeHash(File.ReadAllBytes(pathName + ".shx"))); - - int headerLength = 32; - int bodyLength = 45; - var refContent = File.ReadAllBytes(refPathName + ".dbf"); - var content = File.ReadAllBytes(pathName + ".dbf"); - Assert.AreEqual(headerLength + bodyLength, content.Length); - Assert.AreEqual(refContent.Skip(headerLength).Take(bodyLength), - content.Skip(headerLength).Take(bodyLength)); - } - private static MapFeature[] CreateFeatures(double seed) { return new[] Index: Core/Components/test/Core.Components.Gis.IO.Test/Writers/ShapeFileWriterBaseTest.cs =================================================================== diff -u -r58e275211395fc690df2706ccdaff082ecf7b544 -r718ec8557636bd25dc37b11a836af2e6b3829be6 --- Core/Components/test/Core.Components.Gis.IO.Test/Writers/ShapeFileWriterBaseTest.cs (.../ShapeFileWriterBaseTest.cs) (revision 58e275211395fc690df2706ccdaff082ecf7b544) +++ Core/Components/test/Core.Components.Gis.IO.Test/Writers/ShapeFileWriterBaseTest.cs (.../ShapeFileWriterBaseTest.cs) (revision 718ec8557636bd25dc37b11a836af2e6b3829be6) @@ -24,8 +24,9 @@ using System.Security.AccessControl; using Core.Common.IO.Exceptions; using Core.Common.TestUtil; -using Core.Components.Gis.Data; +using Core.Components.Gis.Features; using Core.Components.Gis.IO.Writers; +using DotSpatial.Data; using NUnit.Framework; namespace Core.Components.Gis.IO.Test.Writers @@ -128,11 +129,11 @@ } } - private class TestShapeFileWriterBase : ShapeFileWriterBase + private class TestShapeFileWriterBase : ShapeFileWriterBase { - public override void AddFeature(MapLineData mapData) + protected override IFeature AddFeature(MapFeature mapFeature) { - // do nothing + return null; } } } Index: Core/Components/test/Core.Components.Gis.IO.Test/test-data/md5_reference.dbf =================================================================== diff -u -r4851d9c2b000de0707f6cce0872979ecc1e3dead -r718ec8557636bd25dc37b11a836af2e6b3829be6 Binary files differ Index: Core/Components/test/Core.Components.Gis.IO.Test/test-data/md5_reference.shp =================================================================== diff -u -r4851d9c2b000de0707f6cce0872979ecc1e3dead -r718ec8557636bd25dc37b11a836af2e6b3829be6 Binary files differ Index: Core/Components/test/Core.Components.Gis.IO.Test/test-data/md5_reference.shx =================================================================== diff -u -r4851d9c2b000de0707f6cce0872979ecc1e3dead -r718ec8557636bd25dc37b11a836af2e6b3829be6 Binary files differ Index: Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLineWriter.cs =================================================================== diff -u -r02cd0d1c2a271dd7cab5c3a1cc345b0627a9b221 -r718ec8557636bd25dc37b11a836af2e6b3829be6 --- Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLineWriter.cs (.../ReferenceLineWriter.cs) (revision 02cd0d1c2a271dd7cab5c3a1cc345b0627a9b221) +++ Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLineWriter.cs (.../ReferenceLineWriter.cs) (revision 718ec8557636bd25dc37b11a836af2e6b3829be6) @@ -60,7 +60,7 @@ MapLineData mapLineData = CreateMapLineData(referenceLine, id); - polyLineShapeFileWriter.AddFeature(mapLineData); + polyLineShapeFileWriter.CopyToFeature(mapLineData); polyLineShapeFileWriter.SaveAs(filePath); } Index: Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj =================================================================== diff -u -r437beb696991b6fbcdc58456f9d0c9361479a603 -r718ec8557636bd25dc37b11a836af2e6b3829be6 --- Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision 437beb696991b6fbcdc58456f9d0c9361479a603) +++ Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision 718ec8557636bd25dc37b11a836af2e6b3829be6) @@ -107,6 +107,10 @@ Core.Components.Gis False + + {70F8CC9C-5BC8-4FB2-B201-EAE7FA8088C2} + Ringtoets.HydraRing.Data + {11F1F874-45AF-43E4-8AE5-15A5C9593E28} Ringtoets.Integration.Data Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLineWriterTest.cs =================================================================== diff -u -r58e275211395fc690df2706ccdaff082ecf7b544 -r718ec8557636bd25dc37b11a836af2e6b3829be6 --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLineWriterTest.cs (.../ReferenceLineWriterTest.cs) (revision 58e275211395fc690df2706ccdaff082ecf7b544) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/ReferenceLineWriterTest.cs (.../ReferenceLineWriterTest.cs) (revision 718ec8557636bd25dc37b11a836af2e6b3829be6) @@ -21,6 +21,8 @@ using System; using System.IO; +using System.Linq; +using System.Security.Cryptography; using Core.Common.Base.Geometry; using Core.Common.TestUtil; using NUnit.Framework; @@ -36,7 +38,8 @@ { // Setup string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, - Path.Combine("ParameteredConstructor_ExpectedValues", "test.shp")); + Path.Combine("WriteReferenceLine_NullReferenceLine_ThrowArgumentNullException", + "test.shp")); var writer = new ReferenceLineWriter(); @@ -59,7 +62,8 @@ }); string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, - Path.Combine("WriteReferenceLine_NullId_ThrowArgumentException", "test.shp")); + Path.Combine("WriteReferenceLine_NullId_ThrowArgumentNullException", + "test.shp")); var writer = new ReferenceLineWriter(); @@ -85,7 +89,8 @@ }); string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, - Path.Combine("WriteReferenceLine_InvalidId_ThrowArgumentException", "test.shp")); + Path.Combine("WriteReferenceLine_InvalidId_ThrowArgumentException", + "test.shp")); var writer = new ReferenceLineWriter(); @@ -145,6 +150,7 @@ // Assert AssertEssentialShapefileExists(directoryPath, baseName, true); + AssertEssentialShapefileMd5Hashes(directoryPath, baseName); } finally { @@ -159,5 +165,24 @@ Assert.AreEqual(shouldExist, File.Exists(pathName + ".shx")); Assert.AreEqual(shouldExist, File.Exists(pathName + ".dbf")); } + + private void AssertEssentialShapefileMd5Hashes(string directoryPath, string baseName) + { + string refPathName = Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO), "LineShapefileMd5"); + string pathName = Path.Combine(directoryPath, baseName); + + AssertBinaryFileContent(refPathName, pathName, ".shp", 100, 88); + AssertBinaryFileContent(refPathName, pathName, ".shx", 100, 8); + AssertBinaryFileContent(refPathName, pathName, ".dbf", 32, 289); + } + + private static void AssertBinaryFileContent(string refPathName, string pathName, string extension, int headerLength, int bodyLength) + { + var refContent = File.ReadAllBytes(refPathName + extension); + var content = File.ReadAllBytes(pathName + extension); + Assert.AreEqual(headerLength + bodyLength, content.Length); + Assert.AreEqual(refContent.Skip(headerLength).Take(bodyLength), + content.Skip(headerLength).Take(bodyLength)); + } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/LineShapefileMd5.dbf =================================================================== diff -u Binary files differ Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/LineShapefileMd5.shp =================================================================== diff -u Binary files differ Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/test-data/LineShapefileMd5.shx =================================================================== diff -u Binary files differ Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryLocationsExporter.cs =================================================================== diff -u --- Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryLocationsExporter.cs (revision 0) +++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryLocationsExporter.cs (revision 718ec8557636bd25dc37b11a836af2e6b3829be6) @@ -0,0 +1,74 @@ +// 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 Core.Common.Base.IO; +using Core.Common.IO.Exceptions; +using Core.Common.Utils; +using log4net; +using Ringtoets.HydraRing.Data; +using Ringtoets.HydraRing.IO.Properties; + +namespace Ringtoets.HydraRing.IO +{ + /// + /// Exports the locations of a and stores them as a shapefile. + /// + public class HydraulicBoundaryLocationsExporter : IFileExporter + { + private static readonly ILog log = LogManager.GetLogger(typeof(HydraulicBoundaryLocationsExporter)); + + private readonly ICollection hydraulicBoundaryLocations; + private readonly string filePath; + + /// + /// Creates a new instance of . + /// + /// The hydraulic boundary locations to export. + /// The path of the file to export to. + /// Thrown when is invalid. + public HydraulicBoundaryLocationsExporter(ICollection hydraulicBoundaryLocations, string filePath) + { + FileUtils.ValidateFilePath(filePath); + + this.hydraulicBoundaryLocations = hydraulicBoundaryLocations; + this.filePath = filePath; + } + + public bool Export() + { + var hydraulicBoundaryLocationsWriter = new HydraulicBoundaryLocationsWriter(); + + try + { + hydraulicBoundaryLocationsWriter.WriteHydraulicBoundaryLocations(hydraulicBoundaryLocations, filePath); + } + catch (CriticalFileWriteException e) + { + log.Error(string.Format(Resources.HydraulicBoundaryLocationsExporter_Error_0_no_HydraulicBoundaryLocations_exported, e.Message)); + return false; + } + + return true; + } + } +} \ No newline at end of file Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryLocationsWriter.cs =================================================================== diff -u --- Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryLocationsWriter.cs (revision 0) +++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/HydraulicBoundaryLocationsWriter.cs (revision 718ec8557636bd25dc37b11a836af2e6b3829be6) @@ -0,0 +1,106 @@ +// 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 Core.Common.Base.Geometry; +using Core.Common.IO.Exceptions; +using Core.Components.Gis.Data; +using Core.Components.Gis.Features; +using Core.Components.Gis.Geometries; +using Core.Components.Gis.IO.Writers; +using Ringtoets.HydraRing.Data; + +namespace Ringtoets.HydraRing.IO +{ + /// + /// Shapefile writer that writes the locations of a as point features. + /// + public class HydraulicBoundaryLocationsWriter + { + /// + /// Writes the locations of a as point features in a shapefile. + /// + /// The hydraulic boundary locations to be written to file. + /// The path to the shapefile. + /// Thrown when or + /// is null. + /// Thrown when is invalid. + /// Thrown when the shapefile cannot be written. + public void WriteHydraulicBoundaryLocations(ICollection hydraulicBoundaryLocations, string filePath) + { + if (hydraulicBoundaryLocations == null) + { + throw new ArgumentNullException("hydraulicBoundaryLocations"); + } + if (filePath == null) + { + throw new ArgumentNullException("filePath"); + } + + var pointShapeFileWriter = new PointShapeFileWriter(); + + foreach (HydraulicBoundaryLocation hydraulicBoundaryLocation in hydraulicBoundaryLocations) + { + var mapLineData = CreateMapPointData(hydraulicBoundaryLocation); + + pointShapeFileWriter.CopyToFeature(mapLineData); + } + + pointShapeFileWriter.SaveAs(filePath); + } + + private MapPointData CreateMapPointData(HydraulicBoundaryLocation hydraulicBoundaryLocation) + { + if (hydraulicBoundaryLocation == null) + { + throw new ArgumentNullException("hydraulicBoundaryLocation"); + } + + MapGeometry hydraulicBoundaryLocationGeometry = new MapGeometry( + new List> + { + new[] + { + hydraulicBoundaryLocation.Location + } + }); + + MapFeature mapFeature = new MapFeature(new[] + { + hydraulicBoundaryLocationGeometry + }); + + mapFeature.MetaData.Add("Naam", hydraulicBoundaryLocation.Name); + mapFeature.MetaData.Add("Id", hydraulicBoundaryLocation.Id); + mapFeature.MetaData.Add("Toetspeil", hydraulicBoundaryLocation.DesignWaterLevel); + mapFeature.MetaData.Add("Hs", hydraulicBoundaryLocation.WaveHeight); + + return new MapPointData(hydraulicBoundaryLocation.Name) + { + Features = new[] + { + mapFeature + } + }; + } + } +} \ No newline at end of file Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/Properties/Resources.Designer.cs =================================================================== diff -u -r733d0d51adf737c52704cd80705507fdb34a2ba3 -r718ec8557636bd25dc37b11a836af2e6b3829be6 --- Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 733d0d51adf737c52704cd80705507fdb34a2ba3) +++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 718ec8557636bd25dc37b11a836af2e6b3829be6) @@ -79,6 +79,16 @@ } /// + /// Looks up a localized string similar to {0}Er zijn geen hydraulische randvoorwaarden locaties geëxporteerd.. + /// + public static string HydraulicBoundaryLocationsExporter_Error_0_no_HydraulicBoundaryLocations_exported { + get { + return ResourceManager.GetString("HydraulicBoundaryLocationsExporter_Error_0_no_HydraulicBoundaryLocations_exported" + + "", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Het bevragen van de database is mislukt.. /// public static string HydraulicLocationConfigurationSqLiteDatabaseReader_Critical_Unexpected_Exception { Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/Properties/Resources.resx =================================================================== diff -u -r733d0d51adf737c52704cd80705507fdb34a2ba3 -r718ec8557636bd25dc37b11a836af2e6b3829be6 --- Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/Properties/Resources.resx (.../Resources.resx) (revision 733d0d51adf737c52704cd80705507fdb34a2ba3) +++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/Properties/Resources.resx (.../Resources.resx) (revision 718ec8557636bd25dc37b11a836af2e6b3829be6) @@ -129,4 +129,7 @@ Het bevragen van de database is mislukt. + + {0}Er zijn geen hydraulische randvoorwaarden locaties geëxporteerd. + \ No newline at end of file Index: Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/Ringtoets.HydraRing.IO.csproj =================================================================== diff -u -r2cf2214c4069c98c3cb21708729fcbc2ca964ab6 -r718ec8557636bd25dc37b11a836af2e6b3829be6 --- Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/Ringtoets.HydraRing.IO.csproj (.../Ringtoets.HydraRing.IO.csproj) (revision 2cf2214c4069c98c3cb21708729fcbc2ca964ab6) +++ Ringtoets/HydraRing/src/Ringtoets.HydraRing.IO/Ringtoets.HydraRing.IO.csproj (.../Ringtoets.HydraRing.IO.csproj) (revision 718ec8557636bd25dc37b11a836af2e6b3829be6) @@ -58,6 +58,8 @@ + + @@ -96,6 +98,14 @@ Core.Common.Version False + + {FD264FAD-E6F9-47CC-97CD-770199A8E629} + Core.Components.Gis.IO + + + {318BA582-88C9-4816-A54A-A7E431461DE3} + Core.Components.Gis + {70F8CC9C-5BC8-4FB2-B201-EAE7FA8088C2} Ringtoets.HydraRing.Data Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryLocationsExporterTest.cs =================================================================== diff -u --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryLocationsExporterTest.cs (revision 0) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryLocationsExporterTest.cs (revision 718ec8557636bd25dc37b11a836af2e6b3829be6) @@ -0,0 +1,139 @@ +// 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.IO; +using System.Security.AccessControl; +using Core.Common.Base.IO; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.HydraRing.Data; + +namespace Ringtoets.HydraRing.IO.Test +{ + public class HydraulicBoundaryLocationsExporterTest + { + [Test] + public void ParameteredConstructor_ValidParameters_ExpectedValues() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(123, "aName", 1.1, 2.2) + { + DesignWaterLevel = 111.111, + WaveHeight = 222.222 + }; + + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.IO, "test.shp"); + + // Call + var hydraulicBoundaryLocationsExporter = new HydraulicBoundaryLocationsExporter(new[] { hydraulicBoundaryLocation }, filePath); + + // Assert + Assert.IsInstanceOf(hydraulicBoundaryLocationsExporter); + } + + [Test] + public void ParameteredConstructor_NullFilePath_ThrowArgumentException() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(123, "aName", 1.1, 2.2) + { + DesignWaterLevel = 111.111, + WaveHeight = 222.222 + }; + + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.IO, "test.shp"); + + // Call + TestDelegate call = () => new HydraulicBoundaryLocationsExporter(new[] { hydraulicBoundaryLocation }, null); + + // Assert + Assert.Throws(call); + } + + [Test] + public void Export_ValidData_ReturnTrue() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(123, "aName", 1.1, 2.2) + { + DesignWaterLevel = 111.111, + WaveHeight = 222.222 + }; + + string directoryPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.IO, + "Export_ValidData_ReturnTrue"); + Directory.CreateDirectory(directoryPath); + string filePath = Path.Combine(directoryPath, "test.shp"); + + var exporter = new HydraulicBoundaryLocationsExporter(new[] { hydraulicBoundaryLocation }, filePath); + + bool isExported; + try + { + // Call + isExported = exporter.Export(); + } + finally + { + Directory.Delete(directoryPath, true); + } + + // Assert + Assert.IsTrue(isExported); + } + + [Test] + public void Export_InvalidDirectoryRights_LogErrorAndReturnFalse() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(123, "aName", 1.1, 2.2) + { + DesignWaterLevel = 111.111, + WaveHeight = 222.222 + }; + + string directoryPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.IO, + "Export_InvalidDirectoryRights_LogErrorAndReturnFalse"); + Directory.CreateDirectory(directoryPath); + string filePath = Path.Combine(directoryPath, "test.shp"); + + var exporter = new HydraulicBoundaryLocationsExporter(new[] { hydraulicBoundaryLocation }, filePath); + + bool isExported = true; + try + { + using (new DirectoryPermissionsRevoker(directoryPath, FileSystemRights.Write)) + { + // Call + isExported = exporter.Export(); + } + } + finally + { + Directory.Delete(directoryPath, true); + } + + // Assert + Assert.IsFalse(isExported); + } + } +} \ No newline at end of file Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryLocationsWriterTest.cs =================================================================== diff -u --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryLocationsWriterTest.cs (revision 0) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/HydraulicBoundaryLocationsWriterTest.cs (revision 718ec8557636bd25dc37b11a836af2e6b3829be6) @@ -0,0 +1,130 @@ +// 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.IO; +using System.Linq; +using System.Security.Cryptography; +using Core.Common.TestUtil; +using NUnit.Framework; +using Ringtoets.HydraRing.Data; + +namespace Ringtoets.HydraRing.IO.Test +{ + [TestFixture] + public class HydraulicBoundaryLocationsWriterTest + { + [Test] + public void WriteHydraulicBoundaryLocations_NullhydraulicBoundaryLocations_ThrowArgumentNullException() + { + // Setup + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.IO, + Path.Combine("WriteHydraulicBoundaryLocations_NullhydraulicBoundaryLocations_ThrowArgumentNullException", + "test.shp")); + + var writer = new HydraulicBoundaryLocationsWriter(); + + // Call + TestDelegate call = () => writer.WriteHydraulicBoundaryLocations(null, filePath); + + // Assert + Assert.Throws(call); + } + + [Test] + public void WriteHydraulicBoundaryLocations_NullFilePath_ThrowArgumentNullException() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(123, "aName", 1.1, 2.2); + + var writer = new HydraulicBoundaryLocationsWriter(); + + // Call + TestDelegate call = () => writer.WriteHydraulicBoundaryLocations(new[] { hydraulicBoundaryLocation }, null); + + // Assert + Assert.Throws(call); + } + + [Test] + public void WriteHydraulicBoundaryLocations_ValidData_WritesShapeFile() + { + // Setup + var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(123, "aName", 1.1, 2.2) + { + DesignWaterLevel = 111.111, + WaveHeight = 222.222 + }; + + string directoryPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.IO, + "WriteHydraulicBoundaryLocations_ValidData_WritesShapeFile"); + Directory.CreateDirectory(directoryPath); + string filePath = Path.Combine(directoryPath, "test.shp"); + var baseName = "test"; + + var writer = new HydraulicBoundaryLocationsWriter(); + + // Precondition + AssertEssentialShapefileExists(directoryPath, baseName, false); + + // Call + try + { + writer.WriteHydraulicBoundaryLocations(new[] { hydraulicBoundaryLocation }, filePath); + + // Assert + AssertEssentialShapefileExists(directoryPath, baseName, true); + AssertEssentialShapefileMd5Hashes(directoryPath, baseName); + } + finally + { + Directory.Delete(directoryPath, true); + } + } + + private static void AssertEssentialShapefileExists(string directoryPath, string baseName, bool shouldExist) + { + string pathName = Path.Combine(directoryPath, baseName); + Assert.AreEqual(shouldExist, File.Exists(pathName + ".shp")); + Assert.AreEqual(shouldExist, File.Exists(pathName + ".shx")); + Assert.AreEqual(shouldExist, File.Exists(pathName + ".dbf")); + } + + private void AssertEssentialShapefileMd5Hashes(string directoryPath, string baseName) + { + string refPathName = Path.Combine(TestHelper.GetTestDataPath(TestDataPath.Ringtoets.HydraRing.IO), "PointShapefileMd5"); + string pathName = Path.Combine(directoryPath, baseName); + + AssertBinaryFileContent(refPathName, pathName, ".shp", 100, 28); + AssertBinaryFileContent(refPathName, pathName, ".shx", 100, 8); + AssertBinaryFileContent(refPathName, pathName, ".dbf", 32, 441); + } + + private static void AssertBinaryFileContent(string refPathName, string pathName, string extension, int headerLength, int bodyLength) + { + var refContent = File.ReadAllBytes(refPathName + extension); + var content = File.ReadAllBytes(pathName + extension); + Assert.AreEqual(headerLength + bodyLength, content.Length); + Assert.AreEqual(refContent.Skip(headerLength).Take(bodyLength), + content.Skip(headerLength).Take(bodyLength)); + } + } +} \ No newline at end of file Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/Ringtoets.HydraRing.IO.Test.csproj =================================================================== diff -u -r8476d48f3aa0d36c866433c29be238aa52abcfe4 -r718ec8557636bd25dc37b11a836af2e6b3829be6 --- Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/Ringtoets.HydraRing.IO.Test.csproj (.../Ringtoets.HydraRing.IO.Test.csproj) (revision 8476d48f3aa0d36c866433c29be238aa52abcfe4) +++ Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/Ringtoets.HydraRing.IO.Test.csproj (.../Ringtoets.HydraRing.IO.Test.csproj) (revision 718ec8557636bd25dc37b11a836af2e6b3829be6) @@ -56,6 +56,8 @@ + + Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/test-data/PointShapefileMd5.dbf =================================================================== diff -u Binary files differ Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/test-data/PointShapefileMd5.shp =================================================================== diff -u Binary files differ Index: Ringtoets/HydraRing/test/Ringtoets.HydraRing.IO.Test/test-data/PointShapefileMd5.shx =================================================================== diff -u Binary files differ Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs =================================================================== diff -u -r27014b59b58198c1ff843949292fcbe4f60f6916 -r718ec8557636bd25dc37b11a836af2e6b3829be6 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 27014b59b58198c1ff843949292fcbe4f60f6916) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 718ec8557636bd25dc37b11a836af2e6b3829be6) @@ -368,6 +368,13 @@ IsEnabled = context => context.WrappedData.ReferenceLine != null, FileFilter = string.Format(RingtoetsCommonIoResources.DataTypeDisplayName_0_shape_file_filter, "Referentielijn") }; + + yield return new ExportInfo + { + CreateFileExporter = (context, filePath) => new HydraulicBoundaryLocationsExporter(context.WrappedData.HydraulicBoundaryDatabase.Locations, filePath), + IsEnabled = context => context.WrappedData.HydraulicBoundaryDatabase != null, + FileFilter = string.Format(RingtoetsCommonIoResources.DataTypeDisplayName_0_shape_file_filter, "Hydraulische randvoorwaarden") + }; } /// @@ -1101,6 +1108,7 @@ return Gui.Get(nodeData, treeViewControl) .AddCustomItem(connectionItem) + .AddExportItem() .AddSeparator() .AddExpandAllItem() .AddCollapseAllItem() Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/HydraulicBoundaryDatabaseContextTreeNodeInfoTest.cs =================================================================== diff -u -r890e0dbb7d3989a8dfdfb64be99c2031b46bccf2 -r718ec8557636bd25dc37b11a836af2e6b3829be6 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/HydraulicBoundaryDatabaseContextTreeNodeInfoTest.cs (.../HydraulicBoundaryDatabaseContextTreeNodeInfoTest.cs) (revision 890e0dbb7d3989a8dfdfb64be99c2031b46bccf2) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/HydraulicBoundaryDatabaseContextTreeNodeInfoTest.cs (.../HydraulicBoundaryDatabaseContextTreeNodeInfoTest.cs) (revision 718ec8557636bd25dc37b11a836af2e6b3829be6) @@ -134,6 +134,7 @@ var nodeData = new HydraulicBoundaryDatabaseContext(assessmentSectionMock); menuBuilderMock.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilderMock); + menuBuilderMock.Expect(mb => mb.AddExportItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddSeparator()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilderMock); menuBuilderMock.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilderMock); Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs =================================================================== diff -u -r27014b59b58198c1ff843949292fcbe4f60f6916 -r718ec8557636bd25dc37b11a836af2e6b3829be6 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs (.../RingtoetsPluginTest.cs) (revision 27014b59b58198c1ff843949292fcbe4f60f6916) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs (.../RingtoetsPluginTest.cs) (revision 718ec8557636bd25dc37b11a836af2e6b3829be6) @@ -264,9 +264,11 @@ ExportInfo[] exportInfos = plugin.GetExportInfos().ToArray(); // Assert - Assert.AreEqual(1, exportInfos.Length); + Assert.AreEqual(2, exportInfos.Length); var referenceLineExportInfo = exportInfos.Single(ei => ei.DataType == typeof(ReferenceLineContext)); Assert.AreEqual("Referentielijn shapebestand (*.shp)|*.shp", referenceLineExportInfo.FileFilter); + var hydraulicBoundaryExportInfo = exportInfos.Single(ei => ei.DataType == typeof(HydraulicBoundaryDatabaseContext)); + Assert.AreEqual("Hydraulische randvoorwaarden shapebestand (*.shp)|*.shp", hydraulicBoundaryExportInfo.FileFilter); } }