Пример #1
0
        public override object ExecuteScalar()
        {
            object result  = null;
            var    context = NHProfilerContextProvider.GetLoggedDbCommand(InternalCommand, null);

            _profiler.ScalarExecuting(InternalCommand, context);
            _stopwatch.Restart();
            try
            {
                result = InternalCommand.ExecuteScalar();
            }
            catch (Exception e)
            {
                context = NHProfilerContextProvider.GetLoggedDbCommand(InternalCommand, e);
                _profiler.ScalarExecuting(InternalCommand, context);
                throw;
            }
            finally
            {
                _stopwatch.Stop();
                context = NHProfilerContextProvider.GetLoggedResult(InternalCommand, null, result, _stopwatch.ElapsedMilliseconds, null);
                _profiler.ScalarExecuted(InternalCommand, context);
            }

            return(result);
        }
Пример #2
0
        public override int ExecuteNonQuery()
        {
            int result = 0;

            var context = NHProfilerContextProvider.GetLoggedDbCommand(InternalCommand, null);

            _profiler.NonQueryExecuting(InternalCommand, context);
            _stopwatch.Restart();
            try
            {
                result       = InternalCommand.ExecuteNonQuery();
                AffectedRows = result;
            }
            catch (Exception e)
            {
                context = NHProfilerContextProvider.GetLoggedDbCommand(InternalCommand, e);
                _profiler.NonQueryExecuting(InternalCommand, context);
                throw;
            }
            finally
            {
                _stopwatch.Stop();
                context = NHProfilerContextProvider.GetLoggedResult(InternalCommand, null, result, _stopwatch.ElapsedMilliseconds, null);
                _profiler.NonQueryExecuted(InternalCommand, context);
            }

            return(result);
        }
Пример #3
0
 protected override void Dispose(bool disposing)
 {
     _profiler.TransactionDisposing(InnerTransaction, NHProfilerContextProvider.GetLoggedDbTransaction(InnerTransaction, _connectionId));
     if (disposing && InnerTransaction != null)
     {
         InnerTransaction.Dispose();
     }
     InnerTransaction = null;
     _connection      = null;
     base.Dispose(disposing);
 }
Пример #4
0
 protected override void Dispose(bool disposing)
 {
     _profiler.ConnectionDisposing(InnerConnection, NHProfilerContextProvider.GetLoggedDbConnection(InnerConnection));
     if (disposing && InnerConnection != null)
     {
         InnerConnection.StateChange -= StateChangeHandler;
         InnerConnection.Dispose();
     }
     InnerConnection = null;
     base.Dispose(disposing);
 }
Пример #5
0
        public ProfiledDbTransaction(DbTransaction transaction, ProfiledDbConnection connection, IDbProfiler profiler)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException("transaction");
            }
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            InnerTransaction = transaction;
            _connection      = connection;
            _profiler        = profiler;
            _connectionId    = UniqueIdExtensions <DbConnection> .GetUniqueId(connection.InnerConnection).ToInt();

            _profiler.TransactionBegan(connection.InnerConnection, NHProfilerContextProvider.GetLoggedDbConnection(this, _connectionId));
        }
Пример #6
0
        protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
        {
            DbDataReader originalResult = null;

            var context = NHProfilerContextProvider.GetLoggedDbCommand(InternalCommand, null);

            _profiler.ReaderExecuting(InternalCommand, context);
            _stopwatch.Restart();
            try
            {
                originalResult = InternalCommand.ExecuteReader(behavior);

                var dataSet = new DataSet {
                    EnforceConstraints = false
                };
                DataRows = new DataTable(tableName: Guid.NewGuid().ToString());
                dataSet.Tables.Add(DataRows);
                dataSet.Load(originalResult, LoadOption.OverwriteChanges, DataRows);

                originalResult = DataRows.CreateDataReader();
            }
            catch (Exception e)
            {
                context = NHProfilerContextProvider.GetLoggedDbCommand(InternalCommand, e);
                _profiler.ReaderExecuting(InternalCommand, context);
                throw;
            }
            finally
            {
                _stopwatch.Stop();
                context = NHProfilerContextProvider.GetLoggedResult(InternalCommand, null, originalResult, _stopwatch.ElapsedMilliseconds, DataRows);
                _profiler.ReaderExecuted(InternalCommand, context);
            }

            return(originalResult);
        }
Пример #7
0
 public override void Rollback()
 {
     _profiler.TransactionRolledBack(InnerTransaction, NHProfilerContextProvider.GetLoggedDbTransaction(InnerTransaction, _connectionId));
     InnerTransaction.Rollback();
 }
Пример #8
0
 public override void Commit()
 {
     _profiler.TransactionCommitted(InnerTransaction, NHProfilerContextProvider.GetLoggedDbTransaction(InnerTransaction, _connectionId));
     InnerTransaction.Commit();
 }
Пример #9
0
 public override void Close()
 {
     _profiler.ConnectionClosed(InnerConnection, NHProfilerContextProvider.GetLoggedDbConnection(InnerConnection));
     InnerConnection.Close();
 }
Пример #10
0
 public override void Open()
 {
     _profiler.ConnectionOpened(InnerConnection, NHProfilerContextProvider.GetLoggedDbConnection(InnerConnection));
     InnerConnection.Open();
 }