Exemple #1
0
        /// <summary>
        /// Free, release, or reset managed or unmanaged resources.
        /// </summary>
        /// <param name="disposing">Wether to free, release, or resetting unmanaged resources or not.</param>
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                if (!_leaveOpen)
                {
                    if (WrappedConnection != null)
                    {
                        if (State != ConnectionState.Closed)
                        {
                            Close();
                        }

                        WrappedConnection.StateChange -= StateChangeHandler;
                        WrappedConnection.Dispose();
                    }

                    WrappedConnection = null;
                }

                Profiler = null;
            }

            // corefx calls Close() in Dispose() without checking ConnectionState.
#if !NETSTANDARD1_6
            base.Dispose(disposing);
#endif

            _disposed = true;
        }
Exemple #2
0
        /// <summary>
        /// Free, release, or reset managed or unmanaged resources.
        /// </summary>
        /// <param name="disposing">Wether to free, release, or resetting unmanaged resources or not.</param>
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                Profiler.OnError("Connection already disposed!");
            }

            if (disposing && WrappedConnection != null)
            {
                if (State != ConnectionState.Closed)
                {
                    Close();
                }

                WrappedConnection.StateChange -= StateChangeHandler;
                WrappedConnection.Dispose();
            }
            _disposed         = true;
            WrappedConnection = null;
            Profiler          = null;

            // corefx calls Close() in Dispose() without checking ConnectionState.
#if !NETSTANDARD1_6
            base.Dispose(disposing);
#endif
        }
Exemple #3
0
        /// <summary>
        /// Create a new instance of <see cref="AdoNetProfilerDbConnection"/> with recieving the instance of original <see cref="DbConnection" />, the instance of <see cref="IAdoNetProfiler"/> an whether leave the instance of original <see cref="DbConnection"/> open or not.
        /// </summary>
        /// <param name="connection">The instance of original <see cref="DbConnection" />.</param>
        /// <param name="profiler">The instance of original <see cref="IAdoNetProfiler" />.</param>
        /// <param name="leaveOpen">Whether leave the instance of <see cref="DbConnection"/> or not.</param>
        public AdoNetProfilerDbConnection(DbConnection connection, IAdoNetProfiler profiler, bool leaveOpen)
        {
            _leaveOpen = leaveOpen;

            WrappedConnection = connection ?? throw new ArgumentNullException(nameof(connection));
            Profiler          = profiler;

            WrappedConnection.StateChange += StateChangeHandler;
        }
Exemple #4
0
        /// <summary>
        /// Create a new instance of <see cref="AdoNetProfilerDbConnection" /> with recieving how to create the instance of original <see cref="DbConnection" /> and the instance of <see cref="IAdoNetProfiler"/>.
        /// </summary>
        /// <param name="connectionFactory">How to create the instance of original <see cref="DbConnection" />.</param>>
        /// <param name="profiler">The instance of original <see cref="IAdoNetProfiler" />.</param>
        public AdoNetProfilerDbConnection(Func <DbConnection> connectionFactory, IAdoNetProfiler profiler)
        {
            _leaveOpen = false;

            WrappedConnection = connectionFactory?.Invoke() ?? throw new ArgumentNullException(nameof(connectionFactory));
            Profiler          = profiler;

            WrappedConnection.StateChange += StateChangeHandler;
        }
        internal AdoNetProfilerDbTransaction(DbTransaction transaction, DbConnection connection, IAdoNetProfiler profiler)
        {
            if (transaction == null) throw new ArgumentNullException(nameof(transaction));
            if (connection  == null) throw new ArgumentNullException(nameof(connection));

            WrappedTransaction = transaction;

            _connection = connection;
            _profiler   = profiler;
        }
        internal AdoNetProfilerDbDataReader(DbDataReader reader, IAdoNetProfiler profiler)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            _reader   = reader;
            _profiler = profiler;
        }
Exemple #7
0
        internal AdoNetProfilerDbDataReader(DbDataReader reader, IAdoNetProfiler profiler)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            _reader   = reader;
            _profiler = profiler;
        }
        internal AdoNetProfilerDbCommand(DbCommand command, DbConnection connection, IAdoNetProfiler profiler)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            WrappedCommand = command;

            _connection = connection;
            _profiler   = profiler;
        }
        public AdoNetProfilerDbConnection(DbConnection connection, IAdoNetProfiler profiler)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }

            WrappedConnection = connection;
            Profiler          = profiler;

            WrappedConnection.StateChange += StateChangeHandler;
        }
Exemple #10
0
        public AdoNetProfilerDbConnection(string cs)
        {
            var c0   = ConfigurationManager.ConnectionStrings[cs];
            var fact = c0 == null ? "System.Data.SqlClient" : c0.ProviderName ?? "System.Data.SqlClient";
            var dbf  = DbProviderFactories.GetFactory(fact);
            var cn   = dbf.CreateConnection();

            cn.ConnectionString            = c0 == null ? cs : c0.ConnectionString;
            WrappedConnection              = cn;
            Profiler                       = AdoNetProfilerFactory.GetProfiler();
            WrappedConnection.StateChange += StateChangeHandler;
        }
Exemple #11
0
        /// <summary>
        /// Create a new instance of <see cref="AdoNetProfilerDbConnection"/> with recieving the instance of original <see cref="DbConnection" /> and the instance of <see cref="IAdoNetProfiler"/>.
        /// </summary>
        /// <param name="connection">The instance of original <see cref="DbConnection" />.</param>
        /// <param name="profiler">The instance of original <see cref="IAdoNetProfiler" />.</param>
        public AdoNetProfilerDbConnection(DbConnection connection, IAdoNetProfiler profiler)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }

            WrappedConnection = connection;
            Profiler          = profiler;

            WrappedConnection.StateChange += StateChangeHandler;
        }
        internal AdoNetProfilerDbCommand(DbCommand command, DbConnection connection, IAdoNetProfiler profiler)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            WrappedCommand = command;

            _connection = connection;
            _profiler   = profiler;
        }
Exemple #13
0
        internal AdoNetProfilerDbTransaction(DbTransaction transaction, DbConnection connection, IAdoNetProfiler profiler)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }

            WrappedTransaction = transaction;

            _connection = connection;
            _profiler   = profiler;
        }
Exemple #14
0
        /// <summary>
        /// Free, release, or reset managed or unmanaged resources.
        /// </summary>
        /// <param name="disposing">Wether to free, release, or resetting unmanaged resources or not.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && WrappedConnection != null)
            {
                if (State != ConnectionState.Closed)
                {
                    Close();
                }

                WrappedConnection.StateChange -= StateChangeHandler;
                WrappedConnection.Dispose();
            }

            WrappedConnection = null;
            Profiler          = null;

            // corefx calls Close() in Dispose() without checking ConnectionState.
#if !COREFX
            base.Dispose(disposing);
#endif
        }
        internal AdoNetProfilerDbDataReader(DbDataReader reader, IAdoNetProfiler profiler, DateTime queryStart)
        {
            CreatedDate = queryStart;
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            _reader    = reader;
            _profiler  = profiler;
            _firstRead = false;
            if (EagerFirstRead)
            {
                _firstReadResult = _reader.Read();
                _firstRead       = true;
                if (_firstReadResult)
                {
                    _records++;
                }
            }
        }
 public TestDbConnection(DbConnection connection, IAdoNetProfiler profiler)
     : base(connection, profiler)
 {
     TestProfiler = (TestProfiler)profiler;
 }
        protected override void Dispose(bool disposing)
        {
            if (disposing && WrappedConnection != null)
            {
                if (State != ConnectionState.Closed)
                {
                    Close();
                }

                WrappedConnection.StateChange -= StateChangeHandler;
                WrappedConnection.Dispose();
            }

            WrappedConnection = null;
            Profiler          = null;

            // corefx calls Close() in Dispose() without checking ConnectionState.
#if !COREFX
            base.Dispose(disposing);
#endif
        }
Exemple #18
0
 /// <summary>
 /// Create a new instance of <see cref="AdoNetProfilerDbConnection"/> with recieving the instance of original <see cref="DbConnection" /> and the instance of <see cref="IAdoNetProfiler"/>.
 /// </summary>
 /// <param name="connection">The instance of original <see cref="DbConnection" />.</param>
 /// <param name="profiler">The instance of original <see cref="IAdoNetProfiler" />.</param>
 public AdoNetProfilerDbConnection(DbConnection connection, IAdoNetProfiler profiler)
     : this(connection, profiler, false)
 {
 }