I recently took my jeep to get the oil changed. While I was there, I realized that garage's business process model would serve as a great demonstration of "how" and "why" to implement a Skip/Rework Pattern for a State Machine workflow, at tomorrow's code camp in Tampa.
Here is the model... Oil Change
While I was giving the clerk my contact and payment information, they asked me if I would approve any needed work that they felt the jeep needed up to a certain amount. Obviously they would let me know before performing any additional service(s). If I did not approve needed work up to a specific amount, they would have to spend more time explaining what needed to be done and if they were to busy possibly removing my car from the bay to service another waiting customer. I would then have wait or make another appointment for a later time.
The Skip and Rework pattern is demonstrated by skipping the normal flow for the RecommendingAdditionalServices event, and getting the customer to approve or deny the additional service(s) within the ServiceApproval state. Instead, needed services can be done immediately by setting the active state to WorkOnAutomobile, directly from the ChangeOil state.
The code do set the state active is pretty simple. I found the above code in Paul Andrew's book, and modified it to fit. The code above is wired to a button that allows the manager to bypass getting approval and sends the car directly to get service(s), because the customer already gave approval up to a certain estimate.
I first check that the Customer has given approval. Then I declare the SetStateEventArgs and pass the state I would like to set as the active state. The event to set the state is raised by calling the EnqueueItem for the workflow instance, passing the arguments for the state that needs to be set.