public InvalidContextStateException(
			TransactionContextState currentState, TransactionContextState[] allowedStates, string message)
            : base(message)
        {
            _currentState = currentState;
            _allowedStates = allowedStates;
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="TransactionContextStateChangedEventArgs"/> class.
		/// </summary>
		/// <param name="oldState">The old transaction context state.</param>
		/// <param name="newState">The new transaction context state.</param>
		public TransactionContextStateChangedEventArgs(TransactionContextState oldState, TransactionContextState newState)
			: base()
		{
			this.OldState = oldState;
			this.NewState = newState;
		}
Пример #3
0
 public TCStateChangedEventArgs(TransactionContextState fromState)
 {
     this.FromState = fromState;
 }
Пример #4
0
 private void RaiseStateChangedEvent(TransactionContextState fromState)
 {
     try
     {
         if(this.StateChanged != null)
             this.StateChanged(this, new TCStateChangedEventArgs(fromState));
     }
     catch(Exception e)
     {
         throw new TransactionContextException(ResourceStringLoader.GetResourceString(
             "error_executing_transaction"), e);
     }
 }
Пример #5
0
 internal void VoteRollbackFromChild()
 {
     _stateFromChildren = TransactionContextState.ToBeRollbacked;
 }
Пример #6
0
 internal void VoteCommitFromChild()
 {
     _stateFromChildren = TransactionContextState.ToBeCommitted;
 }
Пример #7
0
        public virtual void VoteRollback()
        {
            if(_state != TransactionContextState.Entered
                && _state != TransactionContextState.ToBeCommitted
                && _state != TransactionContextState.ToBeRollbacked)
                    throw new InvalidContextStateException(_state,
                        new TransactionContextState[] {
                            TransactionContextState.Entered,
                            TransactionContextState.ToBeCommitted,
                            TransactionContextState.ToBeRollbacked
                        },
                        ResourceStringLoader.GetResourceString("invalid_context_state"));

            TransactionContextState fromState = _state;

            _state = TransactionContextState.ToBeRollbacked;
            TransactionContext contrCtx = this.GetControllingContext();
            if(contrCtx != null && contrCtx != this) contrCtx.VoteRollbackFromChild();

            RaiseStateChangedEvent(fromState);
        }
Пример #8
0
        public virtual void VoteCommit()
        {
            if(_state != TransactionContextState.Entered
                && _state != TransactionContextState.ToBeCommitted)
                throw new InvalidContextStateException(_state, new TransactionContextState[] { TransactionContextState.Entered, TransactionContextState.ToBeCommitted }, "Context should be in one of the following states in VoteCommit - {Entered, ToBeCommitted}.");

            TransactionContextState fromState = _state;

            _state = TransactionContextState.ToBeCommitted;
            TransactionContext contrCtx = this.GetControllingContext();
            if(contrCtx != null && contrCtx != this) contrCtx.VoteCommitFromChild();

            RaiseStateChangedEvent(fromState);
        }
Пример #9
0
        public virtual void Exit()
        {
            if(_state != TransactionContextState.Entered
                && _state != TransactionContextState.ToBeCommitted
                && _state != TransactionContextState.ToBeRollbacked)
                    throw new InvalidContextStateException(_state, new TransactionContextState[] { TransactionContextState.Entered, TransactionContextState.ToBeCommitted, TransactionContextState.ToBeRollbacked }, "Context should be in one of the following states in Exit - {Entered, ToBeCommitted, ToBeRollbacked}.");

            TransactionContextState fromState = _state;

            CallContext.SetData(THREAD_CURRENT_CONTEXT__KEY, parentContext);
            _state = TransactionContextState.Exitted;

            RaiseStateChangedEvent(fromState);
        }
Пример #10
0
        public virtual TransactionContext Enter()
        {
            if(_state != TransactionContextState.Created
                && _state != TransactionContextState.Exitted)
                throw new InvalidContextStateException(_state, new TransactionContextState[] { TransactionContextState.Created, TransactionContextState.Exitted }, "Context should be in one of the following states in Enter - {Created, Exitted}.");

            TransactionContextState fromState = _state;

            parentContext = CallContext.GetData(THREAD_CURRENT_CONTEXT__KEY) as TransactionContext;
            CallContext.SetData(THREAD_CURRENT_CONTEXT__KEY, this);
            _state = TransactionContextState.Entered;

            RaiseStateChangedEvent(fromState);

            return this;
        }
Пример #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TransactionContextStateChangedEventArgs"/> class.
 /// </summary>
 /// <param name="oldState">The old transaction context state.</param>
 /// <param name="newState">The new transaction context state.</param>
 public TransactionContextStateChangedEventArgs(TransactionContextState oldState, TransactionContextState newState)
     : base()
 {
     this.OldState = oldState;
     this.NewState = newState;
 }
Пример #12
0
 /// <summary>
 /// Raises the <see cref="StateChanged"/> event.
 /// </summary>
 /// <param name="previousState">The previous transaction context state.</param>
 /// <param name="newState">The new transaction context state.</param>
 private void OnStateChanged(TransactionContextState previousState, TransactionContextState newState)
 {
     this.StateChanged?.Invoke(this, new TransactionContextStateChangedEventArgs(previousState, newState));
 }
Пример #13
0
		/// <summary>
		/// Raises the <see cref="StateChanged"/> event.
		/// </summary>
		/// <param name="previousState">The previous transaction context state.</param>
		/// <param name="newState">The new transaction context state.</param>
		private void OnStateChanged(TransactionContextState previousState, TransactionContextState newState)
		{
			this.StateChanged?.Invoke(this, new TransactionContextStateChangedEventArgs(previousState, newState));
		}