/// <summary> /// Private helper to get metric value. /// </summary> /// <param name="sqlDal">The SQL data access layer that will communicate with the SQL database.</param> /// <param name="testName">The name of test for logging purposes.</param> /// <param name="cmdType">The type of the commmand (text, stored procedure, or table direct).</param> /// <param name="cmdText">command to run.</param> /// <param name="date">The date of the metric.</param> /// <param name="cmdTimeoutInSeconds">The command timeout in seconds.</param> /// <returns>Task<System.Double>.</returns> /// <exception cref="ArgumentException"></exception> private static async Task <double> GetMetricValueAsDouble(ISqlDataAccessLayer sqlDal, string testName, CommandType cmdType, string cmdText, DateTime date, int cmdTimeoutInSeconds) { var dateParam = new SqlParameter("@Date", SqlDbType.DateTime) { Value = date }; var sqlCommand = sqlDal.CreateSqlCommand(cmdType, cmdText, new List <SqlParameter> { dateParam }, cmdTimeoutInSeconds); var metricValue = await sqlDal.GetQueryResultAsDouble(sqlCommand, "MetricValue"); //var metricValue = await sqlDal.GetQueryResult(sqlCommand, "MetricValue", false); //var metricValue = await sqlDal.GetQueryResult(sqlCommand, "MetricValue", Double.NaN); // Throw an exception when either of the dates returns no metric value (Double.NaN) if (Double.IsNaN(metricValue)) { var msg = $"The database does not have metrics for the test {testName} for date {date}."; throw new Exception(msg); } return(metricValue); }
/// <summary> /// Private helper to get metric value. /// </summary> /// <param name="sqlDal">The SQL data access layer that will communicate with the SQL database.</param> /// <param name="testName">The name of test for logging purposes.</param> /// <param name="cmdType">The type of the commmand (text, stored procedure, or table direct).</param> /// <param name="cmdText">command to run.</param> /// <param name="date">The date of the metric.</param> /// <param name="cmdTimeoutInSeconds">The command timeout in seconds.</param> /// <returns>Task<System.Double>.</returns> /// <exception cref="ArgumentException"></exception> private static async Task <bool> GetMetricValueAsBool(ISqlDataAccessLayer sqlDal, string testName, CommandType cmdType, string cmdText, DateTime date, int cmdTimeoutInSeconds) { var dateParam = new SqlParameter("@Date", SqlDbType.DateTime) { Value = date }; var sqlCommand = sqlDal.CreateSqlCommand(cmdType, cmdText, new List <SqlParameter> { dateParam }, cmdTimeoutInSeconds); var metricValue = await sqlDal.GetQueryResultAsBool(sqlCommand, "MetricValue"); return(metricValue); }