Skip to content

Commit

Permalink
Fixed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jinan-agoda committed Mar 5, 2024
1 parent 18f1b8d commit 4e9dc6f
Showing 1 changed file with 41 additions and 38 deletions.
79 changes: 41 additions & 38 deletions Agoda.Frameworks.DB/DbRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,55 +311,58 @@ public Task<T> ExecuteReaderAsync<T>(
{
var stopwatch = Stopwatch.StartNew();
Exception error = null;
var cancellationTokenSource = new CancellationTokenSource();
cancellationTokenSource.CancelAfter(taskCancellationTimeOutInMilliSecs);
try
using (var cancellationTokenSource = new CancellationTokenSource())
{
using (var connection = _generateConnection(connectionStr))
cancellationTokenSource.CancelAfter(taskCancellationTimeOutInMilliSecs);
try
{
if (connection is SqlConnection sqlConn)
using (var connection = _generateConnection(connectionStr))
{
await sqlConn.OpenAsync();
}
else
{
connection.Open();
}
SqlCommand sqlCommand = null;
try
{
sqlCommand = new SqlCommand(storedProc, connection as SqlConnection)
if (connection is SqlConnection sqlConn)
{
CommandType = CommandType.StoredProcedure,
CommandTimeout = timeoutSecs
};
sqlCommand.Parameters.AddRange(parameters);
using (var reader = await sqlCommand.ExecuteReaderAsync(cancellationTokenSource.Token))
await sqlConn.OpenAsync(cancellationTokenSource.Token);
}
else
{
return await callback(reader);
connection.Open();
}
}
finally
{
if (sqlCommand != null)
SqlCommand sqlCommand = null;
try
{
sqlCommand.Parameters.Clear();
sqlCommand.Dispose();
sqlCommand = new SqlCommand(storedProc, connection as SqlConnection)
{
CommandType = CommandType.StoredProcedure,
CommandTimeout = timeoutSecs
};
sqlCommand.Parameters.AddRange(parameters);
using (var reader = await sqlCommand.ExecuteReaderAsync(cancellationTokenSource.Token))
{
return await callback(reader);
}
}
finally
{
if (sqlCommand != null)
{
sqlCommand.Parameters.Clear();
sqlCommand.Dispose();
}
}
}
}
catch (Exception e)
{
error = e;
throw;
}
finally
{
stopwatch.Stop();
RaiseOnExecuteReaderComplete(
database, storedProc, stopwatch.ElapsedMilliseconds, error);
}
}
catch (Exception e)
{
error = e;
throw;
}
finally
{
stopwatch.Stop();
RaiseOnExecuteReaderComplete(
database, storedProc, stopwatch.ElapsedMilliseconds, error);
}
}, ShouldRetry(maxAttemptCount), RaiseOnError);
}

Expand Down

0 comments on commit 4e9dc6f

Please sign in to comment.