/// <summary>
        /// Tracks when 'command' is started.
        /// </summary>
        /// <param name="profiledDbCommand">The <see cref="IDbCommand"/> that started.</param>
        /// <param name="executeType">The execution type of the <paramref name="profiledDbCommand"/>.</param>
        void IDbProfiler.ExecuteStart(IDbCommand profiledDbCommand, SqlExecuteType executeType)
        {
            var id     = Tuple.Create((object)profiledDbCommand, executeType);
            var timing = profiledDbCommand.GetTiming(executeType.ToString(), this);

            lock (_dbLocker)
            {
                _inProgress     = _inProgress ?? new Dictionary <Tuple <object, SqlExecuteType>, CustomTiming>();
                _inProgress[id] = timing;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initialises a new instance of the <see cref="SqlTiming"/> class. 
        /// Creates a new <c>SqlTiming</c> to profile 'command'.
        /// </summary>
        public SqlTiming(IDbCommand command, SqlExecuteType type, MiniProfiler profiler)
        {
            if (profiler == null) throw new ArgumentNullException("profiler");
            _profiler = profiler;
            
            var commandText = AddSpacesToParameters(command.CommandText);
            var parameters = GetCommandParameters(command);

            if (MiniProfiler.Settings.SqlFormatter != null)
            {
                commandText = MiniProfiler.Settings.SqlFormatter.GetFormattedSql(commandText, parameters, command);
            }

            _customTiming = profiler.CustomTiming("sql", commandText, type.ToString());
            if (_customTiming == null) throw new InvalidOperationException();
        }
Esempio n. 3
0
        /// <summary>
        /// Initialises a new instance of the <see cref="SqlTiming"/> class.
        /// Creates a new <c>SqlTiming</c> to profile 'command'.
        /// </summary>
        /// <param name="command">The <see cref="DbCommand"/> to time.</param>
        /// <param name="type">The execution type.</param>
        /// <param name="profiler">The miniprofiler to attach the timing to.</param>
        /// <exception cref="ArgumentNullException">Throws when the <paramref name="profiler"/> is <c>null</c>.</exception>
        /// <exception cref="InvalidOperationException">Throw if the custom timing can't be created.</exception>
        public SqlTiming(IDbCommand command, SqlExecuteType type, MiniProfiler profiler)
        {
            _profiler = profiler ?? throw new ArgumentNullException(nameof(profiler));

            var commandText = AddSpacesToParameters(command.CommandText);
            var parameters  = GetCommandParameters(command);

            if (MiniProfiler.Settings.SqlFormatter != null)
            {
                commandText = MiniProfiler.Settings.SqlFormatter.GetFormattedSql(commandText, parameters, command);
            }

            _customTiming = profiler.CustomTiming("sql", commandText, type.ToString());
            if (_customTiming == null)
            {
                throw new InvalidOperationException();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Initialises a new instance of the <see cref="SqlTiming"/> class.
        /// Creates a new <c>SqlTiming</c> to profile 'command'.
        /// </summary>
        public SqlTiming(ProfiledDbCommand command, SqlExecuteType type, MiniProfiler profiler)
        {
            if (profiler == null)
            {
                throw new ArgumentNullException("profiler");
            }
            _profiler = profiler;

            var commandText = AddSpacesToParameters(command.CommandText);
            var parameters  = GetCommandParameters(command);

            Command       = command;
            commandText   = Settings.SqlFormatter.FormatSql(commandText, parameters);
            _customTiming = MiniProfiler.CustomTiming("sql", commandText, type.ToString());
            if (_customTiming == null)
            {
                throw new InvalidOperationException();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Tracks when 'command' is started.
        /// </summary>
        /// <param name="profiledDbCommand">The <see cref="IDbCommand"/> that started.</param>
        /// <param name="executeType">The execution type of the <paramref name="profiledDbCommand"/>.</param>
        void IDbProfiler.ExecuteStart(IDbCommand profiledDbCommand, SqlExecuteType executeType)
        {
            var id = Tuple.Create((object)profiledDbCommand, executeType);

            _inProgress[id] = profiledDbCommand.GetTiming(executeType.ToString(), this);
        }