public void Should_include_all_the_state_events() { _workflow = StateMachineWorkflow.New<MyActorWorkflow, MyActor>(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.AReceived) .Then(i => i.OnA) .When(y => y.BReceived) .Then(i => i.OnB) .When(y => y.Stop) .TransitionTo(y => y.Stopped); x.During(y => y.Stopped) .When(y => y.Start) .TransitionTo(y => y.Running) .When(y => y.OnExit) .Finalize(); }); _visitor = new StateMachineWorkflowEventVisitor<MyActorWorkflow, MyActor>(); _workflow.Accept(_visitor); }
public void Throwing_an_exception_from_an_event_handler() { _workflow = StateMachineWorkflow.New<SubjectWorkflow, Subject>(x => { x.AccessCurrentState(y => y.CurrentState); x.Initially() .When(e => e.Create) .Then(i => i.Create) .TransitionTo(s => s.Created) .InCaseOf() .Exception<SubjectException>() .Then(i => { _instanceHandlerCalled = true; }) .Then(() => _handlerCalled = true) .TransitionTo(s => s.Failed); }); _subject = new Subject(); _instance = _workflow.GetInstance(_subject); _instance.RaiseEvent(x => x.Create); }
public void Throwing_an_exception_from_an_event_handler() { _workflow = StateMachineWorkflow.New <SubjectWorkflow, Subject>(x => { x.AccessCurrentState(y => y.CurrentState); x.Initially() .When(e => e.Create) .Then(i => i.Create) .TransitionTo(s => s.Created) .InCaseOf() .Exception <SubjectException>() .Then(i => { _instanceHandlerCalled = true; }) .Then(() => _handlerCalled = true) .TransitionTo(s => s.Failed); }); _subject = new Subject(); _instance = _workflow.GetInstance(_subject); _instance.RaiseEvent(x => x.Create); }
public void Creating_a_new_workflow() { _workflow = StateMachineWorkflow.New<TestWorkflow, TestInstance>(x => { x.AccessCurrentState(y => y.CurrentState); }); _instance = _workflow.GetInstance(new TestInstance()); }
public void Creating_a_new_workflow() { _workflow = StateMachineWorkflow.New <TestWorkflow, TestInstance>(x => { x.AccessCurrentState(y => y.CurrentState); }); _instance = _workflow.GetInstance(new TestInstance()); }
static IDictionary <Event, StateMachineWorkflowEventBinder <TActor> > BuildStateEventBinders( StateMachineWorkflow <TWorkflow, TActor> workflow) { var visitor = new StateMachineWorkflowEventVisitor <TWorkflow, TActor>(); workflow.Accept(visitor); return(visitor.GetBinders().ToDictionary(x => x.Event)); }
protected virtual bool Visit(StateMachineWorkflow <TWorkflow, TActor> workflow) { // this is the first thing hit, so let's make sure we are clean in case we get reused _activities.Clear(); _events.Clear(); _workflow = workflow; return(true); }
public void An_event_causing_a_state_transition() { _workflow = StateMachineWorkflow.New <TestWorkflow, TestInstance>(x => { x.AccessCurrentState(y => y.CurrentState); x.During(y => y.Initial) .When(y => y.Finish) .TransitionTo(y => y.Completed); }); _instance = _workflow.GetInstance(new TestInstance()); _instance.RaiseEvent(x => x.Finish); }
public void An_event_causing_a_state_transition() { _workflow = StateMachineWorkflow.New<TestWorkflow, TestInstance>(x => { x.AccessCurrentState(y => y.CurrentState); x.During(y => y.Initial) .When(y => y.Finish) .TransitionTo(y => y.Completed); }); _instance = _workflow.GetInstance(new TestInstance()); _instance.RaiseEvent(x => x.Finish); }
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 A_message_event_changes_the_state() { _workflow = StateMachineWorkflow.New <TestWorkflow, TestInstance>(x => { x.AccessCurrentState(y => y.CurrentState); x.During(y => y.Initial) .When(y => y.Finish) .TransitionTo(y => y.Completed); }); _instance = _workflow.GetInstance(new TestInstance()); _instance.RaiseEvent(x => x.Finish, new Result { Value = "Success" }); }
public void A_simple_event_is_raised() { _workflow = StateMachineWorkflow.New <TestWorkflow, TestInstance>(x => { x.AccessCurrentState(y => y.CurrentState); x.During(y => y.Initial) .When(y => y.Finish) .Then(() => _nonInstanceValue = true) .Then(instance => instance.ConstantValue = "Success") .TransitionTo(y => y.Completed); }); _testInstance = new TestInstance(); _instance = _workflow.GetInstance(_testInstance); _instance.RaiseEvent(x => x.Finish); }
public void Raising_multiple_events() { _workflow = StateMachineWorkflow.New <TestWorkflow, TestInstance>(x => { x.AccessCurrentState(y => y.CurrentState); x.During(y => y.Initial) .When(y => y.Start) .TransitionTo(y => y.Running); x.During(y => y.Running) .When(y => y.Finish) .TransitionTo(y => y.Completed); }); _instance = _workflow.GetInstance(new TestInstance()); _instance.RaiseEvent(x => x.Start); _instance.RaiseEvent(x => x.Finish); }
public void A_message_event_is_raised() { _workflow = StateMachineWorkflow.New<TestWorkflow, TestInstance>(x => { x.AccessCurrentState(y => y.CurrentState); x.During(y => y.Initial) .When(y => y.Finish) .Then(() => _nonInstanceValue = true) .Then(instance => instance.MessageValue = "Success") .Then((instance, message) => instance.MessageValue = message.Value) .TransitionTo(y => y.Completed); }); _testInstance = new TestInstance(); _instance = _workflow.GetInstance(_testInstance); _instance.RaiseEvent(x => x.Finish, new Result { Value = "Success" }); }
public static ActorFactory <TActor> Create <TWorkflow, TActor>(Func <Inbox, TActor> createInstance, Action <StateMachineConfigurator <TWorkflow, TActor> > configurationAction) where TActor : class, Actor where TWorkflow : class { StateMachineWorkflow <TWorkflow, TActor> workflow = StateMachineWorkflow.New(configurationAction); var workflowBinder = new StateMachineWorkflowBinder <TWorkflow, TActor>(workflow); ActorFactory <TActor> factory = ActorFactory.Create <TActor>(x => { x.ConstructedBy(inbox => { TActor instance = createInstance(inbox); workflowBinder.Bind(inbox, instance); return(instance); }); }); return(factory); }
public StateMachineWorkflowBinder(StateMachineWorkflow <TWorkflow, TActor> workflow) { _workflow = workflow; _binders = BuildStateEventBinders(workflow); }
public ServiceControllerFactory() { _workflow = StateMachineWorkflow.New <IServiceWorkflow, IServiceController>(ConfigureWorkflow); _workflowBinder = new StateMachineWorkflowBinder <IServiceWorkflow, IServiceController>(_workflow); }
public WorkflowInstance(StateMachineWorkflow <TWorkflow, TInstance> workflow, TInstance instance) { _workflow = workflow; _instance = instance; }
public void Raising_multiple_events() { _workflow = StateMachineWorkflow.New<TestWorkflow, TestInstance>(x => { x.AccessCurrentState(y => y.CurrentState); x.During(y => y.Initial) .When(y => y.Start) .TransitionTo(y => y.Running); x.During(y => y.Running) .When(y => y.Finish) .TransitionTo(y => y.Completed); }); _instance = _workflow.GetInstance(new TestInstance()); _instance.RaiseEvent(x => x.Start); _instance.RaiseEvent(x => x.Finish); }
public void A_message_event_changes_the_state() { _workflow = StateMachineWorkflow.New<TestWorkflow, TestInstance>(x => { x.AccessCurrentState(y => y.CurrentState); x.During(y => y.Initial) .When(y => y.Finish) .TransitionTo(y => y.Completed); }); _instance = _workflow.GetInstance(new TestInstance()); _instance.RaiseEvent(x => x.Finish, new Result { Value = "Success" }); }
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); }