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; }
public TCStateChangedEventArgs(TransactionContextState fromState) { this.FromState = fromState; }
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); } }
internal void VoteRollbackFromChild() { _stateFromChildren = TransactionContextState.ToBeRollbacked; }
internal void VoteCommitFromChild() { _stateFromChildren = TransactionContextState.ToBeCommitted; }
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); }
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); }
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); }
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; }
/// <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)); }