public override int ExecuteNonQuery() { if (_transaction != null) { try { _transaction.BeginCommand(this); return(InnerCommand.ExecuteNonQuery()); } finally { _transaction.EndCommand(); } } else { try { _txnlock.OpenWriter(); _txnlock.BeginCommand(this); return(InnerCommand.ExecuteNonQuery()); } finally { _txnlock.EndCommand(); _txnlock.CloseWriter(); } } }
public override object ExecuteScalar() { if (!Stats.IsEnabled) { return(InnerCommand.ExecuteScalar()); } object result; var commandId = Guid.NewGuid(); LogCommandStart(commandId); var stopwatch = Stopwatch.StartNew(); try { result = InnerCommand.ExecuteScalar(); } catch (Exception exception) { LogCommandError(commandId, exception); throw; } stopwatch.Stop(); LogCommandEnd(commandId, stopwatch.ElapsedMilliseconds, null); return(result); }
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) { if (!Stats.IsEnabled) { return(InnerCommand.ExecuteReader(behavior)); } DbDataReader reader; var commandId = Guid.NewGuid(); LogCommandStart(commandId); var stopwatch = Stopwatch.StartNew(); try { reader = InnerCommand.ExecuteReader(behavior); } catch (Exception exception) { LogCommandError(commandId, exception); throw; } stopwatch.Stop(); LogCommandEnd(commandId, stopwatch.ElapsedMilliseconds, reader.RecordsAffected); return(new GlimpseProfileDbDataReader(reader, InnerCommand, InnerConnection.ConnectionId, commandId, Stats)); }
public override int ExecuteNonQuery() { if (!Stats.IsEnabled) { return(InnerCommand.ExecuteNonQuery()); } int num; var commandId = Guid.NewGuid(); LogCommandStart(commandId); var stopwatch = Stopwatch.StartNew(); try { num = InnerCommand.ExecuteNonQuery(); } catch (Exception exception) { LogCommandError(commandId, exception); throw; } stopwatch.Stop(); LogCommandEnd(commandId, stopwatch.ElapsedMilliseconds, num); return(num); }
/// <summary> /// Executes the test method. Creates a new instance of the class /// under tests and passes it to the inner command. Also catches /// any exceptions and converts them into <see cref="FailedResult"/>s. /// </summary> /// <param name="testClass">The instance of the test class</param> /// <returns>Returns information about the test run</returns> public override MethodResult Execute(object testClass) { try { if (testClass == null) { testClass = method.CreateInstance(); } } catch (TargetInvocationException ex) { ExceptionUtility.RethrowWithNoStackTraceLoss(ex.InnerException); } try { return(InnerCommand.Execute(testClass)); } finally { IDisposable disposable = testClass as IDisposable; if (disposable != null) { disposable.Dispose(); } } }
public override bool TrySetMember(SetMemberBinder binder, object value) { var method = InnerCommand.GetType().GetProperty(binder.Name).GetSetMethod(); method.Invoke(InnerCommand, new[] { value }); return(true); }
/// <inheritdoc/> public override Task <object> ExecuteScalarAsync(CancellationToken cancellationToken) { return(ExecuteWithRetryAsync( async() => { await InnerConnection.EnsureIsOpenAsync(cancellationToken).ConfigureAwait(false); return await InnerCommand.ExecuteScalarAsync(cancellationToken).ConfigureAwait(false); })); }
/// <inheritdoc/> protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) { return(ExecuteWithRetry( () => { FixupParameters(); InnerConnection.EnsureIsOpen(); return InnerCommand.ExecuteReader(behavior); })); }
/// <inheritdoc/> public override object ExecuteScalar() { return(ExecuteWithRetry( () => { FixupParameters(); InnerConnection.EnsureIsOpen(); return InnerCommand.ExecuteScalar(); })); }
protected override void Dispose(bool disposing) { if (disposing && InnerCommand != null) { InnerCommand.Dispose(); } InnerCommand = null; InnerConnection = null; base.Dispose(disposing); }
/// <inheritdoc/> public override int ExecuteNonQuery() { return(ExecuteWithRetry( () => { FixupParameters(); InnerConnection.EnsureIsOpen(); return InnerCommand.ExecuteNonQuery(); })); }
/// <inheritdoc/> public override Task <int> ExecuteNonQueryAsync(CancellationToken cancellationToken) { return(ExecuteWithRetryAsync( async() => { FixupParameters(); await InnerConnection.EnsureIsOpenAsync(cancellationToken).ConfigureAwait(false); return await InnerCommand.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false); })); }
/// <inheritdoc/> protected override Task <DbDataReader> ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken) { return(ExecuteWithRetryAsync( async() => { FixupParameters(); await InnerConnection.EnsureIsOpenAsync(cancellationToken).ConfigureAwait(false); return await InnerCommand.ExecuteReaderAsync(behavior, cancellationToken).ConfigureAwait(false); })); }
public override object ExecuteScalar() { RecordingConnection.LogCommand(CommandText); if (!RecordingConnection.CanExecute) { return(null); } return(InnerCommand.ExecuteScalar()); }
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) { RecordingConnection.LogCommand(CommandText); if (!RecordingConnection.CanExecute) { return(null); } return(InnerCommand.ExecuteReader(behavior)); }
public override int ExecuteNonQuery() { RecordingConnection.LogCommand(CommandText); if (!RecordingConnection.CanExecute) { return(0); } return(InnerCommand.ExecuteNonQuery()); }
public async Task ValidConnection_RunAsync_CallsInnerCommandRunAsync() { var cluster = new Mock <IClusterClient>(); var healthChunkResult = Task.FromResult(new ClusterHealthChunk(HealthState.Ok)); cluster.Setup(c => c.GetClusterHealthChunkAsync(60, CancellationToken.None)).Returns(healthChunkResult); FabricClient.Setup(c => c.Cluster).Returns(cluster.Object); await _command.RunAsync(); InnerCommand.Verify(c => c.RunAsync(), Times.Once); }
public async Task UnhealthyCluster_RunAsync_NeverInnerCommandRunAsync() { var cluster = new Mock <IClusterClient>(); var healthChunkResult = Task.FromResult(new ClusterHealthChunk(HealthState.Warning)); cluster.Setup(c => c.GetClusterHealthChunkAsync(60, CancellationToken.None)).Returns(healthChunkResult); FabricClient.Setup(c => c.Cluster).Returns(cluster.Object); await _command.RunAsync(); InnerCommand.Verify(c => c.RunAsync(), Times.Never); }
public override MethodResult Execute(object testClass) { try { return(InnerCommand.Execute(testClass)); } catch { owner.OnFailure(); throw; } }
/// <inheritdoc/> protected override Task <DbDataReader> ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken) { return(ExecuteWithRetryAsync( () => { FixupParameters(); return InnerConnection.EnsureIsOpenAsync(cancellationToken) .ContinueWith(_ => InnerCommand.ExecuteReaderAsync(behavior, cancellationToken), cancellationToken) .Unwrap(); })); }
/// <inheritdoc/> public override Task <int> ExecuteNonQueryAsync(CancellationToken cancellationToken) { return(ExecuteWithRetryAsync( () => { FixupParameters(); return InnerConnection.EnsureIsOpenAsync(cancellationToken) .ContinueWith(_ => InnerCommand.ExecuteNonQueryAsync(cancellationToken), cancellationToken) .Unwrap(); })); }
/// <summary> /// Executes the inner test method, gathering the amount of time it takes to run. /// </summary> /// <returns>Returns information about the test run</returns> public override MethodResult Execute(object testClass) { TestTimer timer = new TestTimer(); timer.Start(); MethodResult methodResult = InnerCommand.Execute(testClass); timer.Stop(); methodResult.ExecutionTime = timer.ElapsedMilliseconds / 1000.00; return(methodResult); }
public async Task ConnectionCheckException_RunAsync_NeverInnerCommandRunAsync() { var cluster = new Mock <IClusterClient>(); cluster .Setup(c => c.GetClusterHealthChunkAsync(60, CancellationToken.None)) .Throws(new Exception("Connection failed.")); FabricClient.Setup(c => c.Cluster).Returns(cluster.Object); await _command.RunAsync(); InnerCommand.Verify(c => c.RunAsync(), Times.Never); }
// disposing: true if Dispose() was called, false // if being finalized by the garbage collector protected override void Dispose(bool disposing) { if (disposing) { if (InnerCommand != null) { InnerCommand.Dispose(); InnerCommand = null; } } base.Dispose(disposing); }
public async Task NoHealthCheckRequired_RunAsync_CallsInnerCommandRunAsync() { _context.Manifest.Options.CheckClusterHealthWaitTime = null; var cluster = new Mock <IClusterClient>(); var healthChunkResult = Task.FromResult(new ClusterHealthChunk(HealthState.Ok)); cluster.Setup(c => c.GetClusterHealthChunkAsync(60, CancellationToken.None)).Returns(healthChunkResult); FabricClient.Setup(c => c.Cluster).Returns(cluster.Object); await _command.RunAsync(); InnerCommand.Verify(c => c.RunAsync(), Times.Once); }
protected override void Dispose(bool disposing) { if (disposing) { InnerCommand.Dispose(); } base.Dispose(disposing); #if DEBUG Interlocked.Decrement(ref _activeObjectsCount); #endif }
private MethodResult ExecuteInternal(object testClass) { Exception exception = null; MethodResult result = null; MethodResult failedResult = null; for (int i = 0; i < _retries + 1; ++i) { try { result = InnerCommand.Execute(testClass); if (result is FailedResult) { TraceIf(_retries > 0, "Retry {0}/{1} failed.", i, _retries); failedResult = (FailedResult)result; } else { TraceIf(_retries > 0 && i > 0, "Retry {0}/{1} passed successfully.", i, _retries); break; } } catch (Exception ex) { TraceIf(_retries > 0, "Retry {0}/{1} failed with {2}", i, _retries, ex); // optimize to preserve stacktrace if (i >= _retries) { throw; } if (exception == null) { exception = ex; } } } if (_suppressError && result is PassedResult) { return(result); } if (exception != null) { ExceptionUtility.RethrowWithNoStackTraceLoss(exception); } return(failedResult ?? result); }
public override void Close() { Stats.CommandRowCount(ConnectionId, CommandId, RowCount); var inner = this.InnerDataReader as SqlDataReader; if (!Disposed && inner != null && InnerCommand.Transaction == null && inner.Read()) { InnerCommand.Cancel(); } Disposed = true; this.InnerDataReader.Close(); }
public override object ExecuteScalar() { try { _txnlock.OpenReader(); _txnlock.BeginCommand(this); return(InnerCommand.ExecuteScalar()); } finally { _txnlock.EndCommand(); _txnlock.CloseReader(); } }
public override MethodResult Execute(object testClass) { MethodResult result = null; try { result = InnerCommand.Execute(testClass); } catch (Exception ex) { result = new FailedResult(_method, ex, DisplayName); } return(result); }