/// <summary> /// Parse the Row into the Value type /// </summary> /// <param name="row">The row that will be parsed</param> /// <returns>Returns: the parsed value for <see cref="Value"/></returns> internal protected virtual T ParseRow(IInpTableRow row) { // The base class cannot parse the value because // it doesn't know what the value type is and needs to be overridden // in derived classes throw new NotImplementedException(); }
/// <summary> /// Override of the <see cref="InpTimeSpanOption.ParseRow(IInpTableRow)"/> option /// that parses the <see cref="IInpTableRow"/> into a <see cref="TimeSpan"/> using the /// <see cref="TimeSpan.FromDays(double)"/> method. /// </summary> /// <param name="row">The row that will be parsed</param> /// <returns></returns> internal protected override TimeSpan ParseRow(IInpTableRow row) { // Check for null _ = row ?? throw new ArgumentNullException(nameof(row)); // If not null try and parse the row, if the parse is successful return it // from days. If not throw a new InpParseException return(TimeSpan.FromDays(double.TryParse(row[1], out var result) ? result : throw new InpParseException(typeof(DryDaysOption).Name))); }
/// <summary> /// Add a row to the table. /// </summary> /// <exception cref="ArgumentException"> /// This will throw if the row is already in the table /// </exception> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="row"/> is null /// </exception> /// <param name="row">The row that is to be added</param> public void AddRow(IInpTableRow row) { // Check for null _ = row ?? throw new ArgumentNullException(nameof(row)); // Check to see if the table already contains this // entry and if it does then append the values to it // Note that we don't read the key value to the values array if (_tableDictionary.ContainsKey(row.Key)) { // Using the range 1..^0 grabs the second value to the last value _tableDictionary[row.Key].Values.AddRange(row.Values.ToArray()[1..^ 0]);
/// <summary> /// Override of the <see cref="InpOption{T}.ParseRow(IInpTableRow)"/> method /// that will convert the value from the row into an int. /// </summary> /// <param name="row">The row that will be parsed</param> /// <returns>Returns: an <see cref="int"/> that is parsed from the second element in the row</returns> protected internal override int ParseRow(IInpTableRow row) { _ = row ?? throw new ArgumentNullException(nameof(row)); if (int.TryParse(row[1], out var value)) { return(value); } else { throw InpParseException.CreateWithStandardMessage(typeof(InpIntOption)); } }
/// <summary> /// Internal Override of the <see cref="InpOption{T}.ParseRow(IInpTableRow)"/> method /// </summary> /// <param name="row">The row that will be parsed</param> /// <returns>Returns: the rows value to a <see cref="TimeSpan"/> to seconds</returns> protected internal override TimeSpan ParseRow(IInpTableRow row) { _ = row ?? throw new ArgumentNullException(nameof(row)); // If able to parse the row return the from seconds method if (double.TryParse(row[1], out var result)) { return(TimeSpan.FromSeconds(result)); } // Else throw an exception else { throw new InpParseException($"Unable to parse {typeof(ConduitLengtheningStepOption)}"); } }
/// <summary> /// Parse the <see cref="IInpTableRow"/> to the <see cref="Value"/> /// for the <see cref="TimeSpan"/> type /// </summary> /// <param name="row">The row that will be parsed</param> /// <returns>Returns: The parsed value</returns> internal protected override TimeSpan ParseRow(IInpTableRow row) { // Check for null _ = row ?? throw new ArgumentNullException(nameof(row)); // Try and parse the row as a time span if (TimeSpan.TryParse(row[1], out var value)) { return(value); } // If it fails then throw an exception else { throw InpParseException.CreateWithStandardMessage(typeof(InpTimeSpanOption)); } }
/// <summary> /// Initializes this entity from a table row and /// a database. /// </summary> /// <param name="row">The row that will be used to initialize this entity</param> /// <param name="database">The database that will be used to initialize this entity</param> public InpEntity(IInpTableRow row, IInpDatabase database) : this() { // Check if the argument is null _ = row ?? throw new ArgumentNullException(nameof(row)); _ = database ?? throw new ArgumentNullException(nameof(database)); // Check to see if the row has a name // and if it does set it if (row.Values.Count > 1) { Name = row[0]; } // Set the database for the Database = database; }
/// <summary> /// Protected internal override of the <see cref="InpOption{T}.ParseRow(IInpTableRow)"/> Method /// that parses a <see cref="double"/> /// </summary> /// <param name="row">The row that will be parsed</param> /// <returns>Returns: a <see cref="double"/> that is parsed from the row</returns> protected internal override double ParseRow(IInpTableRow row) { // Check for null _ = row ?? throw new ArgumentNullException(nameof(row)); // Try to parse the row if (double.TryParse(row[1], out var value)) { // If it succeeds then assign the value of the parsing return(value); } // If it is not successful throw an new exception else { throw InpParseException.CreateWithStandardMessage(typeof(InpDoubleOption)); } }
/// <summary> /// Constructor that accepts a <see cref="IInpTableRow"/> and a <see cref="IInpDatabase"/> /// </summary> /// <param name="row">The row that will be used to construct the option</param> /// <param name="database">The database that the option belongs to</param> internal AllowPondingOption(IInpTableRow row, IInpDatabase database) : base(row, database) { }
/// <summary> /// Constructor that accepts an <see cref="IInpTableRow"/> /// and an <see cref="IInpDatabase"/> /// </summary> /// <param name="row">The row that will be used to construct the value</param> /// <param name="database">The database that the option belongs to</param> internal DryWeatherStepOption(IInpTableRow row, IInpDatabase database) : base(row, database) { }
/// <summary> /// Constructor that takes in an <see cref="IInpTableRow"/> and an <see cref="IInpDatabase"/>. /// The value of the Option will be constructed from the <see cref="IInpTableRow"/> that is passed /// </summary> /// <param name="row">The row that will construct the value for this option</param> /// <param name="database">The database that this option belongs to</param> internal ReportStartDateTimeOption(IInpTableRow row, IInpDatabase database) : base(row, database) { }
/// <summary> /// Constructor that sets the value from the <paramref name="row"/> data /// and sets the database that the option belongs to /// </summary> /// <param name="row"></param> /// <param name="database"></param> internal InpDoubleOption(IInpTableRow row, IInpDatabase database) : base(row, database) { Value = ParseRow(row); }
/// <summary> /// Internal Constructor that builds the option from an <see cref="IInpTableRow"/> /// and places the option into the <see cref="IInpDatabase"/> /// </summary> /// <param name="row">The row that will be used to build the option</param> /// <param name="database">The database that the option belongs to</param> internal ControlRuleStepOption(IInpTableRow row, IInpDatabase database) : base(row, database) { }
/// <summary> /// Constructor the class that accepts an <see cref="IInpTableRow"/> /// and a <see cref="IInpDatabase"/>. /// </summary> /// <param name="row">The row that the option will be created from</param> /// <param name="database">The database that the option will belong to</param> internal EndDateTimeOption(IInpTableRow row, IInpDatabase database) : base(row, database) { // Everything is constructed in the base class }
/// <summary> /// Protected internal override the <see cref="InpOption{T}.ParseRow(IInpTableRow)"/> method /// that will convert this <see cref="IInpTableRow"/> to a <see cref="bool"/> /// </summary> /// <param name="row">The row that will be converted</param> /// <returns>Returns: a <see cref="bool"/> that is created from the row</returns> protected internal override bool ParseRow(IInpTableRow row) => row == null ? throw new ArgumentNullException(nameof(row)) : FromInpString(row[1]);
/// <summary> /// The internal constructor that will create the option from a <see cref="IInpTableRow"/> /// and add this option to the <see cref="IInpDatabase"/> /// </summary> /// <param name="row">The row that will be used to create the option</param> /// <param name="database">The database that this option belongs to</param> internal DryDaysOption(IInpTableRow row, IInpDatabase database) : base(row, database) { Value = ParseRow(row); }
/// <summary> /// Internal Constructor for building the <see cref="ConduitLengtheningStepOption"/> from /// and <see cref="IInpTableRow"/> and add it to the <see cref="IInpDatabase"/> supplied. /// </summary> /// <param name="row">The row that will be used to build the option</param> /// <param name="database">The database that the option belongs to</param> internal ConduitLengtheningStepOption(IInpTableRow row, IInpDatabase database) : base(row, database) { }
/// <summary> /// Parse the <see cref="IInpTableRow"/> that is passed and return it. /// </summary> /// <param name="row">The row that will be parsed an returned</param> /// <exception cref="ArgumentNullException"> /// Will Throw if <paramref name="row"/> is <see cref="null"/> /// </exception> /// <exception cref="InpParseException"> /// Will Throw if <see cref="DateTime.TryParse(ReadOnlySpan{char}, out DateTime)"/> fails /// </exception> /// <returns>Returns: The <see cref="DateTime"/> that is parsed from the row</returns> protected internal override DateTime ParseRow(IInpTableRow row) => row == null ? throw new ArgumentNullException(nameof(row)) : DateTime.TryParse(row[1], out var result) ? result : throw InpParseException.CreateWithStandardMessage(typeof(InpDateTimeOption));
/// <summary> /// Constructor that accepts a <see cref="IInpTableRow"/> and an <see cref="IInpDatabase"/> /// to build the object /// </summary> /// <param name="row">The row that will be used to construct the value</param> /// <param name="database">The database that the date time belongs to</param> internal InpDateTimeOption(IInpTableRow row, IInpDatabase database) : base(row, database) { // Convert the row into a DateTime and // store it in the value property Value = ParseRow(row); }
/// <summary> /// Build the option from an <see cref="IInpTableRow"/> and an <see cref="IInpDatabase"/> /// </summary> /// <param name="row">The row that the <see cref="InpOption{T}"/> will be built from</param> /// <param name="database">The database that the option belongs to</param> internal InpBoolOption(IInpTableRow row, IInpDatabase database) : base(row, database) => Value = ParseRow(row);
/// <summary> /// Constructor that passes the arguments to the base class /// </summary> /// <param name="row">the row that will be used to construct the option</param> /// <param name="database">the database that this option belongs to</param> internal InpOption(IInpTableRow row, IInpDatabase database) : base(row, database) { Value = default; }