Experimenting with ControlStateMachine and Fluent interfaces
A long time ago i read Build your own CAB series and recently i noticed that there is a wiki: Presentation Patterns Wiki! and it inspired me to experiment with state machines. Here are a couple of examples:
controlStateMachine = new ControlStateMachine<states>(this);
controlStateMachine.AfterEachStateChange()
.Do(MakeRelevantButtonsVisible);
controlStateMachine.WhenStateChangesTo(States.RetrievingSubscriptionPeriod)
.TheOnlyVisibleControlsAre(flowLayoutPanel1, datePicker1);
controlStateMachine.WhenStateChangesTo(States.RetrievingCustomerInformation)
.MakeVisible(customerInput1)
.Do(() => customerInput1.Dock = DockStyle.Fill);
controlStateMachine.WhenStateChangesTo(States.Ready)
.MakeInvisible(customerInput1);
And here is another example:
wizardStateMachine = new WizardStateMachine<states>(controlStateMachine);
wizardStateMachine.InState(States.RetrievingSubscriptionPeriod)
.OnCommand(WizardCommands.Next)
.TransitionTo(States.RetrievingCustomerInformation);
wizardStateMachine.InState(States.RetrievingCustomerInformation)
.OnCommand(WizardCommands.Back)
.TransitionTo(States.RetrievingSubscriptionPeriod)
.OnCommand(WizardCommands.Finish)
.TransitionTo(States.Ready);
wizardStateMachine.InState(States.Ready)
.OnCommand(WizardCommands.New)
.Do(() => MessageBox.Show("Currently not supported"));
Stay tuned for future posts where i describe the problem space that have lead to this API.