/// <summary> /// Selects a state to which events can be added /// </summary> /// <typeparam name="TWorkflow"></typeparam> /// <typeparam name="TInstance"></typeparam> /// <param name="stateMachineConfigurator"></param> /// <param name="stateExpression"></param> /// <returns></returns> public static StateConfigurator <TWorkflow, TInstance> During <TWorkflow, TInstance>( this StateMachineConfigurator <TWorkflow, TInstance> stateMachineConfigurator, Expression <Func <TWorkflow, State> > stateExpression) where TWorkflow : class where TInstance : class { return(stateMachineConfigurator.During(stateExpression, DoNothing)); }
static void ConfigureWorkflow(StateMachineConfigurator <IServiceWorkflow, IServiceController> x) { x.AccessCurrentState(s => s.CurrentState); x.Initially() .When(e => e.Create) .TransitionTo(s => s.Creating) .Then(i => i.Create) .InCaseOf() .Exception <BuildServiceException>() .TransitionTo(s => s.Faulted); x.During(s => s.Creating) .When(e => e.OnCreated) .TransitionTo(s => s.Created) .TransitionTo(s => s.Starting) .Then(i => i.Start) .InCaseOf() .Exception <Exception>() .TransitionTo(s => s.Faulted); x.During(s => s.Creating) .AcceptFault(); x.During(s => s.Creating) .When(e => e.Stop) .TransitionTo(s => s.StopRequested); x.During(s => s.Created) .When(e => e.Start) .TransitionTo(s => s.Starting) .Then(i => i.Start) .InCaseOf() .Exception <Exception>() .TransitionTo(s => s.Faulted); x.During(s => s.Created) .When(e => e.OnRunning) .TransitionTo(s => s.Running) .AcceptFault(); x.During(s => s.Starting) .When(e => e.OnRunning) .TransitionTo(s => s.Running) .When(e => e.Stop) .TransitionTo(s => s.StopRequested) .AcceptFault(); x.During(s => s.Running) .AcceptStop() .AcceptPause() .AcceptRestart() .AcceptFault(); x.During(s => s.StopRequested) .When(e => e.OnRunning) .Then(i => i.Stop) .TransitionTo(s => s.Stopping) .When(e => e.OnFaulted) .TransitionTo(s => s.Faulted) .Then(i => i.Stop); x.During(s => s.StopRequested) .When(e => e.OnCreated) .TransitionTo(s => s.Created) .Then(i => i.Stop) .TransitionTo(s => s.Stopping) .InCaseOf() .Exception <Exception>() .TransitionTo(s => s.Faulted); x.During(s => s.Stopping) .When(e => e.OnStopped) .TransitionTo(s => s.Stopped) .AcceptFault(); x.During(s => s.Pausing) .When(e => e.OnPaused) .TransitionTo(s => s.Paused) .AcceptFault(); x.During(s => s.Paused) .When(e => e.Continue) .TransitionTo(s => s.Continuing) .Then(i => i.Continue) .AcceptFault(); x.During(s => s.Continuing) .When(e => e.OnRunning) .TransitionTo(s => s.Running) .AcceptFault(); x.During(s => s.Stopped) .When(e => e.Unload) .TransitionTo(s => s.Unloading) .Then(i => i.Unload); x.During(s => s.Unloading) .When(e => e.OnUnloaded) .TransitionTo(s => s.Completed); x.During(s => s.Faulted) .When(e => e.Restart) .Then(i => i.Create) .TransitionTo(s => s.CreatingToRestart); x.During(s => s.StoppingToRestart) .When(e => e.OnStopped) .TransitionTo(s => s.UnloadingToRestart) .Then(i => i.Unload) .AcceptFault(); x.During(s => s.UnloadingToRestart) .When(e => e.OnUnloaded) .TransitionTo(s => s.CreatingToRestart) .Then(i => i.Create) .AcceptFault(); x.During(s => s.CreatingToRestart) .AcceptFault(); x.During(s => s.CreatingToRestart) .When(e => e.OnCreated) .TransitionTo(s => s.Created) .TransitionTo(s => s.Restarting) .Then(i => i.Start()) .InCaseOf() .Exception <Exception>() .Then((i, m) => { }) // m.Respond(new ServiceFault(i.Name, null /* TODO get ex */))) .TransitionTo(s => s.Faulted); x.During(s => s.Restarting) .When(e => e.OnRunning) .TransitionTo(s => s.Running) .AcceptFault(); x.During(s => s.Faulted) .When(e => e.Stop) .TransitionTo(s => s.Completed); }