Index: Riskeer/HydraRing/src/Riskeer.HydraRing.IO/HydraulicBoundaryDatabase/HrdFileReader.cs =================================================================== diff -u --- Riskeer/HydraRing/src/Riskeer.HydraRing.IO/HydraulicBoundaryDatabase/HrdFileReader.cs (revision 0) +++ Riskeer/HydraRing/src/Riskeer.HydraRing.IO/HydraulicBoundaryDatabase/HrdFileReader.cs (revision d088ed9e249c27cf431b4bfe8bd88eab30cc18cc) @@ -0,0 +1,101 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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.Data; +using System.Data.SQLite; +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 +{ + /// + /// Class for reading a HRD file. + /// + public class HrdFileReader : SqLiteDatabaseReaderBase + { + /// + /// Creates a new instance of . + /// + /// The path of the HRD file to read. + /// Thrown when: + /// + /// the contains invalid characters; + /// no file could be found at . + /// + /// + public HrdFileReader(string databaseFilePath) : base(databaseFilePath) {} + + /// + /// Reads the HRD locations from the database. + /// + /// Thrown when the database has an unsupported structure. + /// Thrown when the database contains incorrect values for required properties. + public IEnumerable ReadHrdLocations() + { + var readHrdLocations = new List(); + + try + { + 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)) + { + readHrdLocations.Add(ReadHrdLocation(reader)); + } + + return readHrdLocations; + } + } + catch (SQLiteException e) + { + throw new CriticalFileReadException( + new FileReaderErrorMessageBuilder(Path).Build(Resources.HydraulicBoundaryDatabase_Unknown_database_structure), + e); + } + } + + /// + /// Reads a HRD location from the database. + /// + /// A based on the data read from the database. + /// Thrown when the database contains incorrect values for required properties. + private ReadHrdLocation ReadHrdLocation(IDataReader reader) + { + try + { + return new ReadHrdLocation(reader.Read("LocationId")); + } + catch (ConversionException e) + { + throw new LineParseException( + new FileReaderErrorMessageBuilder(Path).Build(Resources.HydraulicBoundaryDatabase_Unexpected_value_on_column), + e); + } + } + } +} \ No newline at end of file Index: Riskeer/HydraRing/src/Riskeer.HydraRing.IO/HydraulicBoundaryDatabase/ReadHrdLocation.cs =================================================================== diff -u --- Riskeer/HydraRing/src/Riskeer.HydraRing.IO/HydraulicBoundaryDatabase/ReadHrdLocation.cs (revision 0) +++ Riskeer/HydraRing/src/Riskeer.HydraRing.IO/HydraulicBoundaryDatabase/ReadHrdLocation.cs (revision d088ed9e249c27cf431b4bfe8bd88eab30cc18cc) @@ -0,0 +1,43 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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. + +namespace Riskeer.HydraRing.IO.HydraulicBoundaryDatabase +{ + /// + /// Container for location data that is read from a HRD file. + /// + public class ReadHrdLocation + { + /// + /// Creates a new instance of . + /// + /// The database id of the read HRD location. + public ReadHrdLocation(long locationId) + { + LocationId = locationId; + } + + /// + /// Gets the database id of the read HRD location. + /// + public long LocationId { get; } + } +} \ No newline at end of file