internal EnlistmentContext(Transaction transaction, EnlistmentPhase phase)
		{
			if(transaction == null)
				throw new ArgumentNullException("transaction");

			_transaction = transaction;
			_phase = phase;
		}
Пример #2
0
        internal EnlistmentContext(Transaction transaction, EnlistmentPhase phase)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException("transaction");
            }

            _transaction = transaction;
            _phase       = phase;
        }
Пример #3
0
        private void DoEnlistment(EnlistmentPhase phase)
        {
            var isCompleted = System.Threading.Interlocked.Exchange(ref _isCompleted, 1);

            if (isCompleted != 0)
            {
                return;
            }

            //如果当前事务是跟随模式,并且具有父事务则当前事务不用通知投票者(订阅者),而是交由父事务处理
            if (_behavior == TransactionBehavior.Followed && _parent != null)
            {
                switch (phase)
                {
                case EnlistmentPhase.Abort:
                    _parent._operation = OPERATION_ABORT;
                    break;

                case EnlistmentPhase.Rollback:
                    _parent._operation = OPERATION_ROLLBACK;
                    break;
                }

                //更新当前事务的状态
                this.UpdateStatus(phase);

                //退出当前子事务
                return;
            }

            switch (_operation)
            {
            case OPERATION_ABORT:
                phase = EnlistmentPhase.Abort;
                break;

            case OPERATION_ROLLBACK:
                phase = EnlistmentPhase.Rollback;
                break;
            }

            while (_enlistments.Count > 0)
            {
                var enlistment = _enlistments.Dequeue();

                enlistment.OnEnlist(new EnlistmentContext(this, phase));
            }

            //更新当前事务的状态
            this.UpdateStatus(phase);
        }
Пример #4
0
        private void UpdateStatus(EnlistmentPhase phase)
        {
            switch (phase)
            {
            case EnlistmentPhase.Abort:
            case EnlistmentPhase.Rollback:
                _status = TransactionStatus.Aborted;
                break;

            case EnlistmentPhase.Commit:
                _status = TransactionStatus.Committed;
                break;

            default:
                _status = TransactionStatus.Undetermined;
                break;
            }
        }
		internal EnlistmentContext(Transaction transaction, EnlistmentPhase phase)
		{
			_transaction = transaction;
			_phase = phase;
		}