/// <summary> /// Transition to a given state /// </summary> /// <param name="newState"><see cref="State"/> to transition to</param> /// <exception cref="InvalidSagaStateTransitionException">Thrown if transition is not allowed</exception> public void TransitionTo(State newState) { if(!CanTransitionTo(newState)) throw new InvalidSagaStateTransitionException(string.Format("Cannot transition from State [{0}] to State [{1}]",_currentState.GetType().FullName, newState.GetType().FullName)); _currentState = newState; }
/// <summary> /// Check if this state can transition to a specified state /// </summary> /// <param name="state"><see cref="State"/> to check if can transition to</param> /// <returns>true if it can transition, false if not</returns> public bool CanTransitionTo(State state) { return _canTransitionTo.Contains(state); }
/// <summary> /// Check if a transition is allowed /// </summary> /// <param name="newState"><see cref="State"/> to check if is allowed</param> /// <returns>true if transition is allowed, false if not</returns> public bool CanTransitionTo(State newState) { return _currentState.CanTransitionTo(newState); }
/// <summary> /// Initializes a new instance of <see cref="SagaState"/> with a current state /// </summary> /// <param name="currentState"><see cref="State">Current state</see> to set</param> public SagaState(State currentState) { _currentState = currentState; }