private async ValueTask DisposeImpl(bool isAsync)
        {
            if (isDisposed)
            {
                return;
            }

            isDisposed = true;
            try {
                if (Transaction == null || !Transaction.State.IsActive())
                {
                    return;
                }

                if (IsCompleted)
                {
                    await Transaction.Commit(isAsync).ConfigureAwait(false);
                }
                else
                {
                    await Transaction.Rollback(isAsync).ConfigureAwait(false);
                }
            }
            finally {
                try {
                    disposable.DisposeSafely(true);
                }
                finally {
                    disposable = null;
                }
            }
        }
 /// <inheritdoc/>
 public void Dispose()
 {
     if (isDisposed)
     {
         return;
     }
     isDisposed = true;
     try {
         if (Transaction == null || !Transaction.State.IsActive())
         {
             return;
         }
         if (IsCompleted)
         {
             Transaction.Commit();
         }
         else
         {
             Transaction.Rollback();
         }
     }
     finally {
         try {
             disposable.DisposeSafely(true);
         }
         finally {
             disposable = null;
         }
     }
 }
        public void ReturnsFalseForNullDisposable()
        {
            IDisposable disposable = null;
            var         result     = disposable.DisposeSafely();

            Assert.IsFalse(result);
        }
예제 #4
0
        public void Test_DisposeSafely_DoesNotThrow_ForNull()
        {
            // Arrange.
            IDisposable disposable = null;

            // Act/Assert.
            Assert.DoesNotThrow(() => disposable.DisposeSafely());
        }
예제 #5
0
 /// <summary>
 /// Completes request processing.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 protected virtual void EndRequest(object sender, EventArgs e)
 {
     lock (provideSessionLock)
         try {
             resource.DisposeSafely();
         }
         finally {
             resource = null;
             session  = null;
         }
 }
예제 #6
0
 /// <summary>
 /// Calls <see cref="IDisposable.Dispose"/> within a try/catch and logs any errors.
 /// </summary>
 /// <param name="disposable">The <see cref="IDisposable"/> to be disposed</param>
 /// <returns>True if the object was successfully disposed, false if an error was thrown</returns>
 public static bool DisposeSafely(this IDisposable disposable)
 {
     return(disposable.DisposeSafely(error => Log.Error(error)));
 }