Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new <see cref="SQLiteDataReader"/>.
        /// </summary>
        /// <exception cref="CriticalFileReadException">Thrown when the query to fetch stochastic soil
        /// model segment points from the database failed.</exception>
        private void CreateDataReader()
        {
            string stochasticSoilModelSegmentsQuery = SoilDatabaseQueryBuilder.GetSegmentPointsQuery();

            try
            {
                dataReader = CreateDataReader(stochasticSoilModelSegmentsQuery);
            }
            catch (SQLiteException exception)
            {
                string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.StochasticSoilModelDatabaseReader_Failed_to_read_database);
                throw new CriticalFileReadException(message, exception);
            }
        }
Ejemplo n.º 2
0
        private void PrepareReader()
        {
            string soilProfile1DQuery = SoilDatabaseQueryBuilder.GetSoilProfile1DQuery();

            try
            {
                dataReader = CreateDataReader(soilProfile1DQuery);
            }
            catch (SQLiteException exception)
            {
                string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.SoilProfileReader_Error_reading_soil_profile_from_database);
                throw new CriticalFileReadException(message, exception);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a new <see cref="IDataReader"/>.
        /// </summary>
        /// <exception cref="CriticalFileReadException">Thrown when the query to fetch
        /// preconsolidation stresses from the database failed.</exception>
        private void CreateReader()
        {
            string soilProfile2DPreconsolidationStressesQuery =
                SoilDatabaseQueryBuilder.GetSoilProfile2DPreconsolidationStressesQuery();

            try
            {
                dataReader = CreateDataReader(soilProfile2DPreconsolidationStressesQuery);
            }
            catch (SQLiteException exception)
            {
                string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.PreconsolidationStressReader_Failed_to_read_database);
                throw new CriticalFileReadException(message, exception);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a new <see cref="SQLiteDataReader"/>.
        /// </summary>
        /// <exception cref="CriticalFileReadException">Thrown when query to fetch stochastic soil
        /// models from the database failed.</exception>
        private void CreateDataReader()
        {
            string stochasticSoilModelCount         = SoilDatabaseQueryBuilder.GetStochasticSoilModelOfMechanismCountQuery();
            string stochasticSoilModelSegmentsQuery = SoilDatabaseQueryBuilder.GetStochasticSoilModelPerMechanismQuery();

            try
            {
                dataReader = CreateDataReader(stochasticSoilModelCount + stochasticSoilModelSegmentsQuery);
            }
            catch (SQLiteException exception)
            {
                string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.StochasticSoilModelDatabaseReader_Failed_to_read_database);
                throw new CriticalFileReadException(message, exception);
            }

            StochasticSoilModelCount = ReadStochasticSoilModelCount();
            dataReader.NextResult();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Verifies that the probabilities in the database are valid.
        /// </summary>
        /// <exception cref="SQLiteException">Thrown when the execution the query failed.</exception>
        /// <exception cref="CriticalFileReadException">Thrown when:
        /// <list type="bullet">
        /// <item>The probabilities could not be read;</item>
        /// <item>One or more probabilities are not valid.</item>
        /// </list>
        /// </exception>
        /// <remarks>A valid probability:
        /// <list type="bullet">
        /// <item>has a value in the interval [0.0, 1.0];</item>
        /// <item>is not <c>null</c>.</item>
        /// </list>
        /// </remarks>
        private void ReadAllProbabilitiesValid()
        {
            string checkSegmentNameUniqueness = SoilDatabaseQueryBuilder.GetStochasticSoilProfileProbabilitiesValidQuery();

            using (IDataReader dataReader = CreateDataReader(checkSegmentNameUniqueness))
            {
                if (!dataReader.Read())
                {
                    throw new CriticalFileReadException(
                              BuildMessageWithPath(Resources.SoilDatabaseConstraintsReader_VerifyConstraints_Unexpected_error_while_verifying_valid_StochasticSoilProfile_probability));
                }

                if (!Convert.ToBoolean(dataReader[StochasticSoilProfileTableDefinitions.AllProbabilitiesValid]))
                {
                    throw new CriticalFileReadException(
                              BuildMessageWithPath(Resources.SoilDatabaseConstraintsReader_VerifyConstraints_Invalid_StochasticSoilProfile_probability));
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Verifies that the segments in the database are unique.
        /// </summary>
        /// <exception cref="SQLiteException">Thrown when the execution the query failed.</exception>
        /// <exception cref="CriticalFileReadException">Thrown when:
        /// <list type="bullet">
        /// <item>The database segments could not be read;</item>
        /// <item>The database segments are not unique.</item>
        /// </list>
        /// </exception>
        private void ReadUniqueSegements()
        {
            string query = SoilDatabaseQueryBuilder.GetSoilModelNamesUniqueQuery();

            using (IDataReader dataReader = CreateDataReader(query))
            {
                if (!dataReader.Read())
                {
                    throw new CriticalFileReadException(
                              BuildMessageWithPath(Resources.SoilDatabaseConstraintsReader_VerifyConstraints_Unexpected_error_while_verifying_unique_StochasticSoilModel_names));
                }

                if (!Convert.ToBoolean(dataReader[StochasticSoilModelTableDefinitions.AreSegmentsUnique]))
                {
                    throw new CriticalFileReadException(
                              BuildMessageWithPath(Resources.SoilDatabaseConstraintsReader_VerifyConstraints_Non_unique_StochasticSoilModel_names));
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Verifies if the database has the required version.
        /// </summary>
        /// <exception cref="CriticalFileReadException">Thrown when:
        /// <list type="bullet">
        /// <item>The database version could not be read.</item>
        /// <item>The database version is incorrect.</item>
        /// </list>
        /// </exception>
        public void VerifyVersion()
        {
            string checkVersionQuery = SoilDatabaseQueryBuilder.GetCheckVersionQuery();
            var    sqliteParameter   = new SQLiteParameter
            {
                DbType        = DbType.String,
                ParameterName = $"@{MetaTableDefinitions.Value}",
                Value         = databaseRequiredVersion
            };

            try
            {
                ReadVersion(checkVersionQuery, sqliteParameter);
            }
            catch (SQLiteException exception)
            {
                string exceptionMessage = new FileReaderErrorMessageBuilder(Path).Build(
                    Resources.SoilProfileReader_Critical_Unexpected_value_on_column);
                throw new CriticalFileReadException(exceptionMessage, exception);
            }
        }