private Task <T> RunTransactionAsync <T>(AccessMode mode, Func <IAsyncTransaction, Task <T> > work,
                                                 Action <TransactionConfigBuilder> action)
        {
            return(TryExecuteAsync(_logger, async() => await _retryLogic.RetryAsync(async() =>
            {
                var tx = await BeginTransactionWithoutLoggingAsync(mode, action, true).ConfigureAwait(false);
                try
                {
                    var result = await work(tx).ConfigureAwait(false);
                    if (tx.IsOpen)
                    {
                        await tx.CommitAsync().ConfigureAwait(false);
                    }

                    return result;
                }
                catch
                {
                    if (tx.IsOpen)
                    {
                        await tx.RollbackAsync().ConfigureAwait(false);
                    }

                    throw;
                }
            }).ConfigureAwait(false)));
        }
Esempio n. 2
0
 private Task <T> RunTransactionAsync <T>(AccessMode mode, Func <IAsyncTransaction, Task <T> > work,
                                          TransactionConfig txConfig)
 {
     return(TryExecuteAsync(_logger, async() => await _retryLogic.RetryAsync(async() =>
     {
         var tx = await BeginTransactionWithoutLoggingAsync(mode, txConfig).ConfigureAwait(false);
         {
             try
             {
                 var result = await work(tx).ConfigureAwait(false);
                 await tx.CommitAsync().ConfigureAwait(false);
                 return result;
             }
             catch
             {
                 await tx.RollbackAsync().ConfigureAwait(false);
                 throw;
             }
         }
     }).ConfigureAwait(false)));
 }