Created
October 5, 2010 19:32
-
-
Save copenhas/612173 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .... | |
| #region StateMachine | |
| static ServiceController() | |
| { | |
| Define(() => | |
| { | |
| Initially( | |
| When(OnStart) | |
| .Then(sc => sc.Initialize()) | |
| .Then(sc => sc.StartAction(sc._instance)) | |
| .TransitionTo(Started) | |
| ); | |
| During(Started, | |
| When(OnPause) | |
| .Then(sc => sc.PauseAction(sc._instance)) | |
| .TransitionTo(Paused)); | |
| During(Paused, | |
| When(OnContinue) | |
| .Then(sc => sc.ContinueAction(sc._instance)) | |
| .TransitionTo(Started)); | |
| Anytime(When(OnStop) | |
| .Then(sc => sc.StopAction(sc._instance)) | |
| .TransitionTo(Stopped) | |
| ); | |
| }); | |
| } | |
| public static Event OnStart { get; set; } | |
| public static Event OnStop { get; set; } | |
| public static Event OnPause { get; set; } | |
| public static Event OnContinue { get; set; } | |
| public static State Initial { get; set; } | |
| public static State Started { get; set; } | |
| public static State Stopped { get; set; } | |
| public static State Paused { get; set; } | |
| public static State Completed { get; set; } | |
| #endregion | |
| ..... |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a code snippet from the TopShelf project. They are using a sister project Mangum to define a state machine to control a logical service instance.
I should add that this was inside a ServiceController class. They seem to create one for each service that is being managed. That Magnum project looks very interesting.