From 473a9ec664ec77621ab60b390aebd3c44ac91e1e Mon Sep 17 00:00:00 2001 From: Pent Ploompuu Date: Sun, 11 Jun 2023 23:38:10 +0300 Subject: [PATCH] Expose SaveTriggerConfiguration --- .../Reflection/DynamicTransitionInfo.cs | 11 +---- src/Stateless/StateConfiguration.Async.cs | 39 +++------------ src/Stateless/StateConfiguration.cs | 47 ++++--------------- src/Stateless/StateMachine.cs | 14 ++++-- 4 files changed, 25 insertions(+), 86 deletions(-) diff --git a/src/Stateless/Reflection/DynamicTransitionInfo.cs b/src/Stateless/Reflection/DynamicTransitionInfo.cs index a8179256..7b2cc6fb 100644 --- a/src/Stateless/Reflection/DynamicTransitionInfo.cs +++ b/src/Stateless/Reflection/DynamicTransitionInfo.cs @@ -68,16 +68,7 @@ public class DynamicTransitionInfo : TransitionInfo /// public DynamicStateInfos PossibleDestinationStates { get; private set; } - /// - /// Creates a new instance of . - /// - /// The trigger type. - /// The trigger associated with this transition. - /// The guard conditions associated with this transition. - /// The destination selector associated with this transition. - /// The possible destination states. - /// - public static DynamicTransitionInfo Create(TTrigger trigger, IEnumerable guards, + internal static DynamicTransitionInfo Create(TTrigger trigger, IEnumerable guards, InvocationInfo selector, DynamicStateInfos possibleStates) { var transition = new DynamicTransitionInfo diff --git a/src/Stateless/StateConfiguration.Async.cs b/src/Stateless/StateConfiguration.Async.cs index 6a89fbc3..b3aeb663 100644 --- a/src/Stateless/StateConfiguration.Async.cs +++ b/src/Stateless/StateConfiguration.Async.cs @@ -14,13 +14,13 @@ public partial class StateConfiguration /// /// /// Function that must return true in order for the trigger to be accepted. - /// + /// The asynchronous action performed by the internal transition /// - public StateConfiguration InternalTransitionAsyncIf(TTrigger trigger, Func guard, Func entryAction) + public StateConfiguration InternalTransitionAsyncIf(TTrigger trigger, Func guard, Func internalAction) { - if (entryAction == null) throw new ArgumentNullException(nameof(entryAction)); + if (internalAction == null) throw new ArgumentNullException(nameof(internalAction)); - _representation.AddTriggerBehaviour(new InternalTriggerBehaviour.Async(trigger, guard, (t, args) => entryAction(t))); + _representation.AddTriggerBehaviour(new InternalTriggerBehaviour.Async(trigger, guard, (t, args) => internalAction(t))); return this; } @@ -39,22 +39,6 @@ public StateConfiguration InternalTransitionAsyncIf(TTrigger trigger, Func return this; } - /// - /// 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 - /// - /// - /// The accepted trigger - /// Function that must return true in order for the trigger to be accepted. - /// The asynchronous action performed by the internal transition - /// - public StateConfiguration InternalTransitionAsyncIf(TTrigger trigger, Func guard, Func internalAction) - { - if (internalAction == null) throw new ArgumentNullException(nameof(internalAction)); - - _representation.AddTriggerBehaviour(new InternalTriggerBehaviour.Async(trigger, guard, (t, args) => internalAction(t))); - return this; - } - /// /// 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 /// @@ -115,34 +99,23 @@ public StateConfiguration InternalTransitionAsyncIf(Trigger } - /// - /// 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 - /// - /// - /// - /// - public StateConfiguration InternalTransitionAsync(TTrigger trigger, Func entryAction) - { - return InternalTransitionAsyncIf(trigger, () => true, entryAction); - } /// /// 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 /// /// The accepted trigger /// The asynchronous action performed by the internal transition /// - public StateConfiguration InternalTransitionAsync(TTrigger trigger, Func internalAction) + public StateConfiguration InternalTransitionAsync(TTrigger trigger, Func internalAction) { return InternalTransitionAsyncIf(trigger, () => true, internalAction); } /// /// 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 /// - /// /// The accepted trigger /// The asynchronous action performed by the internal transition /// - public StateConfiguration InternalTransitionAsync(TTrigger trigger, Func internalAction) + public StateConfiguration InternalTransitionAsync(TTrigger trigger, Func internalAction) { return InternalTransitionAsyncIf(trigger, () => true, internalAction); } diff --git a/src/Stateless/StateConfiguration.cs b/src/Stateless/StateConfiguration.cs index beec0168..700f75e2 100644 --- a/src/Stateless/StateConfiguration.cs +++ b/src/Stateless/StateConfiguration.cs @@ -48,27 +48,27 @@ public StateConfiguration Permit(TTrigger trigger, TState destinationState) /// /// 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 /// - /// - /// + /// The accepted trigger + /// The action performed by the internal transition /// - public StateConfiguration InternalTransition(TTrigger trigger, Action entryAction) + public StateConfiguration InternalTransition(TTrigger trigger, Action internalAction) { - return InternalTransitionIf(trigger, t => true, entryAction); + return InternalTransitionIf(trigger, t => true, internalAction); } /// /// 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 /// - /// + /// The accepted trigger /// Function that must return true in order for the trigger to be accepted. - /// + /// The action performed by the internal transition /// A description of the guard condition /// - public StateConfiguration InternalTransitionIf(TTrigger trigger, Func guard, Action entryAction, string guardDescription = null) + public StateConfiguration InternalTransitionIf(TTrigger trigger, Func guard, Action internalAction, string guardDescription = null) { - if (entryAction == null) throw new ArgumentNullException(nameof(entryAction)); + if (internalAction == null) throw new ArgumentNullException(nameof(internalAction)); - _representation.AddTriggerBehaviour(new InternalTriggerBehaviour.Sync(trigger, guard, (t, args) => entryAction(t), guardDescription)); + _representation.AddTriggerBehaviour(new InternalTriggerBehaviour.Sync(trigger, guard, (t, args) => internalAction(t), guardDescription)); return this; } @@ -99,35 +99,6 @@ public StateConfiguration InternalTransitionIf(TTrigger trigger, Func - /// 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 - /// - /// - /// The accepted trigger - /// Function that must return true in order for the trigger to be accepted. - /// The action performed by the internal transition - /// A description of the guard condition - /// - public StateConfiguration InternalTransitionIf(TTrigger trigger, Func guard, Action internalAction, string guardDescription = null) - { - if (internalAction == null) throw new ArgumentNullException(nameof(internalAction)); - - _representation.AddTriggerBehaviour(new InternalTriggerBehaviour.Sync(trigger, guard, (t, args) => internalAction(t), guardDescription)); - return this; - } - - /// - /// 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 - /// - /// - /// The accepted trigger - /// The action performed by the internal transition - /// - public StateConfiguration InternalTransition(TTrigger trigger, Action internalAction) - { - return InternalTransitionIf(trigger, t => true, internalAction); - } - /// /// 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 /// diff --git a/src/Stateless/StateMachine.cs b/src/Stateless/StateMachine.cs index 270cc620..9317e1d9 100644 --- a/src/Stateless/StateMachine.cs +++ b/src/Stateless/StateMachine.cs @@ -246,7 +246,7 @@ public void Fire(TriggerWithParameters trigger, params object[] args) public TriggerWithParameters SetTriggerParameters(TTrigger trigger, params Type[] argumentTypes) { var configuration = new TriggerWithParameters(trigger, argumentTypes); - SaveTriggerConfiguration(configuration); + SetTriggerParameters(configuration); return configuration; } @@ -600,7 +600,7 @@ public override string ToString() public TriggerWithParameters SetTriggerParameters(TTrigger trigger) { var configuration = new TriggerWithParameters(trigger); - SaveTriggerConfiguration(configuration); + SetTriggerParameters(configuration); return configuration; } @@ -615,7 +615,7 @@ public TriggerWithParameters SetTriggerParameters(TTrigger trigger public TriggerWithParameters SetTriggerParameters(TTrigger trigger) { var configuration = new TriggerWithParameters(trigger); - SaveTriggerConfiguration(configuration); + SetTriggerParameters(configuration); return configuration; } @@ -631,11 +631,15 @@ public TriggerWithParameters SetTriggerParameters(TT public TriggerWithParameters SetTriggerParameters(TTrigger trigger) { var configuration = new TriggerWithParameters(trigger); - SaveTriggerConfiguration(configuration); + SetTriggerParameters(configuration); return configuration; } - void SaveTriggerConfiguration(TriggerWithParameters trigger) + /// + /// Specify the arguments that must be supplied when a specific trigger is fired. + /// + /// The underlying trigger value and the argument types expected by the trigger. + public void SetTriggerParameters(TriggerWithParameters trigger) { if (_triggerConfiguration.ContainsKey(trigger.Trigger)) throw new InvalidOperationException(