Beispiel #1
0
    private TxEnlistment GetEnlistment()
    {
      var tx = Transaction.Current;
      TxEnlistment enlistment;

      if (TxEnabled && tx != null)
      {
        lock (_enlistmentsLock)
        {
          if (_enlistments == null)
          {
            _enlistments = new Dictionary<string, TxEnlistment>();
          }

          if (_enlistments.ContainsKey(tx.TransactionInformation.LocalIdentifier))
          {
            enlistment = _enlistments[tx.TransactionInformation.LocalIdentifier];
          }
          else
          {
            enlistment = new TxEnlistment(tx);
            enlistment.IgnoreExceptionsInRollback = IgnoreExceptionsInRollback;
            _enlistments.Add(tx.TransactionInformation.LocalIdentifier, enlistment);
          }
        }
      }
      else
      {
        enlistment = new TxEnlistment();
      }

      return enlistment;
    }
Beispiel #2
0
        private static void EnlistOperation(IRollbackableOperation operation)
        {
            Transaction tx = Transaction.Current;
            TxEnlistment enlistment;

            lock (_enlistmentsLock)
            {
                if (_enlistments == null)
                {
                    _enlistments = new Dictionary<string, TxEnlistment>();
                }

                if (!_enlistments.TryGetValue(tx.TransactionInformation.LocalIdentifier, out enlistment))
                {
                    enlistment = new TxEnlistment(tx);
                    _enlistments.Add(tx.TransactionInformation.LocalIdentifier, enlistment);
                }
                enlistment.EnlistOperation(operation);
            }
        }