ExecuteOnEntry parameters

65 views
Skip to first unread message

scope_creep

unread,
Mar 28, 2012, 10:29:24 AM3/28/12
to bbvcommon
Is it possible to pass parameters to the the method executed on a
entry to a state, the ExecuteOnEntry. I can get it to work with
the .Execute but not on ExecuteOnEntry.

fsm.In(ProcessState.CheckCredential)
.ExecuteOnEntry(CheckCredentialOkAct)
.On(Command.EvCredNotOk).Goto(ProcessState.SendingError)
.On(Command.EvCredOk).Goto(ProcessState.WaitForLic);

Action<object> CheckCredentialOkAct = new
Action<object>(this.CheckCredentials);

it doesn’t work, as it doesn't fit the method call definition. If see
it offers the following interface, with a parameter.

IExitActionSyntax<TState, TEvent> ExecuteOnEntry<T>(Action<T> action,
T parameter);

What do you define the parmater to pass the parameter in, from outside
the class the fsm is defined in.

Thanks
Bob

Urs Enzler

unread,
Mar 30, 2012, 2:38:16 AM3/30/12
to bbvcommon
Hi Bob

Unfortunately, it is currently not possible to pass the argument you
specify in stateMachine.Fire(someEvent, someArgument) into the entry
or exit action.

The parameter you see in the overload of ExecuteOnEntry can be used in
the definition. For example:

stateMachine.In(State.A)
.ExecuteOnEntry(ToggleButton, true)
.ExecuteOnExit(ToggleButton, false)

This would for example enable or disable a button depending on the
parameter.


At the moment, you have to replace your entry action with transition
actions and add the action you would execute on entry to every
transition that ends in this state.


We're currently working on a new version of the state machine and will
try to incorporate your input. The project will also be renamed to
Appccelerate (http://github.com/appccelerate/appccelerate).

Cheers
Urs

scope_creep

unread,
Apr 6, 2012, 11:11:41 AM4/6/12
to bbvcommon
Thanks. I managed to work around it, to get an excellent wee state
machine built. Find piece of code and mighty handy, and specifically
removing the one class per state problem.
Reply all
Reply to author
Forward
0 new messages