Ramon Smits

Tell me your secrets and i'll tell you mine

Recent Posts

Tags

Community

Email Notifications

Patterns & Practices / Guidelines

EntLib

Nant

Blogs that I monitor

Archives


StateMachine in c# and xml

Yesterday I browsed through the new articles at codeproject.com. Leslie Sanford StateMachine articles had my attention. He has designed and implemented it in c#. A job done pretty well I think. I took a look at his code that reads an xml definition to deserialize its state design. My thoughts were that it wasn't really readable and logical so I made a class design that serializes to a "self-describing" xml document.

An example:
<?xml version="1.0"?>
<Machine Id="Switch" InitialState="On" xmlns="Exyll.StateMachine">
  <SubStates>
    <State Id="On">
      <Transitions>
        <Transition EventName="TurnOff" Target="Off" />
      </Transitions>
    </State>
    <State Id="Off">
      <Transitions>
        <Transition EventName="TurnOn" Target="On" />
      </Transitions>
    </State>
  </SubStates>
  <Events>
    <Event>TurnOff</Event>
    <Event>TurnOn</Event>
  </Events>
</Machine>

If you are interested in this class design and the xmlattributes I had to add to achieve this xml format then download StateMachine code.

Comments

Ramon Smits said:

I added unittest for a switch in version 1. Leslie had some troubles with building his trafficsign. I...
# September 30, 2005 1:36 AM

Ramon Smits said:

Updated:
&amp;nbsp;- New archive to download (v3)
&amp;nbsp;- XML updated
&amp;nbsp;- Code rewrite with delegates...
# September 30, 2005 2:53 AM

Ramon Smits said:

Updated:
&amp;nbsp;- New archive to download (v3)
&amp;nbsp;- XML updated
&amp;nbsp;- Code rewrite with delegates...
# September 30, 2005 2:57 AM

Ramon Smits said:

Updated:
&amp;nbsp;- New archive to download (v3)
&amp;nbsp;- XML updated
&amp;nbsp;- Code rewrite with delegates...
# December 30, 2005 8:59 AM

Ramon Smits said:

Updated:
&amp;nbsp;- New archive to download (v3)
&amp;nbsp;- XML updated
&amp;nbsp;- Code rewrite with delegates...
# December 30, 2005 8:59 AM

Julian said:

Hi Ramon,

I found very interesting that you've done.

I have a question.

I want to implement functionality that give possibility switch between tabItems. (TabItem1,TabItem2,TabItem3....TabItemN), when user click button "next" on the Form. And for that reason I'd like to use State Machine Pattern and apply Singletone there.

Probably I need to have following things: changeState, getNextState, previousState,currentState,nextState.

Each state it's a name of TabItem (for instance: Home Item, Welcome Item etc.).

I understand that it shod be like this this this and this. But I can't do that..because I've no enough experience :(

Could you please help me with that, I'll be very thankful. I really want to understand how it works in my example.

Thank you in advance,

# October 11, 2009 11:37 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Please add 2 and 2 and type the answer here: