public async Task Save(UserIterationResult iterationResult) { var iterationDto = new IterationDto { Iteration = iterationResult.Iteration, BaseUrl = iterationResult.BaseUrl, DidError = iterationResult.DidError, Elapsed = iterationResult.Elapsed.Ticks, StartTick = iterationResult.StartTick, EndTick = iterationResult.EndTick, Exception = iterationResult.Exception, TestName = iterationResult.TestName, UserNumber = iterationResult.UserNumber, UserDelay = iterationResult.UserDelay }; _dbConnection.Open(); using (var transaction = _dbConnection.BeginTransaction()) { var iterationId = await _dbConnection.InsertAsync(iterationDto); var inserts = iterationResult.StatusResults.Select(httpStatusResult => new HttpStatusResultDto() { IterationId = iterationId, ElapsedMilliseconds = httpStatusResult.ElapsedMilliseconds, Method = httpStatusResult.Method, RequestUrl = httpStatusResult.RequestUrl, StatusCode = httpStatusResult.StatusCode, RequestStartTick = httpStatusResult.RequestStartTick }); await _dbConnection.InsertAsync(inserts); transaction.Commit(); } }
public void Queue(UserIterationResult result) { _queue.Enqueue(result); _signal.Release(); }
public void Queue(UserIterationResult result) { _queue.Enqueue(result); }
public async Task Save(UserIterationResult iterationResult) { var iterationDto = new IterationDto { Iteration = iterationResult.Iteration, BaseUrl = iterationResult.BaseUrl, DidError = iterationResult.DidError, StartedMs = iterationResult.StartedTime.TotalMilliseconds, ElapsedMs = iterationResult.Elapsed.TotalMilliseconds, Exception = iterationResult.Exception, TestName = iterationResult.TestName, UserNumber = iterationResult.UserNumber, UserDelay = iterationResult.UserDelay }; const string sql = @"INSERT INTO [Iteration] ([Iteration], [BaseUrl], [DidError], [ElapsedMs], [StartedMs], [Exception], [TestName], [UserNumber], [UserDelay]) values (@Iteration, @BaseUrl, @DidError, @ElapsedMs, @StartedMs, @Exception, @TestName, @UserNumber, @UserDelay); SELECT last_insert_rowid();"; long iterationId; if (_insertIteration == null) { _insertIteration = _dbConnection.CreateCommand(); _insertIteration.CommandText = sql; _iteration = _insertIteration.CreateParameter(); _iteration.DbType = DbType.Int32; _iteration.ParameterName = "@Iteration"; _insertIteration.Parameters.Add(_iteration); _baseUrl = _insertIteration.CreateParameter(); _baseUrl.DbType = DbType.String; _baseUrl.ParameterName = "@BaseUrl"; _insertIteration.Parameters.Add(_baseUrl); _didError = _insertIteration.CreateParameter(); _didError.DbType = DbType.Boolean; _didError.ParameterName = "@DidError"; _insertIteration.Parameters.Add(_didError); _elapsedMs = _insertIteration.CreateParameter(); _elapsedMs.DbType = DbType.Double; _elapsedMs.ParameterName = "@ElapsedMs"; _insertIteration.Parameters.Add(_elapsedMs); _startedMs = _insertIteration.CreateParameter(); _startedMs.DbType = DbType.Double; _startedMs.ParameterName = "@StartedMs"; _insertIteration.Parameters.Add(_startedMs); _exception = _insertIteration.CreateParameter(); _exception.DbType = DbType.String; _exception.ParameterName = "@Exception"; _insertIteration.Parameters.Add(_exception); _testName = _insertIteration.CreateParameter(); _testName.DbType = DbType.String; _testName.ParameterName = "@TestName"; _insertIteration.Parameters.Add(_testName); _userNumber = _insertIteration.CreateParameter(); _userNumber.DbType = DbType.Int32; _userNumber.ParameterName = "@UserNumber"; _insertIteration.Parameters.Add(_userNumber); _userDelay = _insertIteration.CreateParameter(); _userDelay.DbType = DbType.Int64; _userDelay.ParameterName = "@UserDelay"; _insertIteration.Parameters.Add(_userDelay); _insertIteration.Prepare(); } _iteration.Value = iterationDto.Iteration; _baseUrl.Value = iterationDto.BaseUrl; _didError.Value = iterationDto.DidError; _elapsedMs.Value = iterationDto.ElapsedMs; _startedMs.Value = iterationDto.StartedMs; _exception.Value = iterationDto.Exception as object ?? DBNull.Value; _testName.Value = iterationDto.TestName; _userNumber.Value = iterationDto.UserNumber; _userDelay.Value = iterationDto.UserDelay; iterationId = (long)await _insertIteration.ExecuteScalarAsync(); var inserts = iterationResult.StatusResults.Select(httpStatusResult => new HttpStatusResultDto { IterationId = (int)iterationId, ElapsedMilliseconds = httpStatusResult.ElapsedMilliseconds, Method = httpStatusResult.Method, RequestUrl = httpStatusResult.RequestUrl, StatusCode = httpStatusResult.StatusCode, RequestStartedMs = httpStatusResult.RequestStartedMs }); await InsertResults(inserts); }
public async Task Save(UserIterationResult iterationResult) { var iterationDto = new IterationDto { Iteration = iterationResult.Iteration, BaseUrl = iterationResult.BaseUrl, DidError = iterationResult.DidError, Elapsed = iterationResult.Elapsed.Ticks, StartTick = iterationResult.StartTick, EndTick = iterationResult.EndTick, Exception = iterationResult.Exception, TestName = iterationResult.TestName, UserNumber = iterationResult.UserNumber, UserDelay = iterationResult.UserDelay }; const string sql = @"INSERT INTO [Iteration] ([Iteration], [BaseUrl], [DidError], [Elapsed], [StartTick], [EndTick], [Exception], [TestName], [UserNumber], [UserDelay]) values (@Iteration, @BaseUrl, @DidError, @Elapsed, @StartTick, @EndTick, @Exception, @TestName, @UserNumber, @UserDelay); SELECT last_insert_rowid();"; if (_dbConnection.State != ConnectionState.Open) { await _dbConnection.OpenAsync(); } //using (MonitorLock.CreateLock(_obj, _dbConnection.ConnectionString)) { await RawExecuteAsync("BEGIN TRANSACTION"); try { var cmd = new CommandDefinition(sql, iterationDto); var iterationId = await _dbConnection.ExecuteScalarAsync <int>(cmd); var inserts = iterationResult.StatusResults.Select(httpStatusResult => new HttpStatusResultDto { IterationId = iterationId, ElapsedMilliseconds = httpStatusResult.ElapsedMilliseconds, Method = httpStatusResult.Method, RequestUrl = httpStatusResult.RequestUrl, StatusCode = httpStatusResult.StatusCode, RequestStartTick = httpStatusResult.RequestStartTick }); foreach (var batch in inserts.Batch(100)) { await InsertHttpStatusResults(batch, batch.Count); } await RawExecuteAsync("COMMIT TRANSACTION"); } catch (Exception) { await RawExecuteAsync("ROLLBACK TRANSACTION"); throw; } } }