Пример #1
0
 public static Func <object[], bool> ToPackedGuard <TArg0, TArg1, TArg2>(Func <TArg0, TArg1, TArg2, bool> guard)
 {
     return(args => guard(
                ParameterConversion.Unpack <TArg0>(args, 0),
                ParameterConversion.Unpack <TArg1>(args, 1),
                ParameterConversion.Unpack <TArg2>(args, 2)));
 }
Пример #2
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>
 /// <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>(TriggerWithParameters <TArg0> trigger, Action <TArg0, Transition> entryAction)
 {
     Enforce.ArgumentNotNull(entryAction, "entryAction");
     Enforce.ArgumentNotNull(trigger, "trigger");
     _representation.AddEntryAction(trigger.Trigger, (t, args) => entryAction(
                                        ParameterConversion.Unpack <TArg0>(args, 0), t));
     return(this);
 }
Пример #3
0
            /// <summary>
            /// Ensure that the supplied arguments are compatible with those configured for this
            /// trigger.
            /// </summary>
            /// <param name="args"></param>
            public void ValidateParameters(object[] args)
            {
                if (args == null)
                {
                    throw new ArgumentNullException(nameof(args));
                }

                ParameterConversion.Validate(args, _argumentTypes);
            }
Пример #4
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>
 /// <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>
 /// <param name="entryActionDescription">Action description.</param>
 /// <returns>The receiver.</returns>
 public StateConfiguration OnEntryFrom <TArg0, TArg1>(TriggerWithParameters <TArg0, TArg1> trigger, Action <TArg0, TArg1, Transition> entryAction, string entryActionDescription = null)
 {
     Enforce.ArgumentNotNull(entryAction, nameof(entryAction));
     Enforce.ArgumentNotNull(trigger, nameof(trigger));
     _representation.AddEntryAction(trigger.Trigger, (t, args) => entryAction(
                                        ParameterConversion.Unpack <TArg0>(args, 0),
                                        ParameterConversion.Unpack <TArg1>(args, 1), t), entryActionDescription ?? entryAction.TryGetMethodName());
     return(this);
 }
Пример #5
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>
 /// <typeparam name="TArg0">Type of the first trigger argument.</typeparam>
 public StateConfiguration PermitDynamicIf <TArg0>(TriggerWithParameters <TArg0> trigger, Func <TArg0, TState> destinationStateSelector, Func <bool> guard)
 {
     Enforce.ArgumentNotNull(trigger, "trigger");
     Enforce.ArgumentNotNull(destinationStateSelector, "destinationStateSelector");
     return(InternalPermitDynamicIf(
                trigger.Trigger,
                args => destinationStateSelector(
                    ParameterConversion.Unpack <TArg0>(args, 0)),
                guard));
 }
Пример #6
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>
 /// <param name="guardDescription">Guard description</param>
 /// <returns>The reciever.</returns>
 /// <typeparam name="TArg0">Type of the first trigger argument.</typeparam>
 public StateConfiguration PermitDynamicIf <TArg0>(TriggerWithParameters <TArg0> trigger, Func <TArg0, TState> destinationStateSelector, Func <bool> guard, string guardDescription = null)
 {
     Enforce.ArgumentNotNull(trigger, nameof(trigger));
     Enforce.ArgumentNotNull(destinationStateSelector, nameof(destinationStateSelector));
     return(InternalPermitDynamicIf(
                trigger.Trigger,
                args => destinationStateSelector(
                    ParameterConversion.Unpack <TArg0>(args, 0)),
                guard,
                guardDescription ?? guard?.TryGetMethodName()));
 }
Пример #7
0
            /// <summary>
            /// Add an internal transition to the state machine. An internal action does not cause the Exit and Entry actions to be triggered, and does not change the state of the state machine
            /// </summary>
            /// <typeparam name="TArg0"></typeparam>
            /// <typeparam name="TArg1"></typeparam>
            /// <param name="trigger">The accepted trigger</param>
            /// <param name="guard">Function that must return true in order for the trigger to be accepted.</param>
            /// <param name="internalAction">The asynchronous action performed by the internal transition</param>
            /// <returns></returns>
            public StateConfiguration InternalTransitionAsyncIf <TArg0, TArg1>(TriggerWithParameters <TArg0, TArg1> trigger, Func <bool> guard, Func <TArg0, TArg1, Transition, Task> internalAction)
            {
                if (internalAction == null)
                {
                    throw new ArgumentNullException(nameof(internalAction));
                }

                _representation.AddTriggerBehaviour(new InternalTriggerBehaviour(trigger.Trigger, guard));
                _representation.AddInternalAction(trigger.Trigger, (t, args) => internalAction(
                                                      ParameterConversion.Unpack <TArg0>(args, 0),
                                                      ParameterConversion.Unpack <TArg1>(args, 1), t));
                return(this);
            }
Пример #8
0
            /// <summary>
            /// Specify an asynchronous 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>
            /// <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>
            /// <param name="entryActionDescription">Action description.</param>
            /// <returns>The receiver.</returns>
            public StateConfiguration OnEntryFromAsync <TArg0, TArg1>(TriggerWithParameters <TArg0, TArg1> trigger, Func <TArg0, TArg1, Transition, Task> entryAction, string entryActionDescription = null)
            {
                if (trigger == null)
                {
                    throw new ArgumentNullException(nameof(trigger));
                }
                if (entryAction == null)
                {
                    throw new ArgumentNullException(nameof(entryAction));
                }

                _representation.AddEntryAction(trigger.Trigger,
                                               (t, args) => entryAction(
                                                   ParameterConversion.Unpack <TArg0>(args, 0),
                                                   ParameterConversion.Unpack <TArg1>(args, 1), t),
                                               Reflection.InvocationInfo.Create(entryAction, entryActionDescription, Reflection.InvocationInfo.Timing.Asynchronous));
                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);
            }
Пример #10
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="TArg0"></typeparam>
 /// <param name="trigger"></param>
 /// <param name="entryAction"></param>
 /// <returns></returns>
 public StateConfiguration InternalTransition <TArg0>(TriggerWithParameters <TArg0> trigger, Action <TArg0, Transition> entryAction)
 {
     _representation.AddTriggerBehaviour(new InternalTriggerBehaviour(trigger.Trigger));
     _representation.AddInternalAction(trigger.Trigger, (t, args) => entryAction(ParameterConversion.Unpack <TArg0>(args, 0), t));
     return(this);
 }
Пример #11
0
 /// <summary>
 /// Add an internal transition to the state machine. An internal action does not cause the Exit and Entry actions to be triggered, and does not change the state of the state machine
 /// </summary>
 /// <typeparam name="TArg0"></typeparam>
 /// <param name="trigger">The accepted trigger</param>
 /// <param name="guard">Function that must return true in order for the trigger to be accepted.</param>
 /// <param name="internalAction">The asynchronous action performed by the internal transition</param>
 /// <returns></returns>
 public StateConfiguration InternalTransitionAsyncIf <TArg0>(TriggerWithParameters <TArg0> trigger, Func <bool> guard, Func <TArg0, Transition, Task> internalAction)
 {
     if (internalAction == null)
     {
         throw new ArgumentNullException(nameof(internalAction));
     }
     if (!internalAction.GetMethodInfo().IsDefined(typeof(AsyncStateMachineAttribute), false))
     {
         throw new ArgumentException("The supplied method is not tagged 'async'", nameof(internalAction));
     }
     _representation.AddTriggerBehaviour(new InternalTriggerBehaviour.Async(trigger.Trigger, guard, (t, args) => internalAction(ParameterConversion.Unpack <TArg0>(args, 0), t)));
     return(this);
 }
Пример #12
0
            /// <summary>
            /// Add an internal transition to the state machine. An internal action does not cause the Exit and Entry actions to be triggered, and does not change the state of the state machine
            /// </summary>
            /// <typeparam name="TArg0"></typeparam>
            /// <param name="trigger">The accepted trigger</param>
            /// <param name="internalAction">The action performed by the internal transition</param>
            /// <returns></returns>
            public StateConfiguration InternalTransition <TArg0>(TriggerWithParameters <TArg0> trigger, Action <TArg0, Transition> internalAction)
            {
                if (internalAction == null)
                {
                    throw new ArgumentNullException(nameof(internalAction));
                }

                _representation.AddTriggerBehaviour(new InternalTriggerBehaviour(trigger.Trigger));
                _representation.AddInternalAction(trigger.Trigger, (t, args) => internalAction(ParameterConversion.Unpack <TArg0>(args, 0), t));
                return(this);
            }