/// <summary> /// Gets the location ids from the database, based upon <paramref name="trackParameter"/>. /// </summary> /// <param name="trackParameter">A parameter containing the hydraulic boundary track id.</param> /// <returns>A collection of <see cref="ReadHydraulicLocationMapping"/> as found in the database.</returns> /// <exception cref="SQLiteException">Thrown when the database query failed.</exception> /// <exception cref="InvalidCastException">Thrown when the database returned incorrect values for /// required properties.</exception> private IEnumerable <ReadHydraulicLocationMapping> GetLocationIdsFromDatabase(SQLiteParameter trackParameter) { string query = HydraulicLocationConfigurationDatabaseQueryBuilder.GetLocationIdsByTrackIdQuery(); var locationLookup = new Dictionary <long, long>(); using (IDataReader dataReader = CreateDataReader(query, trackParameter)) { while (MoveNext(dataReader)) { long hrdLocationId = Convert.ToInt64(dataReader[LocationsTableDefinitions.HrdLocationId]); long hlcdLocationId = Convert.ToInt64(dataReader[LocationsTableDefinitions.LocationId]); // Must be unique if (locationLookup.ContainsKey(hrdLocationId)) { log.Warn(Resources.HydraulicLocationConfigurationDatabaseReader_GetLocationIdFromDatabase_Ambiguous_Row_Found_Take_First); } else { locationLookup[hrdLocationId] = hlcdLocationId; } } } return(locationLookup.Select(lookup => new ReadHydraulicLocationMapping(lookup.Key, lookup.Value)).ToArray()); }
/// <summary> /// Gets the hydraulic location configuration settings from the database. /// </summary> /// <returns>A collection of the read hydraulic configuration database settings.</returns> /// <exception cref="SQLiteException">Thrown when the database query failed.</exception> /// <exception cref="LineParseException">Thrown when the database returned incorrect values for /// required properties.</exception> private IEnumerable <ReadHydraulicLocationConfigurationDatabaseSettings> GetConfigurationSettingsFromDatabase() { string query = HydraulicLocationConfigurationDatabaseQueryBuilder.GetScenarioInformationQuery(); var readSettings = new List <ReadHydraulicLocationConfigurationDatabaseSettings>(); using (IDataReader dataReader = CreateDataReader(query)) { while (MoveNext(dataReader)) { readSettings.Add(ReadSetting(dataReader)); } } return(readSettings); }
/// <summary> /// Reads the use preprocessor closure from the database. /// </summary> /// <param name="trackParameter">A parameter containing the hydraulic boundary track id.</param> /// <returns>The read indicator whether to use the preprocessor closure.</returns> /// <exception cref="CriticalFileReadException">Thrown when the information could not be read /// from the database file.</exception> /// <exception cref="SQLiteException">Thrown when the database query failed.</exception> /// <exception cref="InvalidCastException">Thrown when the database returned incorrect values for /// required properties.</exception> private bool ReadUsePreprocessorClosure(SQLiteParameter trackParameter) { string query = HydraulicLocationConfigurationDatabaseQueryBuilder.GetRegionByTrackIdQuery(); using (IDataReader dataReader = CreateDataReader(query, trackParameter)) { DataTable schemaTable = dataReader.GetSchemaTable(); DataColumn columnName = schemaTable.Columns[schemaTable.Columns.IndexOf("ColumnName")]; if (schemaTable.Rows.Cast <DataRow>().All(row => row[columnName].ToString() != RegionsTableDefinitions.UsePreprocessorClosure)) { return(false); } if (MoveNext(dataReader)) { return(Convert.ToBoolean(dataReader[RegionsTableDefinitions.UsePreprocessorClosure])); } string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.HydraulicLocationConfigurationDatabaseReader_Critical_Unexpected_Exception); throw new CriticalFileReadException(message); } }
/// <summary> /// Determines whether the table related to the scenario information is present in the database. /// </summary> /// <returns><c>true</c> if the table is present; <c>false</c> otherwise.</returns> /// <exception cref="CriticalFileReadException">Thrown when the information could not be read from the database file.</exception> private bool IsScenarioInformationTablePresent() { string query = HydraulicLocationConfigurationDatabaseQueryBuilder.GetIsScenarioInformationPresentQuery(); try { using (IDataReader dataReader = CreateDataReader(query)) { if (dataReader.Read()) { return(Convert.ToBoolean(dataReader[ScenarioInformationTableDefinitions.IsScenarioInformationPresent])); } string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.HydraulicBoundaryDatabaseReader_Critical_Unexpected_value_on_column); throw new CriticalFileReadException(message); } } catch (SQLiteException exception) { string message = new FileReaderErrorMessageBuilder(Path).Build(Resources.HydraulicLocationConfigurationDatabaseReader_Critical_Unexpected_Exception); throw new CriticalFileReadException(message, exception); } }