// 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.Data; using System.Data.SQLite; using Core.Common.Base.IO; using Core.Common.IO.Readers; using Core.Common.Utils.Builders; using Ringtoets.Piping.IO.Builders; using Ringtoets.Piping.IO.Properties; using Ringtoets.Piping.IO.SoilProfile.Schema; namespace Ringtoets.Piping.IO.SoilProfile { /// /// This class reads a soil database file and reads version from this database. /// public class SoilDatabaseVersionReader : SqLiteDatabaseReaderBase { private const string databaseRequiredVersion = "15.0.6.0"; /// /// Creates a new instance of , /// which will use the as its source. /// /// The path of the database file to open. /// Thrown when: /// The contains invalid characters. /// No file could be found at . /// The database version could not be read. /// The database version is incorrect. /// public SoilDatabaseVersionReader(string databaseFilePath) : base(databaseFilePath) {} /// /// Verifies if the database has the required version. /// /// Thrown when: /// The database version could not be read. /// The database version is incorrect. /// public void VerifyVersion() { string checkVersionQuery = SoilDatabaseQueryBuilder.GetCheckVersionQuery(); var sqliteParameter = new SQLiteParameter { DbType = DbType.String, ParameterName = $"@{MetaDataTableColumns.Value}", Value = databaseRequiredVersion }; try { ReadVersion(checkVersionQuery, sqliteParameter); } catch (SQLiteException exception) { string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.PipingSoilProfileReader_Critical_Unexpected_value_on_column); throw new CriticalFileReadException(message, exception); } } private void ReadVersion(string checkVersionQuery, SQLiteParameter sqliteParameter) { using (IDataReader dataReader = CreateDataReader(checkVersionQuery, sqliteParameter)) { if (!dataReader.Read()) { throw new CriticalFileReadException(string.Format( Resources.PipingSoilProfileReader_Database_incorrect_version_requires_Version_0_, databaseRequiredVersion)); } } } } }