Conditional and Parameterised transitions

802 views
Skip to first unread message

Brett Bailey

unread,
Aug 30, 2012, 5:17:23 AM8/30/12
to dotnet-state-ma...@googlegroups.com

Is it possible to access the parameter of a parameterised transition in the guard clause of  PermitIf().

For example I would like to do something like this:

_assignTrigger = _machine.SetTriggerParameters<string>(Trigger.Assign);

_machine.Configure(State.Assigned)
.PermitIf(_assignTrigger, OrderState.Blocked, x => IsBlackListed(x))
.Permit(_assignTrigger, OrderState.Accepted)



_machine.Fire(_assignTrigger, "j...@example.com") //transition to Accepted unless email is blacklisted


Cheers
~Brett

Simon

unread,
Aug 30, 2012, 3:49:00 PM8/30/12
to dotnet-state-ma...@googlegroups.com
I've tried that as well but no luck, I think you can only us the parameter in the OnEntry(). 

Would be a good addition to the framework though!

Grant BlahaErath

unread,
Aug 30, 2012, 4:13:24 PM8/30/12
to dotnet-state-ma...@googlegroups.com
Yes.  PermitDynamic(aTrigger, (aParam) => { .... });  should do the trick.  You have to resolve the state for that trigger in that lambda function, rather than let it iterate through a cluster of PermitIf conditionals.    I also recommend throwing an exception (like InvalidOperation) if there is no match or obvious fall through condition since that means your automaton is incomplete.
 
You can think of PermitIf as a subset of PermitDynamic.  PermitIf is a collection of conditional statements that is iterated over, while PermitDynamic performs the same role without the iteration of a collection.  Inside the PermitDynamic would be one or more if/then/return state statements.  Or, if the conditionals are too complex, create a second state machine inside the PermitDynamic.  I like using PermitDynamic for resolving WPF RoutedCommands.
 
-g
Reply all
Reply to author
Forward
0 new messages