Index: Core/Common/src/Core.Common.Base/Properties/Resources.Designer.cs
===================================================================
diff -u -rdd7a5cfb0343fa2350b4143232b94cbba37612e9 -reb0fa1ad33501642b7cd6c7639155f9f83fd50b4
--- Core/Common/src/Core.Common.Base/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision dd7a5cfb0343fa2350b4143232b94cbba37612e9)
+++ Core/Common/src/Core.Common.Base/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision eb0fa1ad33501642b7cd6c7639155f9f83fd50b4)
@@ -141,5 +141,23 @@
return ResourceManager.GetString("ReferenceLine_SetGeometry_New_geometry_has_null_coordinate", resourceCulture);
}
}
+
+ ///
+ /// Looks up a localized string similar to Bestand bevat 1 multi-polylijn, welke niet ondersteund is..
+ ///
+ public static string ReferenceLineReader_File_contains_unsupported_multi_polyline {
+ get {
+ return ResourceManager.GetString("ReferenceLineReader_File_contains_unsupported_multi_polyline", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Bestand moet exact 1 gehele polylijn bevatten..
+ ///
+ public static string ReferenceLineReader_File_must_contain_1_polyline {
+ get {
+ return ResourceManager.GetString("ReferenceLineReader_File_must_contain_1_polyline", resourceCulture);
+ }
+ }
}
}
Index: Core/Common/src/Core.Common.Base/Properties/Resources.resx
===================================================================
diff -u -rdd7a5cfb0343fa2350b4143232b94cbba37612e9 -reb0fa1ad33501642b7cd6c7639155f9f83fd50b4
--- Core/Common/src/Core.Common.Base/Properties/Resources.resx (.../Resources.resx) (revision dd7a5cfb0343fa2350b4143232b94cbba37612e9)
+++ Core/Common/src/Core.Common.Base/Properties/Resources.resx (.../Resources.resx) (revision eb0fa1ad33501642b7cd6c7639155f9f83fd50b4)
@@ -144,4 +144,10 @@
Een punt in de geometrie voor de referentielijn heeft geen waarde.
+
+ Bestand moet exact 1 gehele polylijn bevatten.
+
+
+ Bestand bevat 1 multi-polylijn, welke niet ondersteund is.
+
\ No newline at end of file
Index: Core/Components/test/Core.Components.Gis.IO.Test/PolylineShapeFileReaderTest.cs
===================================================================
diff -u -rcd709418712e8fa50e2e8a0da0e2488139ac9054 -reb0fa1ad33501642b7cd6c7639155f9f83fd50b4
--- Core/Components/test/Core.Components.Gis.IO.Test/PolylineShapeFileReaderTest.cs (.../PolylineShapeFileReaderTest.cs) (revision cd709418712e8fa50e2e8a0da0e2488139ac9054)
+++ Core/Components/test/Core.Components.Gis.IO.Test/PolylineShapeFileReaderTest.cs (.../PolylineShapeFileReaderTest.cs) (revision eb0fa1ad33501642b7cd6c7639155f9f83fd50b4)
@@ -94,6 +94,27 @@
}
[Test]
+ [TestCase("Single_Point_with_ID.shp")]
+ [TestCase("Multiple_Point_with_ID.shp")]
+ [TestCase("Single_Multi-Polygon_with_ID.shp")]
+ [TestCase("Multiple_Polygon_with_ID.shp")]
+ public void ParameteredConstructor_ShapeFileIsNotLinesShapesfile_ThrowCriticalFileReadException(string shapeFileName)
+ {
+ // Setup
+ string nonLineShapeFile = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO,
+ shapeFileName);
+
+ // Call
+ TestDelegate call = () => new PolylineShapeFileReader(nonLineShapeFile);
+
+ // Assert
+ var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Bestand bevat geometrieën die geen lijn zijn.",
+ nonLineShapeFile);
+ var message = Assert.Throws(call).Message;
+ Assert.AreEqual(expectedMessage, message);
+ }
+
+ [Test]
public void GetNumberOfLines_EmptyLineShapeFile_ReturnZero()
{
// Setup
@@ -263,31 +284,10 @@
}
[Test]
- [TestCase("Single_Point_with_ID.shp")]
- [TestCase("Multiple_Point_with_ID.shp")]
- [TestCase("Single_Multi-Polygon_with_ID.shp")]
- [TestCase("Multiple_Polygon_with_ID.shp")]
- public void ParameteredConstructor_ShapeFileIsNotLinesShapesfile_ThrowCriticalFileReadException(string shapeFileName)
+ public void ReadLine_ShapeFileIsIsMultiLine_ThrowCriticalFileReadException()
{
// Setup
string nonLineShapeFile = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO,
- shapeFileName);
-
- // Call
- TestDelegate call = () => new PolylineShapeFileReader(nonLineShapeFile);
-
- // Assert
- var expectedMessage = string.Format("Fout bij het lezen van bestand '{0}': Bestand bevat geometrieën die geen lijn zijn.",
- nonLineShapeFile);
- var message = Assert.Throws(call).Message;
- Assert.AreEqual(expectedMessage, message);
- }
-
- [Test]
- public void ParameteredConstructor_ShapeFileIsIsMultiLine_ThrowCriticalFileReadException()
- {
- // Setup
- string nonLineShapeFile = TestHelper.GetTestDataPath(TestDataPath.Core.Components.Gis.IO,
"Single_Multi-PolyLine_with_ID.shp");
var reader = new PolylineShapeFileReader(nonLineShapeFile);
Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.Designer.cs (revision eb0fa1ad33501642b7cd6c7639155f9f83fd50b4)
@@ -0,0 +1,63 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.18444
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace Ringtoets.Common.IO.Properties {
+ using System;
+
+
+ ///
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ ///
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources() {
+ }
+
+ ///
+ /// Returns the cached ResourceManager instance used by this class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Ringtoets.Common.IO.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ ///
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+ }
+}
Index: Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx
===================================================================
diff -u
--- Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (revision 0)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/Properties/Resources.resx (revision eb0fa1ad33501642b7cd6c7639155f9f83fd50b4)
@@ -0,0 +1,101 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 1.3
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLineReader.cs
===================================================================
diff -u -rcd709418712e8fa50e2e8a0da0e2488139ac9054 -reb0fa1ad33501642b7cd6c7639155f9f83fd50b4
--- Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLineReader.cs (.../ReferenceLineReader.cs) (revision cd709418712e8fa50e2e8a0da0e2488139ac9054)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/ReferenceLineReader.cs (.../ReferenceLineReader.cs) (revision eb0fa1ad33501642b7cd6c7639155f9f83fd50b4)
@@ -20,14 +20,21 @@
// All rights reserved.
using System;
+using System.IO;
using System.Linq;
using Core.Common.Base.Geometry;
+using Core.Common.Base.Properties;
+using Core.Common.IO.Exceptions;
+using Core.Common.Utils;
+using Core.Common.Utils.Builders;
using Core.Components.Gis.Data;
using Core.Components.Gis.IO;
using Ringtoets.Common.Data;
+using CoreCommonUtilsResources = Core.Common.Utils.Properties.Resources;
+
namespace Ringtoets.Common.IO
{
///
@@ -42,17 +49,89 @@
/// The filepath to the shape file.
/// The reference line created from the data in the shape file.
/// When is invalid.
+ /// When either:
+ ///
+ /// - points to a file that does not exist.
+ /// - There isn't exactly 1 polyline in the shapefile.
+ /// - Shapefile contains a multi-polyline.
+ ///
+ ///
public ReferenceLine ReadReferenceLine(string shapeFilePath)
{
- using (var lineShapeReader = new PolylineShapeFileReader(shapeFilePath))
+ FileUtils.ValidateFilePath(shapeFilePath);
+ if (!File.Exists(shapeFilePath))
{
- MapLineData lineMapData = lineShapeReader.ReadLine();
+ string message = new FileReaderErrorMessageBuilder(shapeFilePath)
+ .Build(CoreCommonUtilsResources.Error_File_does_not_exist);
+ throw new CriticalFileReadException(message);
+ }
- var referenceLine = new ReferenceLine();
- referenceLine.SetGeometry(lineMapData.Points.Select(t => new Point2D(t.Item1, t.Item2)));
+ using (PolylineShapeFileReader lineShapeReader = OpenPolyLineShapeFile(shapeFilePath))
+ {
+ var lineMapData = GetReferenceLineMapData(lineShapeReader, shapeFilePath);
+ return CreateReferenceLine(lineMapData);
+ }
+ }
- return referenceLine;
+ ///
+ /// Opens the poly line shape file.
+ ///
+ /// The shape file path.
+ /// The reader that can be used to read the shape file.
+ /// When shape file does not have line geometries.
+ private static PolylineShapeFileReader OpenPolyLineShapeFile(string shapeFilePath)
+ {
+ try
+ {
+ return new PolylineShapeFileReader(shapeFilePath);
}
+ catch (CriticalFileReadException e)
+ {
+ string message = new FileReaderErrorMessageBuilder(shapeFilePath)
+ .Build(Resources.ReferenceLineReader_File_must_contain_1_polyline);
+ throw new CriticalFileReadException(message, e);
+ }
}
+
+ ///
+ /// Gets the reference line map data.
+ ///
+ /// The line shape reader.
+ /// The shape file path.
+ ///
+ ///
+ /// When either:
+ ///
+ /// - There isn't exactly 1 polyline in the shapefile.
+ /// - Shapefile contains a multi-polyline.
+ ///
+ ///
+ private static MapLineData GetReferenceLineMapData(PolylineShapeFileReader lineShapeReader, string shapeFilePath)
+ {
+ if (lineShapeReader.GetNumberOfLines() != 1)
+ {
+ string message = new FileReaderErrorMessageBuilder(shapeFilePath)
+ .Build(Resources.ReferenceLineReader_File_must_contain_1_polyline);
+ throw new CriticalFileReadException(message);
+ }
+
+ try
+ {
+ return lineShapeReader.ReadLine();
+ }
+ catch (ElementReadException e)
+ {
+ string message = new FileReaderErrorMessageBuilder(shapeFilePath)
+ .Build(Resources.ReferenceLineReader_File_contains_unsupported_multi_polyline);
+ throw new CriticalFileReadException(message, e);
+ }
+ }
+
+ private static ReferenceLine CreateReferenceLine(MapLineData lineMapData)
+ {
+ var referenceLine = new ReferenceLine();
+ referenceLine.SetGeometry(lineMapData.Points.Select(t => new Point2D(t.Item1, t.Item2)));
+ return referenceLine;
+ }
}
}
\ No newline at end of file
Index: Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj
===================================================================
diff -u -ra96a27081bc12d581a196160abc92854a11ec1c6 -reb0fa1ad33501642b7cd6c7639155f9f83fd50b4
--- Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision a96a27081bc12d581a196160abc92854a11ec1c6)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/Ringtoets.Common.IO.csproj (.../Ringtoets.Common.IO.csproj) (revision eb0fa1ad33501642b7cd6c7639155f9f83fd50b4)
@@ -42,6 +42,11 @@
Properties\GlobalAssembly.cs
+
+ True
+ True
+ Resources.resx
+
@@ -54,6 +59,14 @@
{3bbfd65b-b277-4e50-ae6d-bd24c3434609}
Core.Common.Base
+
+ {e344867e-9ac9-44c8-88a5-8185681679a9}
+ Core.Common.IO
+
+
+ {f49bd8b2-332a-4c91-a196-8cce0a2c7d98}
+ Core.Common.Utils
+
{c90b77da-e421-43cc-b82e-529651bc21ac}
Core.Common.Version
@@ -71,6 +84,12 @@
Ringtoets.Common.Data
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+
+