Beispiel #1
0
        /// <summary>
        /// Execute a reader stored procedure using existing connection string
        /// </summary>
        /// <typeparam name="T">the return type which need to be got from the data reader</typeparam>
        /// <param name="sprocName">stored procedure name to be executed</param>
        /// <param name="processMethod">method to process data reader and make return value</param>
        /// <param name="connection">The connection the command will execute on</param>
        /// <param name="dbTran">The transaction the command will execute on</param>
        /// <param name="commandParams">sql parameters to pass into the stored procedure</param>
        /// <returns>
        ///     The process result as specific return type
        /// </returns>
        public T ExecuteReaderHelper <T>(string sprocName,
                                         ProcessingDelegate <T> processMethod,
                                         DbConnection connection = null,
                                         DbTransaction dbTran    = null,
                                         params SqlParameter[] commandParams) where T : class
        {
            DbConnection dbConnection = null;

            try
            {
                T sqlRet = default(T);
                dbConnection = connection ?? new SqlConnection(this.ConnectionString);
                if (dbConnection.State != ConnectionState.Open)
                {
                    dbConnection.Open();
                }
                using (var cmd = dbConnection.CreateCommand())
                {
                    cmd.Transaction = dbTran;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = sprocName;
                    cmd.Parameters.AddRange(commandParams);
                    using (IDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            sqlRet = processMethod(reader);
                        }
                    }
                }
                return(sqlRet);
            }
            catch (Exception)
            {
                if (null != dbTran)
                {
                    dbTran.Rollback();
                }
                throw;
            }
            finally
            {
                if (null == connection && null != dbConnection)
                {
                    dbConnection.Dispose();
                }
            }
        }
Beispiel #2
0
 public DataProcessingPipeLineMiddleware(ILogger <DataProcessingPipeLineMiddleware> logger, ProcessingDelegate next)
 {
     _logger = logger;
     _next   = next;
 }
Beispiel #3
0
 private static void InvokeOperation(ProcessingDelegate operation, long arg)
 {
     operation(arg);
 }
Beispiel #4
0
 public ProcessingContextBuilder AddDataHandler(ProcessingDelegate dataHandler)
 {
     _dataHandler = dataHandler;
     return(this);
 }