Exemplo n.º 1
0
 /// <summary>
 /// Begin a transaction.
 /// </summary>
 /// <returns></returns>
 public static DisposableAction BeginTransaction()
 {
     OnTransactionOpening();
     if (!IsInTransaction)
     {
         List <Transaction> transactions = new List <Transaction>();
         CurrentContext.SetData(TransactionScopeKey, transactions);
     }
     CurrentTransactionList.Add(new Transaction(DateTime.Now));
     OnTransactionOpened();
     return(new DisposableAction(CloseCurrentTransaction));
 }
Exemplo n.º 2
0
        /// <summary>
        /// Close current transaction, this function is private because is used inside a DisposableAction.
        /// We need to check if are inside an exception handler to doom the transaction, then we need to
        /// remove the global transaction from the context and committ it.
        /// </summary>
        private static void CloseCurrentTransaction()
        {
            Verify.That(IsInTransaction, "Cannot doom the transaction because there is not an active transaction");
            if (Utils.ExceptionUtils.IsInExceptionHandler())
            {
                CurrentTransaction.Doom();
            }
            Boolean IsDoomed = CurrentTransaction.IsDoomed;

            OnTransactionClosing(IsDoomed);
            Transaction currentTransaction = CurrentTransaction;

            CurrentTransactionList.RemoveAt(CurrentTransactionList.Count - 1);
            if (CurrentTransactionList.Count == 0)
            {
                CurrentContext.ReleaseData(TransactionScopeKey);
            }
            currentTransaction.Complete();
            OnTransactionClosed(IsDoomed);
        }