public override void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<int> interceptionContext) { if (command.Parameters.Count > 0 && command.Parameters[0].Value.ToString() == "Throw") { interceptionContext.Exception = new DataException("Exception Test"); } }
public void Cloning_the_interception_context_preserves_contextual_information_but_not_mutable_state() { var objectContext = new ObjectContext(); var dbContext = DbContextMockHelper.CreateDbContext(objectContext); var interceptionContext = new DbCommandInterceptionContext<string>(); var mutableData = ((IDbMutableInterceptionContext<string>)interceptionContext).MutableData; mutableData.SetExecuted("Wensleydale"); mutableData.SetExceptionThrown(new Exception("Cheez Whiz")); mutableData.UserState = new object(); interceptionContext = interceptionContext .WithDbContext(dbContext) .WithObjectContext(objectContext) .AsAsync() .WithCommandBehavior(CommandBehavior.SchemaOnly); Assert.Equal(new[] { objectContext }, interceptionContext.ObjectContexts); Assert.Equal(new[] { dbContext }, interceptionContext.DbContexts); Assert.True(interceptionContext.IsAsync); Assert.Equal(CommandBehavior.SchemaOnly, interceptionContext.CommandBehavior); Assert.Null(interceptionContext.Result); Assert.Null(interceptionContext.OriginalResult); Assert.Null(interceptionContext.Exception); Assert.Null(interceptionContext.OriginalException); Assert.Null(interceptionContext.UserState); Assert.False(interceptionContext.IsExecutionSuppressed); }
public void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext) { if (!command.CommandText.EndsWith(" option(recompile)")) { command.CommandText += " option(recompile)"; } }
public void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext) { if (!command.CommandText.EndsWith(" option(recompile)")) { command.CommandText += " option(recompile)"; } }
public override void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext) { // actually the same method overriden in the SchoolInterceptorLogging class bool throwTransientErrors = false; if (command.Parameters.Count > 0 && command.Parameters[0].Value.ToString() == "%Throw%") { throwTransientErrors = true; command.Parameters[0].Value = "%an%"; command.Parameters[1].Value = "%an%"; } if (throwTransientErrors) { _logger.Information("Returning transient error for command: {0}", command.CommandText); _counter++; if (_counter < 4) { interceptionContext.Exception = CreateDummySqlException(); } else { _counter = 0; } } }
public override void ReaderExecuted(System.Data.Common.DbCommand command, DbCommandInterceptionContext<System.Data.Common.DbDataReader> interceptionContext) { _stopwatch.Stop(); if (interceptionContext.Exception != null) { LogHelper.Write(CommonLogger.DataBase, LogLevel.Error, String.Format("Exception:{1} \r\n --> Error executing command:\r\n {0}", command.CommandText, interceptionContext.Exception.ToString())); #if !DEBUG WorkPool.Append<NormalNotifyEmail>(WorkType.email_for_normalnotify, new NormalNotifyEmail() { Message = String.Format("Exception:{1} \r\n --> Error executing command:\r\n {0}", command.CommandText, interceptionContext.Exception.ToString()), Title = SiteSettings.SiteName + "--数据执行警告", Recipient = "*****@*****.**" }); #endif } else { if (SQLTrace) { if (_stopwatch.ElapsedMilliseconds >= logValue) { LogHelper.Write(CommonLogger.DataBase, LogLevel.Trace, String.Format("\r\n执行时间:{0} 毫秒 \r\n -->ReaderExecuted.Command:\r\n{1}", _stopwatch.ElapsedMilliseconds, command.CommandText)); } } } base.ReaderExecuted(command, interceptionContext); }
public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<Int32> interceptionContext) { if (!command.CommandText.EndsWith(" option(recompile)")) { command.CommandText += " option(recompile)"; } }
public override void NonQueryExecuting(System.Data.Common.DbCommand command, DbCommandInterceptionContext<int> interceptionContext) { base.NonQueryExecuting(command, interceptionContext); _stopwatch.Restart(); }
public override void ReaderExecuting(System.Data.Common.DbCommand command, DbCommandInterceptionContext<System.Data.Common.DbDataReader> interceptionContext) { base.ReaderExecuting(command, interceptionContext); _stopwatch.Restart(); }
public override void ScalarExecuting(System.Data.Common.DbCommand command, DbCommandInterceptionContext<object> interceptionContext) { base.ScalarExecuting(command, interceptionContext); _stopwatch.Restart(); }
public override void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext) { if (!Suppress) { command.CommandText = TableAliasRegex.Replace(command.CommandText, "${tableAlias} WITH (NOLOCK)"); CommandText = command.CommandText; } }
public override void NonQueryExecuting( DbCommand command, DbCommandInterceptionContext<Int32> interceptionContext ) { base.NonQueryExecuting(command, interceptionContext); _stopwatch.Restart(); }
public override void NonQueryExecuted(DbCommand command, DbCommandInterceptionContext<int> interceptionContext) { _stopwatch.Stop(); if (interceptionContext.Exception != null) { _logger.Error(interceptionContext.Exception, "Error executing command: {0}: ", command.CommandText); } base.NonQueryExecuted(command, interceptionContext); }
private static ScalarCommandInterceptionData CreateInterceptionContext(DbCommand command, DbCommandInterceptionContext<object> interceptionContext) { return new ScalarCommandInterceptionData { DbCommand = command, DbContext = GetDbContext(interceptionContext), Error = interceptionContext.OriginalException, IsAsync = interceptionContext.IsAsync, Result = interceptionContext.Result }; }
private static DbReaderCommandInterceptionData CreateInterceptionContext(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext) { return new DbReaderCommandInterceptionData { DbCommand = command, DbContext = GetDbContext(interceptionContext), Error = interceptionContext.OriginalException, IsAsync = interceptionContext.IsAsync, Result = interceptionContext.Result }; }
public void New_base_interception_context_has_no_state() { var interceptionContext = new DbCommandInterceptionContext(); Assert.Empty(interceptionContext.ObjectContexts); Assert.Empty(interceptionContext.DbContexts); Assert.False(interceptionContext.IsAsync); Assert.Equal(CommandBehavior.Default, interceptionContext.CommandBehavior); }
public override void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext) { if (!Suppress) { var rnd = Guid.NewGuid().ToString("N"); command.CommandText = String.Format(Wrapped_Query_Tpl, command.CommandText, rnd, rnd); CommandText = command.CommandText; } }
public override void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext) { if (!SuppressNoLock) { command.CommandText = TableAliasRegex.Replace(command.CommandText, "${tableAlias} WITH (NOLOCK)"); } }
public override void ReaderExecuted(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext) { _stopwatch.Stop(); if (interceptionContext.Exception != null) _logger.Error(interceptionContext.Exception, "Error executing command: {0}", command.CommandText); else _logger.TraceApi("SQL Database", "SchoolInterceptor.ReaderExecuted", _stopwatch.Elapsed, "Command: {0}:", command.CommandText); base.ReaderExecuted(command, interceptionContext); }
public override void ScalarExecuted(DbCommand command, DbCommandInterceptionContext<object> interceptionContext) { _stopwatch.Stop(); if (interceptionContext.Exception != null) { _logger.Error(interceptionContext.Exception, "Error executing command: {0}", command.CommandText); } else { _logger.TraceApi("SQL Database", "SchoolInterceptor.ScalarExecuted", _stopwatch.Elapsed, "Command: {0}: ", command.CommandText); } base.ScalarExecuted(command, interceptionContext); }
/// <summary> /// Sends <see cref="IDbCommandInterceptor.NonQueryExecuting" /> and /// <see cref="IDbCommandInterceptor.NonQueryExecuted" /> to any <see cref="IDbCommandInterceptor" /> /// registered on <see cref="DbInterception" /> before/after making a /// call to <see cref="DbCommand.ExecuteNonQuery" />. /// </summary> /// <remarks> /// Note that the result of executing the command is returned by this method. The result is not available /// in the interception context passed into this method since the interception context is cloned before /// being passed to interceptors. /// </remarks> /// <param name="command">The command on which the operation will be executed.</param> /// <param name="interceptionContext">Optional information about the context of the call being made.</param> /// <returns>The result of the operation, which may have been modified by interceptors.</returns> public virtual int NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext) { Check.NotNull(command, "command"); Check.NotNull(interceptionContext, "interceptionContext"); return _internalDispatcher.Dispatch( command, (t, c) => t.ExecuteNonQuery(), new DbCommandInterceptionContext<int>(interceptionContext), (i, t, c) => i.NonQueryExecuting(t, c), (i, t, c) => i.NonQueryExecuted(t, c)); }
/// <summary> /// Sends <see cref="IDbCommandInterceptor.ScalarExecuting" /> and /// <see cref="IDbCommandInterceptor.ScalarExecuted" /> to any <see cref="IDbCommandInterceptor" /> /// registered on <see cref="DbInterception" /> before/after making a /// call to <see cref="DbCommand.ExecuteScalar" />. /// </summary> /// <remarks> /// Note that the result of executing the command is returned by this method. The result is not available /// in the interception context passed into this method since the interception context is cloned before /// being passed to interceptors. /// </remarks> /// <param name="command">The command on which the operation will be executed.</param> /// <param name="interceptionContext">Optional information about the context of the call being made.</param> /// <returns>The result of the operation, which may have been modified by interceptors.</returns> public virtual object Scalar(DbCommand command, DbCommandInterceptionContext interceptionContext) { Check.NotNull(command, "command"); Check.NotNull(interceptionContext, "interceptionContext"); return _internalDispatcher.Dispatch( command, (t, c) => t.ExecuteScalar(), new DbCommandInterceptionContext<object>(interceptionContext), (i, t, c) => i.ScalarExecuting(t, c), (i, t, c) => i.ScalarExecuted(t, c)); }
public override void NonQueryExecuted(DbCommand command, DbCommandInterceptionContext<int> interceptionContext) { _stopwatch.Stop(); if (interceptionContext.Exception != null) { _logger.Error(interceptionContext.Exception, "Error executing command: {0}", command.CommandText); } else { _logger.TraceApi("SQL Database", "TekConfInterceptor.NonQueryExecuted", _stopwatch.Elapsed, "Command: {0}: ", command.CommandText); } base.NonQueryExecuted(command, interceptionContext); }
public void ReaderExecuted(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext) { _stopwatch.Stop(); if (interceptionContext.Exception != null) { // _logger.Error(interceptionContext.Exception, "Error executing command: {0}", command.CommandText); } else { // _logger.TraceApi("SQL Database", "InterceptorLogging.ReaderExecuted", _stopwatch.Elapsed, "Command: {0}: ", command.CommandText); } base.ReaderExecuted(command, interceptionContext); }
public override void ScalarExecuted(System.Data.Common.DbCommand command, DbCommandInterceptionContext<object> interceptionContext) { _stopwatch.Stop(); if (interceptionContext.Exception != null) { LogHelper.LogSql(string.Format("Exception:{1} \r\n --> Error executing command: {0}", command.CommandText, interceptionContext.Exception.ToString())); } else { LogHelper.LogSql(string.Format("\r\n执行时间:{0} 毫秒\r\n-->ScalarExecuted.Command:{1}\r\n", _stopwatch.ElapsedMilliseconds, command.CommandText)); } base.ScalarExecuted(command, interceptionContext); }
public override void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext) { if (!Suppress) { if (!command.CommandText.TrimStart().StartsWith("DECLARE @v")) { var rnd = Guid.NewGuid().ToString("N"); command.CommandText = String.Format(Wrapped_Query_Tpl, command.CommandText, rnd, rnd); CommandText = command.CommandText; } } }
public override void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext) { Stopwatch timespan = Stopwatch.StartNew(); base.ScalarExecuting(command, interceptionContext); timespan.Stop(); if (interceptionContext.Exception != null) { _logger.Error(interceptionContext.Exception, "Error executing command: {0}", command.CommandText); } else { _logger.TraceApi("SQL Database", "IDEIBiblio.ScalarExecuting", timespan.Elapsed, "Command: {0}: ", command.CommandText); } }
public override void NonQueryExecuted(DbCommand command, DbCommandInterceptionContext<int> interceptionContext) { _stopwatch.Stop(); if (interceptionContext.Exception != null) { _logger.Error(interceptionContext.Exception, "Error executing command: {0}", command.CommandText); } else { telemetry.TrackMetric("NonQueryExecuted", _stopwatch.ElapsedMilliseconds); _logger.TraceApi("SQL Database", "SchoolInterceptor.NonQueryExecuted", _stopwatch.Elapsed, "Command: {0}: ", command.CommandText); } base.NonQueryExecuted(command, interceptionContext); }
public override void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext) { bool throwTransientErrors = false; if (command.Parameters.Count > 0 && command.Parameters[0].Value.ToString() == "Throw") { throwTransientErrors = true; command.Parameters[0].Value = "an"; command.Parameters[1].Value = "an"; } if (throwTransientErrors && _counter < 4) { _logger.Information("Returning transient error for command: {0}", command.CommandText); _counter++; interceptionContext.Exception = CreateDummySqlException(); } }
public override void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext) { Stopwatch timespan = Stopwatch.StartNew(); base.ReaderExecuting(command, interceptionContext); timespan.Stop(); if (interceptionContext.Exception != null) { _logger.Error(interceptionContext.Exception, "Error executing command: {0}", command.CommandText); } else { _logger.TraceApi("SQL Database", "SchoolInterceptor.ReaderExecuting", timespan.Elapsed, "Command: {0}: ", command.CommandText); } }