/// <summary> /// Ignore the specified trigger when in the configured state, if the guard /// returns true.. /// </summary> /// <param name = "trigger">The trigger to ignore.</param> /// <param name = "guard">Function that must return true in order for the /// trigger to be ignored.</param> /// <returns>The receiver.</returns> public StateConfiguration IgnoreIf(TTrigger trigger, Func <bool> guard) { Enforce.ArgumentNotNull(guard, "guard"); _representation.AddTriggerBehaviour(new IgnoredTriggerBehaviour(trigger, guard)); return(this); }
public IgnoredTriggerBehaviour(TTrigger trigger, Func <bool> guard) : this(trigger, guard, string.Empty) { }
public bool CanHandle(TTrigger trigger) { return(TryFindHandler(trigger, out TriggerBehaviourResult unused)); }
StateConfiguration InternalPermitIf(TTrigger trigger, TState destinationState, Func <bool> guard, string guardDescription) { Enforce.ArgumentNotNull(guard, nameof(guard)); _representation.AddTriggerBehaviour(new TransitioningTriggerBehaviour(trigger, destinationState, guard, guardDescription)); return(this); }
/// <summary> /// Accept the specified trigger, execute exit actions and re-execute entry actions. /// Reentry behaves as though the configured state transitions to an identical sibling state. /// </summary> /// <param name="trigger">The accepted trigger.</param> /// <returns>The reciever.</returns> /// <remarks> /// Applies to the current state only. Will not re-execute superstate actions, or /// cause actions to execute transitioning between super- and sub-states. /// </remarks> public StateConfiguration PermitReentry(TTrigger trigger) { return(InternalPermit(trigger, _representation.UnderlyingState, string.Empty)); }
/// <summary> /// Ignore the specified trigger when in the configured state. /// </summary> /// <param name="trigger">The trigger to ignore.</param> /// <returns>The receiver.</returns> public StateConfiguration Ignore(TTrigger trigger) { return(IgnoreIf(trigger, NoGuard)); }
/// <summary> /// Accept the specified trigger and transition to the destination state. /// </summary> /// <param name="trigger">The accepted trigger.</param> /// <param name="destinationState">The state that the trigger will cause a /// transition to.</param> /// <returns>The reciever.</returns> public StateConfiguration Permit(TTrigger trigger, TState destinationState) { EnforceNotIdentityTransition(destinationState); return(InternalPermit(trigger, destinationState, string.Empty)); }
/// <summary> /// Short for "Transition." Adds a new entry to the state transition table. /// </summary> /// <param name="from">Current state</param> /// <param name="trigger">Trigger</param> /// <param name="to">The state the FSM will transition to.</param> /// <returns><c>this</c></returns> /// <exception cref="System.ArgumentNullException">Any of the /// arguments <paramref name="from"/>, <paramref name="trigger"/>, or /// <paramref name="to"/> is null. /// </exception> public TransitionCompiler Tr(TState from, TTrigger trigger, TState to) { return(compiler.Tr(from, trigger, to)); }
private void transitionState <Targ>(Storage state, Transition <Targ> transition, TTrigger trigger, TMemory memory, Targ arg) { var currentState = state.state; var nextState = transition.Next; state.state = transition.Next; if (transition.Action != null) { transition.Action(currentState, trigger, nextState, memory, arg); } if (onAnyTransitionAction != null) { onAnyTransitionAction(currentState, trigger, nextState, memory); } }
public bool Allowed(TState state, TTrigger trigger) { return (Guard == null || Guard(state, trigger, Next)); }
/// <summary> /// Short for "Transition." Adds a new entry to the state transition table. /// </summary> /// <param name="from">Current state</param> /// <param name="trigger">Trigger</param> /// <param name="to">The state the FSM will transition to.</param> /// <returns><c>this</c></returns> /// <exception cref="System.ArgumentNullException">Any of the /// arguments <paramref name="from"/>, <paramref name="trigger"/>, or /// <paramref name="to"/> is null. /// </exception> public TransitionCompiler <TNewArg> Tr <TNewArg>(TState from, TTrigger trigger, TState to) { return(compiler.Tr <TNewArg>(from, trigger, to)); }
public TransitioningTriggerBehaviour(TTrigger trigger, TState destination, Func <TState, TTrigger, bool> action) : base(trigger, action) { _destination = destination; }
protected TriggerBehaviour(TTrigger trigger, Func <TState, TTrigger, bool> action) { _trigger = trigger; _action = action; }
/// <summary> /// Construct a transition. /// </summary> /// <param name="source">The state transitioned from.</param> /// <param name="destination">The state transitioned to.</param> /// <param name="trigger">The trigger that caused the transition.</param> /// <param name="parameters">The optional trigger parameters</param> public InitialTransition(TState source, TState destination, TTrigger trigger, object[] parameters = null) : base(source, destination, trigger, parameters) { }
public bool CanHandle(TTrigger trigger) { TriggerBehaviour unused; return(TryFindHandler(trigger, out unused)); }
public bool CanHandle(TTrigger trigger, params object[] args) { return(TryFindHandler(trigger, args, out TriggerBehaviourResult unused)); }
public DynamicTriggerBehaviour(TTrigger trigger, Func <object[], TState> destination, Func <bool> guard) : base(trigger, guard) { _destination = Enforce.ArgumentNotNull(destination, "destination"); }
/// <summary> /// Construct a transition. /// </summary> /// <param name="source">The state transitioned from.</param> /// <param name="destination">The state transitioned to.</param> /// <param name="trigger">The trigger that caused the transition.</param> public Transition(TState source, TState destination, TTrigger trigger) { _source = source; _destination = destination; _trigger = trigger; }
/// <summary> /// Accept the specified trigger and transition to the destination state, calculated /// dynamically by the supplied function. /// </summary> /// <param name="trigger">The accepted trigger.</param> /// <param name="destinationStateSelector">Function to calculate the state /// that the trigger will cause a transition to.</param> /// <returns>The reciever.</returns> public StateConfiguration PermitDynamic(TTrigger trigger, Func <TState> destinationStateSelector) { return(PermitDynamicIf(trigger, destinationStateSelector, NoGuard)); }
public InternalTriggerBehaviour(TTrigger trigger) : base(trigger, () => true, "Internal Transition") { }
StateConfiguration InternalPermit(TTrigger trigger, TState destinationState, string guardDescription) { return(InternalPermitIf(trigger, destinationState, () => true, guardDescription)); }
/// <summary> /// TriggerBehaviour constructor /// </summary> /// <param name="trigger"></param> /// <param name="guard">TransitionGuard (null if no guard function)</param> protected TriggerBehaviour(TTrigger trigger, TransitionGuard guard) { _guard = guard ?? TransitionGuard.Empty; Trigger = trigger; }
StateConfiguration InternalPermitDynamic(TTrigger trigger, Func <object[], TState> destinationStateSelector, string guardDescription) { return(InternalPermitDynamicIf(trigger, destinationStateSelector, NoGuard, guardDescription)); }
// Constructor public TriggerConfiguration(TTrigger trigger, StateConfiguration owningStateConfiguration) { _trigger = trigger; _owningStateConfiguration = owningStateConfiguration; }
public IgnoredTriggerBehaviour(TTrigger trigger, Func <bool> guard, string description) : base(trigger, guard, description) { }
public TriggerConfiguration(TTrigger trigger, Func <bool> guardClause, StateConfiguration owningStateConfiguration) { _guardClause = guardClause; _trigger = trigger; _owningStateConfiguration = owningStateConfiguration; }
public void AddEntryAction(TTrigger trigger, Action <Transition, object[]> action, Reflection.InvocationInfo entryActionDescription) { _entryActions.Add(new EntryActionBehavior.SyncFrom <TTrigger>(trigger, action, entryActionDescription)); }
protected TriggerBehaviour(TTrigger trigger, Func <bool> guard) { m_trigger = trigger; m_guard = guard; }
public bool TryFindHandler(TTrigger trigger, out TriggerBehaviourResult handler) { return(TryFindLocalHandler(trigger, out handler) || (Superstate != null && Superstate.TryFindHandler(trigger, out handler))); }
/// <summary> /// Accept the specified trigger, execute exit actions and re-execute entry actions. /// Reentry behaves as though the configured state transitions to an identical sibling state. /// </summary> /// <param name = "trigger">The accepted trigger.</param> /// <param name = "guard">Function that must return true in order for the /// trigger to be accepted.</param> /// <returns>The reciever.</returns> /// <remarks> /// Applies to the current state only. Will not re-execute superstate actions, or /// cause actions to execute transitioning between super- and sub-states. /// </remarks> public StateConfiguration PermitReentryIf(TTrigger trigger, Func <bool> guard) { return(InternalPermitIf(trigger, _representation.UnderlyingState, guard)); }