Ejemplo n.º 1
0
        /// <summary>
        /// Selects page results from dbo.Feedback table.
        /// SQL+ Routine: dbo.FeedbackPaged - Authored by Alan Hyneman
        /// </summary>
        public FeedbackPagedOutput FeedbackPaged(IFeedbackPagedInput input, bool bypassValidation = false)
        {
            if (!bypassValidation)
            {
                if (!input.IsValid())
                {
                    throw new ArgumentException("FeedbackPagedInput fails validation - use the FeedbackPagedInput.IsValid() method prior to passing the input argument to the FeedbackPaged method.", "input");
                }
            }
            FeedbackPagedOutput output = new FeedbackPagedOutput();

            if (sqlConnection != null)
            {
                using (SqlCommand cmd = GetFeedbackPagedCommand(sqlConnection, input))
                {
                    cmd.Transaction = sqlTransaction;
                    FeedbackPagedCommand(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 = GetFeedbackPagedCommand(cnn, input))
                        {
                            cnn.Open();
                            FeedbackPagedCommand(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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Builds the command object for FeedbackPaged method.
        /// </summary>
        /// <param name="cnn">The connection that will execute the procedure.</param>
        /// <param name="input">FeedbackPagedInput instance for loading parameter values.</param>
        /// <returns>SqlCommand ready for execution.</returns>
        private SqlCommand GetFeedbackPagedCommand(SqlConnection cnn, IFeedbackPagedInput input)
        {
            SqlCommand result = new SqlCommand()
            {
                CommandType = CommandType.StoredProcedure,
                CommandText = "[dbo].[FeedbackPaged]",
                Connection  = cnn
            };

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

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

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

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

            return(result);
        }