/// <summary>
 ///     Construct a state machine with external state storage.
 /// </summary>
 /// <param name="stateAccessor">A function that will be called to read the current state value.</param>
 /// <param name="stateMutator">An action that will be called to write new state values.</param>
 public StateMachine(Func <TState> stateAccessor, Action <TState> stateMutator)
 {
     _stateAccessor = Enforce.ArgumentNotNull(stateAccessor, "stateAccessor");
     _stateMutator  = Enforce.ArgumentNotNull(stateMutator, "stateMutator");
 }
 private StateConfiguration InternalPermitIf(TTrigger trigger, TState destinationState, Func <bool> guard)
 {
     Enforce.ArgumentNotNull(guard, "guard");
     _representation.AddTriggerBehaviour(new TransitioningTriggerBehaviour(trigger, destinationState, guard));
     return(this);
 }
 /// <summary>
 ///     Transition from the current state via the specified trigger.
 ///     The target state is determined by the configuration of the current state.
 ///     Actions associated with leaving the current state and entering the new one
 ///     will be invoked.
 /// </summary>
 /// <typeparam name="TArg0">Type of the first trigger argument.</typeparam>
 /// <typeparam name="TArg1">Type of the second trigger argument.</typeparam>
 /// <typeparam name="TArg2">Type of the third trigger argument.</typeparam>
 /// <param name="arg0">The first argument.</param>
 /// <param name="arg1">The second argument.</param>
 /// <param name="arg2">The third argument.</param>
 /// <param name="trigger">The trigger to fire.</param>
 /// <exception cref="System.InvalidOperationException">
 ///     The current state does
 ///     not allow the trigger to be fired.
 /// </exception>
 public void Fire <TArg0, TArg1, TArg2>(TriggerWithParameters <TArg0, TArg1, TArg2> trigger, TArg0 arg0, TArg1 arg1,
                                        TArg2 arg2)
 {
     Enforce.ArgumentNotNull(trigger, "trigger");
     InternalFire(trigger.Trigger, arg0, arg1, arg2);
 }
 /// <summary>
 ///     Specify an action that will execute when transitioning from
 ///     the configured state.
 /// </summary>
 /// <param name="exitAction">Action to execute, providing details of the transition.</param>
 /// <returns>The receiver.</returns>
 public StateConfiguration OnExit(Action <Transition> exitAction)
 {
     Enforce.ArgumentNotNull(exitAction, "exitAction");
     _representation.AddExitAction(exitAction);
     return(this);
 }
 /// <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>
 /// <param name="guard">
 ///     Function that must return true in order for the
 ///     trigger to be accepted.
 /// </param>
 /// <returns>The reciever.</returns>
 public StateConfiguration PermitDynamicIf(TTrigger trigger, Func <TState> destinationStateSelector, Func <bool> guard)
 {
     Enforce.ArgumentNotNull(destinationStateSelector, "destinationStateSelector");
     return(InternalPermitDynamicIf(trigger, args => destinationStateSelector(), guard));
 }
 internal StateConfiguration(StateRepresentation representation, Func <TState, StateRepresentation> lookup)
 {
     _representation = Enforce.ArgumentNotNull(representation, "representation");
     _lookup         = Enforce.ArgumentNotNull(lookup, "lookup");
 }
 /// <summary>
 ///     Specify an action that will execute when transitioning from
 ///     the configured state.
 /// </summary>
 /// <param name="exitAction">Action to execute.</param>
 /// <returns>The receiver.</returns>
 public StateConfiguration OnExit(Action exitAction)
 {
     Enforce.ArgumentNotNull(exitAction, "exitAction");
     return(OnExit(t => exitAction()));
 }
 /// <summary>
 ///     Specify an action that will execute when transitioning into
 ///     the configured state.
 /// </summary>
 /// <param name="entryAction">Action to execute, providing details of the transition.</param>
 /// <param name="trigger">The trigger by which the state must be entered in order for the action to execute.</param>
 /// <returns>The receiver.</returns>
 public StateConfiguration OnEntryFrom(TTrigger trigger, Action <Transition> entryAction)
 {
     Enforce.ArgumentNotNull(entryAction, "entryAction");
     _representation.AddEntryAction(trigger, (t, args) => entryAction(t));
     return(this);
 }
 /// <summary>
 ///     Specify an action that will execute when transitioning into
 ///     the configured state.
 /// </summary>
 /// <typeparam name="TArg0">Type of the first trigger argument.</typeparam>
 /// <typeparam name="TArg1">Type of the second trigger argument.</typeparam>
 /// <typeparam name="TArg2">Type of the third trigger argument.</typeparam>
 /// <param name="entryAction">Action to execute, providing details of the transition.</param>
 /// <param name="trigger">The trigger by which the state must be entered in order for the action to execute.</param>
 /// <returns>The receiver.</returns>
 public StateConfiguration OnEntryFrom <TArg0, TArg1, TArg2>(TriggerWithParameters <TArg0, TArg1, TArg2> trigger,
                                                             Action <TArg0, TArg1, TArg2> entryAction)
 {
     Enforce.ArgumentNotNull(entryAction, "entryAction");
     return(OnEntryFrom(trigger, (a0, a1, a2, t) => entryAction(a0, a1, a2)));
 }
 /// <summary>
 ///     Specify an action that will execute when transitioning into
 ///     the configured state.
 /// </summary>
 /// <param name="entryAction">Action to execute.</param>
 /// <returns>The receiver.</returns>
 public StateConfiguration OnEntry(Action entryAction)
 {
     Enforce.ArgumentNotNull(entryAction, "entryAction");
     return(OnEntry(t => entryAction()));
 }
 /// <summary>
 ///     Specify an action that will execute when transitioning into
 ///     the configured state.
 /// </summary>
 /// <param name="entryAction">Action to execute.</param>
 /// <param name="trigger">The trigger by which the state must be entered in order for the action to execute.</param>
 /// <returns>The receiver.</returns>
 public StateConfiguration OnEntryFrom(TTrigger trigger, Action entryAction)
 {
     Enforce.ArgumentNotNull(entryAction, "entryAction");
     return(OnEntryFrom(trigger, t => entryAction()));
 }
 /// <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);
 }
            /// <summary>
            ///     Ensure that the supplied arguments are compatible with those configured for this
            ///     trigger.
            /// </summary>
            /// <param name="args"></param>
            public void ValidateParameters(object[] args)
            {
                Enforce.ArgumentNotNull(args, "args");

                ParameterConversion.Validate(args, _argumentTypes);
            }
Beispiel #14
0
 public void AddSubstate(StateRepresentation substate)
 {
     Enforce.ArgumentNotNull(substate, "substate");
     _substates.Add(substate);
 }
Beispiel #15
0
 public void AddExitAction(Action <Transition> action)
 {
     _exitActions.Add(Enforce.ArgumentNotNull(action, "action"));
 }
Beispiel #16
0
 public void AddEntryAction(Action <Transition, object[]> action)
 {
     _entryActions.Add(Enforce.ArgumentNotNull(action, "action"));
 }