示例#1
0
        /// <summary>
        /// Selects from feedback based on the feedback id.
        /// SQL+ Routine: dbo.FeedbackTable - Authored by Alan Hyneman
        /// </summary>
        public FeedbackTableOutput FeedbackTable(IFeedbackTableInput input, bool bypassValidation = false)
        {
            if (!bypassValidation)
            {
                if (!input.IsValid())
                {
                    throw new ArgumentException("FeedbackTableInput fails validation - use the FeedbackTableInput.IsValid() method prior to passing the input argument to the FeedbackTable method.", "input");
                }
            }
            FeedbackTableOutput output = new FeedbackTableOutput();

            if (sqlConnection != null)
            {
                using (SqlCommand cmd = GetFeedbackTableCommand(sqlConnection, input))
                {
                    cmd.Transaction = sqlTransaction;
                    FeedbackTableCommand(cmd, output);
                }
                return(output);
            }
            for (int idx = 0; idx <= retryOptions.RetryIntervals.Count; idx++)
            {
                if (idx > 0)
                {
                    System.Threading.Thread.Sleep(retryOptions.RetryIntervals[idx - 1]);
                }
                try
                {
                    using (SqlConnection cnn = new SqlConnection(connectionString))
                        using (SqlCommand cmd = GetFeedbackTableCommand(cnn, input))
                        {
                            cnn.Open();
                            FeedbackTableCommand(cmd, output);
                            cnn.Close();
                        }
                    break;
                }
                catch (SqlException sqlException)
                {
                    bool throwException = true;

                    if (retryOptions.TransientErrorNumbers.Contains(sqlException.Number))
                    {
                        throwException = (idx == retryOptions.RetryIntervals.Count);

                        if (retryOptions.Logger != null)
                        {
                            retryOptions.Logger.Log(sqlException);
                        }
                    }
                    if (throwException)
                    {
                        throw;
                    }
                }
            }
            return(output);
        }
示例#2
0
        /// <summary>
        /// Builds the command object for FeedbackTable method.
        /// </summary>
        /// <param name="cnn">The connection that will execute the procedure.</param>
        /// <param name="input">FeedbackTableInput instance for loading parameter values.</param>
        /// <returns>SqlCommand ready for execution.</returns>
        private SqlCommand GetFeedbackTableCommand(SqlConnection cnn, IFeedbackTableInput input)
        {
            SqlCommand result = new SqlCommand()
            {
                CommandType = CommandType.Text,
                CommandText = "SELECT * FROM [dbo].[FeedbackTable](@FeedbackId)",
                Connection  = cnn
            };

            result.Parameters.Add(new SqlParameter()
            {
                ParameterName = "@FeedbackId",
                Direction     = ParameterDirection.Input,
                SqlDbType     = SqlDbType.Int,
                Scale         = 0,
                Precision     = 10,
                Value         = input.FeedbackId
            });

            return(result);
        }