Created
May 25, 2010 23:12
-
-
Save bforrest/413808 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
| using System; | |
| using LinenLifeCycle.Messages; | |
| using Magnum.StateMachine; | |
| using MassTransit; | |
| using MassTransit.Saga; | |
| namespace LinenLifeCycle | |
| { | |
| public class LinenCycleSaga: SagaStateMachine<LinenCycleSaga>, ISaga | |
| { | |
| static LinenCycleSaga() | |
| { | |
| Define(() => | |
| { | |
| Initially( | |
| When(NewInventory) | |
| .Then((saga, message) => saga.ProcessNewInventory(message)) | |
| .TransitionTo(InLaundryRoom), | |
| When(LaunderingComplete) | |
| .Then((saga, message) => saga.ArticleWasLaundered(message)) | |
| .TransitionTo(InLaundryRoom)); | |
| During(InLaundryRoom, | |
| When(MovedToFloor) | |
| .TransitionTo(OnTheFloor)); | |
| During(OnTheFloor, | |
| When(OutForUse) | |
| .Then((saga, message) => saga.InventoryOutForUse(message)) | |
| .TransitionTo(InPatronRoom)); | |
| During(InPatronRoom, | |
| When(ReturnedForLaundering) | |
| .Then((saga, message) => saga.Launder(message)) | |
| .TransitionTo(AwaitingLaundering)); | |
| During(AwaitingLaundering, | |
| When(LaunderingComplete) | |
| .Where(x => x.CycleCount > 100) | |
| .Then((saga, message) => saga.ArticleIsRetired(message)) | |
| .TransitionTo(Retired), | |
| When(LaunderingComplete) | |
| .Then((saga, message) => saga.ArticleWasLaundered(message)) | |
| .TransitionTo(Completed)); | |
| }); | |
| } | |
| public static State Initial { get; set; } | |
| public static State InLaundryRoom { get; set; } | |
| public static State OnTheFloor { get; set;} | |
| public static State InPatronRoom { get; set; } | |
| public static State OutToPatron { get; set; } | |
| public static State AwaitingLaundering { get; set; } | |
| public static State Completed { get; set; } | |
| public static State Retired { get; set; } | |
| public static Event<NewArticleReceived> NewInventory { get; set; } | |
| public static Event<ArticleOutForUse> MovedToFloor { get; set; } | |
| public static Event<ArticleOutForUse> OutForUse { get; set; } | |
| public static Event<NeedsLaundering> ReturnedForLaundering { get; set; } | |
| public static Event<ArticleLaundered> LaunderingComplete { get; set; } | |
| public static Event InventoryReadyForUse { get; set; } | |
| private void ProcessNewInventory(NewArticleReceived message) | |
| { | |
| //TODO: Update inventory store | |
| } | |
| private void InventoryOutForUse(ArticleOutForUse message) | |
| { | |
| // TODO: Not a clue yet | |
| } | |
| private void Launder(NeedsLaundering message) | |
| { | |
| // TODO: Launder | |
| } | |
| private void ArticleWasLaundered(ArticleLaundered message) | |
| { | |
| // TODO: increment wash- count etc. | |
| } | |
| private void ArticleIsRetired(ArticleLaundered message) | |
| { | |
| // TODO: increment wash- count etc. | |
| } | |
| public Guid CorrelationId { get; set;} | |
| public IServiceBus Bus { get; set;} | |
| public virtual string TagIdHex { get; set; } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment