Index: Riskeer/HydraRing/src/Riskeer.HydraRing.IO/HydraulicBoundaryDatabase/LocationsFileReader.cs
===================================================================
diff -u -r3458412302e1bee553ff71cd2fc8744d049dd370 -r7962fccfb455ceb43058f1812f3a2ea1fe53a97a
--- Riskeer/HydraRing/src/Riskeer.HydraRing.IO/HydraulicBoundaryDatabase/LocationsFileReader.cs (.../LocationsFileReader.cs) (revision 3458412302e1bee553ff71cd2fc8744d049dd370)
+++ Riskeer/HydraRing/src/Riskeer.HydraRing.IO/HydraulicBoundaryDatabase/LocationsFileReader.cs (.../LocationsFileReader.cs) (revision 7962fccfb455ceb43058f1812f3a2ea1fe53a97a)
@@ -24,6 +24,8 @@
using Core.Common.Base.IO;
using Core.Common.IO.Exceptions;
using Core.Common.IO.Readers;
+using Core.Common.Util.Builders;
+using Riskeer.HydraRing.IO.Properties;
namespace Riskeer.HydraRing.IO.HydraulicBoundaryDatabase
{
@@ -35,11 +37,11 @@
///
/// Creates a new instance of .
///
- /// The path of the locations file to open.
+ /// The path of the locations file to read.
/// Thrown when:
///
- /// - The contains invalid characters.
- /// - No file could be found at .
+ /// - the contains invalid characters;
+ /// - no file could be found at .
///
///
public LocationsFileReader(string databaseFilePath) : base(databaseFilePath) {}
@@ -50,23 +52,37 @@
/// Thrown when the database contains incorrect values for required properties.
public IEnumerable ReadLocations()
{
- using (IDataReader reader = CreateDataReader(GetLocationsQuery()))
+ using (IDataReader reader = CreateDataReader("SELECT L.LocationId, L.Segment, T.HRDFileName " +
+ "FROM Locations L " +
+ "INNER JOIN Tracks T USING(TrackId) " +
+ "WHERE L.TypeOfHydraulicDataId > 1;"))
{
while (MoveNext(reader))
{
- yield return new ReadLocation(reader.Read("LocationId"),
- reader.Read("Segment"),
- reader.Read("HRDFileName"));
+ yield return ReadLocation(reader);
}
}
}
- private static string GetLocationsQuery()
+ ///
+ /// Reads a location from the database.
+ ///
+ /// A based on the data read from the database.
+ /// Thrown when the database contains incorrect values for required properties.
+ private ReadLocation ReadLocation(IDataReader reader)
{
- return "SELECT L.LocationId, L.Segment, T.HRDFileName " +
- "FROM Locations L " +
- "INNER JOIN Tracks T USING(TrackId) " +
- "WHERE L.TypeOfHydraulicDataId > 1;"; // Value > 1 makes it relevant
+ try
+ {
+ return new ReadLocation(reader.Read("LocationId"),
+ reader.Read("Segment"),
+ reader.Read("HRDFileName"));
+ }
+ catch (ConversionException e)
+ {
+ throw new LineParseException(
+ new FileReaderErrorMessageBuilder(Path).Build(Resources.HydraulicBoundaryDatabaseReader_Critical_Unexpected_value_on_column),
+ e);
+ }
}
}
-}
+}
\ No newline at end of file