@@ -23,41 +23,36 @@ public QueueCreator(ISqlConstants sqlConstants, DbConnectionFactory connectionFa
2323
2424 public async Task CreateQueueIfNecessary ( string [ ] queueAddresses , CanonicalQueueAddress delayedQueueAddress , CancellationToken cancellationToken = default )
2525 {
26- using ( var connection = await connectionFactory . OpenNewConnection ( cancellationToken ) . ConfigureAwait ( false ) )
26+ using var connection = await connectionFactory . OpenNewConnection ( cancellationToken ) . ConfigureAwait ( false ) ;
27+ foreach ( var address in queueAddresses )
2728 {
28- foreach ( var address in queueAddresses )
29- {
30- await CreateQueue ( sqlConstants . CreateQueueText , addressTranslator ( address ) , connection , createMessageBodyColumn , cancellationToken ) . ConfigureAwait ( false ) ;
31- }
29+ await CreateQueue ( sqlConstants . CreateQueueText , addressTranslator ( address ) , connection , createMessageBodyColumn , cancellationToken ) . ConfigureAwait ( false ) ;
30+ }
3231
33- if ( delayedQueueAddress != null )
34- {
35- await CreateQueue ( sqlConstants . CreateDelayedMessageStoreText , delayedQueueAddress , connection , createMessageBodyColumn , cancellationToken ) . ConfigureAwait ( false ) ;
36- }
32+ if ( delayedQueueAddress != null )
33+ {
34+ await CreateQueue ( sqlConstants . CreateDelayedMessageStoreText , delayedQueueAddress , connection , createMessageBodyColumn , cancellationToken ) . ConfigureAwait ( false ) ;
3735 }
3836 }
3937
4038 async Task CreateQueue ( string creationScript , CanonicalQueueAddress canonicalQueueAddress , DbConnection connection , bool createMessageBodyColumn , CancellationToken cancellationToken )
4139 {
4240 try
4341 {
44- using ( var transaction = connection . BeginTransaction ( ) )
45- {
46- var tableName = canonicalQueueAddress . QualifiedTableName ;
42+ using var transaction = await connection . BeginTransactionAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
43+ var tableName = canonicalQueueAddress . QualifiedTableName ;
4744
48- var sql = string . Format ( creationScript , tableName , canonicalQueueAddress . Table ) ;
49- using ( var command = connection . CreateCommand ( ) )
50- {
51- command . Transaction = transaction ;
52- command . CommandText = sql ;
53- command . CommandType = CommandType . Text ;
54-
55- await command . ExecuteNonQueryAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
56-
57- }
45+ var sql = string . Format ( creationScript , tableName , canonicalQueueAddress . Table ) ;
46+ using ( var command = connection . CreateCommand ( ) )
47+ {
48+ command . Transaction = transaction ;
49+ command . CommandText = sql ;
50+ command . CommandType = CommandType . Text ;
5851
59- transaction . Commit ( ) ;
52+ await command . ExecuteNonQueryAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
6053 }
54+
55+ await transaction . CommitAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
6156 }
6257 catch ( OperationCanceledException ) when ( cancellationToken . IsCancellationRequested )
6358 {
@@ -75,19 +70,17 @@ async Task CreateQueue(string creationScript, CanonicalQueueAddress canonicalQue
7570 var advisoryLockId = CalculateLockId ( canonicalQueueAddress . QualifiedTableName ) ;
7671 var bodyStringSql = string . Format ( sqlConstants . AddMessageBodyStringColumn , canonicalQueueAddress . Schema , canonicalQueueAddress . Table , advisoryLockId ) ;
7772
78- using ( var transaction = connection . BeginTransaction ( ) )
73+ using var transaction = await connection . BeginTransactionAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
74+ using ( var command = connection . CreateCommand ( ) )
7975 {
80- using ( var command = connection . CreateCommand ( ) )
81- {
82- command . Transaction = transaction ;
83- command . CommandText = bodyStringSql ;
84- command . CommandType = CommandType . Text ;
85-
86- await command . ExecuteNonQueryAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
87- }
76+ command . Transaction = transaction ;
77+ command . CommandText = bodyStringSql ;
78+ command . CommandType = CommandType . Text ;
8879
89- transaction . Commit ( ) ;
80+ await command . ExecuteNonQueryAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
9081 }
82+
83+ await transaction . CommitAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
9184 }
9285 }
9386
0 commit comments