public void Should_be_easy() { StateMachineWorkflow <RemoteRequestEngineWorkflow, RemoteRequestEngine> workflow = StateMachineWorkflow.New <RemoteRequestEngineWorkflow, RemoteRequestEngine>(x => { x.AccessCurrentState(i => i.CurrentState); x.Initially() .When(w => w.Start) .TransitionTo(y => y.Running) .When(y => y.Stop) .TransitionTo(y => y.Stopped); x.During(y => y.Running) .When(y => y.Interrupted) .Then(i => i.CancelPendingRequest) .When(y => y.Stop) .Then(i => i.CancelAllPendingRequests) .TransitionTo(y => y.Stopped); x.During(y => y.Stopped) .When(y => y.Start) .TransitionTo(y => y.Running) .When(y => y.Dispose) .Finalize(); x.Finally() .Then(instance => Trace.WriteLine("Completed")); }); var visitor = new TraceStateMachineVisitor(); workflow.Accept(visitor); var engine = new RemoteRequestEngine(); WorkflowInstance <RemoteRequestEngineWorkflow> engineInstance = workflow.GetInstance(engine); engineInstance.RaiseEvent(x => x.Start); engineInstance.RaiseEvent(x => x.Interrupted, new InterruptImpl { Source = "End of the world" }); engineInstance.RaiseEvent(x => x.Stop); engineInstance.RaiseEvent(x => x.Dispose); Trace.WriteLine("Final State: " + engineInstance.CurrentState); }
public void Should_be_easy() { StateMachineWorkflow<RemoteRequestEngineWorkflow, RemoteRequestEngine> workflow = StateMachineWorkflow.New<RemoteRequestEngineWorkflow, RemoteRequestEngine>(x => { x.AccessCurrentState(i => i.CurrentState); x.Initially() .When(w => w.Start) .TransitionTo(y => y.Running) .When(y => y.Stop) .TransitionTo(y => y.Stopped); x.During(y => y.Running) .When(y => y.Interrupted) .Then(i => i.CancelPendingRequest) .When(y => y.Stop) .Then(i => i.CancelAllPendingRequests) .TransitionTo(y => y.Stopped); x.During(y => y.Stopped) .When(y => y.Start) .TransitionTo(y => y.Running) .When(y => y.Dispose) .Finalize(); x.Finally() .Then(instance => Trace.WriteLine("Completed")); }); var visitor = new TraceStateMachineVisitor(); workflow.Accept(visitor); var engine = new RemoteRequestEngine(); WorkflowInstance<RemoteRequestEngineWorkflow> engineInstance = workflow.GetInstance(engine); engineInstance.RaiseEvent(x => x.Start); engineInstance.RaiseEvent(x => x.Interrupted, new InterruptImpl {Source = "End of the world" }); engineInstance.RaiseEvent(x => x.Stop); engineInstance.RaiseEvent(x => x.Dispose); Trace.WriteLine("Final State: " + engineInstance.CurrentState); }
public void Should_be_easy() { StateMachineWorkflow <RemoteRequestEngineWorkflow, RemoteRequestEngine> workflow = StateMachineWorkflow.New <RemoteRequestEngineWorkflow, RemoteRequestEngine>(x => { x.AccessCurrentState(i => i.CurrentState); x.Initially(c => { c.When(e => e.Start, t => { t.TransitionTo(y => y.Running); }); c.When(e => e.Stop, t => { t.TransitionTo(y => y.Stopped); }); }); x.During(s => s.Running, c => { c.When(e => e.Interrupted, t => { t.TransitionTo(y => y.Stopped); }); c.When(e => e.Stop, t => { t.TransitionTo(y => y.Stopped); }); }); x.During(s => s.Stopped, c => { c.When(e => e.Start, t => { t.TransitionTo(y => y.Running); }); c.When(e => e.Dispose, t => { t.Finalize(); }); }); x.DuringAny(c => { c.When(e => e.Dispose) .Then(() => {}); }); x.Finally(t => { t.Then(instance => Trace.WriteLine("Completed")); }); }); var visitor = new TraceStateMachineVisitor(); workflow.Accept(visitor); var engine = new RemoteRequestEngine(); WorkflowInstance <RemoteRequestEngineWorkflow> engineInstance = workflow.GetInstance(engine); engineInstance.RaiseEvent(x => x.Start); engineInstance.RaiseEvent(x => x.Stop); engineInstance.RaiseEvent(x => x.Dispose); Trace.WriteLine("Final State: " + engineInstance.CurrentState); }
public void Should_be_easy() { StateMachineWorkflow<RemoteRequestEngineWorkflow, RemoteRequestEngine> workflow = StateMachineWorkflow.New<RemoteRequestEngineWorkflow, RemoteRequestEngine>(x => { x.AccessCurrentState(i => i.CurrentState); x.Initially(c => { c.When(e => e.Start, t => { t.TransitionTo(y => y.Running); }); c.When(e => e.Stop, t => { t.TransitionTo(y => y.Stopped); }); }); x.During(s => s.Running, c => { c.When(e => e.Interrupted, t => { t.TransitionTo(y => y.Stopped); }); c.When(e => e.Stop, t => { t.TransitionTo(y => y.Stopped); }); }); x.During(s => s.Stopped, c => { c.When(e => e.Start, t => { t.TransitionTo(y => y.Running); }); c.When(e => e.Dispose, t => { t.Finalize(); }); }); x.DuringAny(c => { c.When(e => e.Dispose) .Then(() => {}); }); x.Finally(t => { t.Then(instance => Trace.WriteLine("Completed")); }); }); var visitor = new TraceStateMachineVisitor(); workflow.Accept(visitor); var engine = new RemoteRequestEngine(); WorkflowInstance<RemoteRequestEngineWorkflow> engineInstance = workflow.GetInstance(engine); engineInstance.RaiseEvent(x => x.Start); engineInstance.RaiseEvent(x => x.Stop); engineInstance.RaiseEvent(x => x.Dispose); Trace.WriteLine("Final State: " + engineInstance.CurrentState); }