Exemplo n.º 1
0
        public static object Unpack(object[] args, Type argType, int index)
        {
            Enforce.ArgumentNotNull(args, "args");

            if (args.Length <= index)
            {
                throw new ArgumentException(
                          string.Format(ParameterConversionResources.ArgOfTypeRequiredInPosition, argType, index));
            }

            var arg = args[index];

            if (arg != null && !argType.IsAssignableFrom(arg.GetType()))
            {
                throw new ArgumentException(
                          string.Format(ParameterConversionResources.WrongArgType, index, arg.GetType(), argType));
            }

            return(arg);
        }
 internal Task InternalActionAsync(Transition transition, object[] args)
 {
     Enforce.ArgumentNotNull(transition, "transition");
     return(ExecuteInternalActionsAsync(transition, args));
 }
Exemplo n.º 3
0
 public void AddSubstate(StateRepresentation substate)
 {
     Enforce.ArgumentNotNull(substate, nameof(substate));
     _substates.Add(substate);
 }
 public DynamicTriggerBehaviour(TTrigger trigger, Func <object[], TState> destination, Func <bool> guard, string description)
     : base(trigger, guard, description)
 {
     _destination = Enforce.ArgumentNotNull(destination, "destination");
 }
Exemplo n.º 5
0
 public void AddEntryAction(Action <Transition, object[]> action)
 {
     _entryActions.Add(Enforce.ArgumentNotNull(action, "action"));
 }
Exemplo n.º 6
0
 internal StateConfiguration(StateMachine <TState, TTrigger> machine, StateRepresentation representation, Func <TState, StateRepresentation> lookup)
 {
     _machine        = Enforce.ArgumentNotNull(machine, nameof(machine));
     _representation = Enforce.ArgumentNotNull(representation, nameof(representation));
     _lookup         = Enforce.ArgumentNotNull(lookup, nameof(lookup));
 }
Exemplo n.º 7
0
 internal StateConfiguration(StateRepresentation representation, Func <TState, StateRepresentation> lookup)
 {
     _representation = Enforce.ArgumentNotNull(representation, nameof(representation));
     _lookup         = Enforce.ArgumentNotNull(lookup, nameof(lookup));
 }
Exemplo n.º 8
0
 /// <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);
 }
Exemplo n.º 9
0
 /// <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()));
 }
Exemplo n.º 10
0
 /// <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);
 }
Exemplo n.º 11
0
 public ExitActionBehavior(Action <Transition> action, string actionDescription)
 {
     _action            = action;
     _actionDescription = Enforce.ArgumentNotNull(actionDescription, nameof(actionDescription));
 }
Exemplo n.º 12
0
 /// <summary>
 /// </summary>
 /// <param name="action"></param>
 /// <returns></returns>
 public StateConfiguration OnUnhandled(Action <TState, TTrigger> action)
 {
     Enforce.ArgumentNotNull(action, "action");
     _representation.OnUnhandled = action;
     return(this);
 }
Exemplo n.º 13
0
 protected ExitActionBehavior(string actionDescription)
 {
     _actionDescription = Enforce.ArgumentNotNull(actionDescription, nameof(actionDescription));
 }
Exemplo n.º 14
0
 protected TriggerBehaviour(TTrigger trigger, Func <bool> guard, string guardDescription)
 {
     Trigger          = trigger;
     Guard            = guard;
     GuardDescription = Enforce.ArgumentNotNull(guardDescription, nameof(guardDescription));
 }
Exemplo n.º 15
0
 /// <summary>
 /// Transition from the current state via the specified trigger in async fashion.
 /// 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>
 /// <param name="arg0">The first argument.</param>
 /// <param name="arg1">The second 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 Task FireAsync <TArg0, TArg1>(TriggerWithParameters <TArg0, TArg1> trigger, TArg0 arg0, TArg1 arg1)
 {
     Enforce.ArgumentNotNull(trigger, "trigger");
     return(InternalFireAsync(trigger.Trigger, arg0, arg1));
 }
Exemplo n.º 16
0
 public EntryActionBehavior(Action <Transition, object[]> action, string actionDescription)
 {
     Action            = action;
     ActionDescription = Enforce.ArgumentNotNull(actionDescription, nameof(actionDescription));
 }
Exemplo n.º 17
0
 void ExecuteExitActions(Transition transition)
 {
     Enforce.ArgumentNotNull(transition, nameof(transition));
     foreach (var action in _exitActions)
         action.Action(transition);
 }
Exemplo n.º 18
0
 /// <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()));
 }
Exemplo n.º 19
0
 /// <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) : this()
 {
     _stateAccessor = Enforce.ArgumentNotNull(stateAccessor, "stateAccessor");
     _stateMutator  = Enforce.ArgumentNotNull(stateMutator, "stateMutator");
 }
Exemplo n.º 20
0
 /// <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);
 }
 protected ActivateActionBehaviour(TState state, string actionDescription)
 {
     _state             = state;
     _actionDescription = Enforce.ArgumentNotNull(actionDescription, nameof(actionDescription));
 }
Exemplo n.º 22
0
 internal StateConfiguration(StateRepresentation representation, Func <TState, StateRepresentation> lookup)
 {
     _representation = Enforce.ArgumentNotNull(representation, "representation");
     _lookup         = Enforce.ArgumentNotNull(lookup, "lookup");
 }
Exemplo n.º 23
0
 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);
 }
Exemplo n.º 24
0
 /// <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 <TArg0, TArg1, TArg2>(trigger, (a0, a1, a2, t) => entryAction(a0, a1, a2)));
 }
Exemplo n.º 25
0
 public void AddExitAction(Action <Transition> action)
 {
     _exitActions.Add(Enforce.ArgumentNotNull(action, "action"));
 }
Exemplo n.º 26
0
 /// <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>
            /// 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);
            }
Exemplo n.º 28
0
 /// <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);
 }
Exemplo n.º 29
0
 internal void InternalAction(Transition transition, object[] args)
 {
     Enforce.ArgumentNotNull(transition, "transition");
     ExecuteInternalActions(transition, args);
 }
Exemplo n.º 30
0
 /// <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));
 }