/// <summary> /// Creates a new instance of <see cref="CriticalProfileProperties"/> which contains properties /// that are critical for reading profiles. If these properties cannot be read, then something /// went wrong while querying the database. /// </summary> /// <param name="reader">The <see cref="IRowBasedDatabaseReader"/> from which to obtain the critical properties.</param> /// <exception cref="CriticalFileReadException">Thrown when the values in the database could not be /// casted to the expected column types.</exception> public CriticalProfileProperties(IRowBasedDatabaseReader reader) { try { ProfileName = reader.Read <string>(SoilProfileTableDefinitions.ProfileName); LayerCount = reader.Read <long>(SoilProfileTableDefinitions.LayerCount); ProfileId = reader.Read <long>(SoilProfileTableDefinitions.SoilProfileId); } catch (InvalidCastException e) { var messageBuilder = new FileReaderErrorMessageBuilder(reader.Path); if (!string.IsNullOrEmpty(ProfileName)) { messageBuilder.WithSubject(string.Format(Resources.SoilProfileReader_SoilProfileName_0_, ProfileName)); } string message = messageBuilder.Build(Resources.SoilProfileReader_Critical_Unexpected_value_on_column); throw new CriticalFileReadException(message, e); } }
/// <summary> /// Creates a new instance of <see cref="Layer1DProperties"/> which contains properties /// that are required to create a complete <see cref="SoilLayer1D"/>. If these properties /// cannot be read, then the reader can proceed to the next profile. /// </summary> /// <param name="reader">The <see cref="IRowBasedDatabaseReader"/> to read the required layer property values from.</param> /// <param name="profileName">The profile name used in generating exceptions messages if casting failed.</param> /// <exception cref="SoilProfileReadException">Thrown when the values in the database could not be /// casted to the expected column types.</exception> internal Layer1DProperties(IRowBasedDatabaseReader reader, string profileName) : base(reader, profileName) { const string readColumn = SoilProfileTableDefinitions.Top; try { Top = reader.Read <double>(readColumn); } catch (InvalidCastException e) { string message = string.Format(Resources.SoilProfileReader_Profile_Name_0_has_invalid_value_on_Column_1, profileName, readColumn); throw new SoilProfileReadException(message, profileName, e); } }