Пример #1
0
 /// <summary>
 /// The initial state for a workflow (named Initial) to which events can be attached
 /// </summary>
 /// <typeparam name="TWorkflow"></typeparam>
 /// <typeparam name="TInstance"></typeparam>
 /// <param name="stateMachineConfigurator"></param>
 /// <returns></returns>
 public static StateConfigurator <TWorkflow, TInstance> Initially <TWorkflow, TInstance>(
     this StateMachineConfigurator <TWorkflow, TInstance> stateMachineConfigurator)
     where TWorkflow : class
     where TInstance : class
 {
     return(stateMachineConfigurator.Initially(DoNothing));
 }
Пример #2
0
 /// <summary>
 /// Finally is triggered upon entry to the Final state
 /// </summary>
 /// <typeparam name="TWorkflow"></typeparam>
 /// <typeparam name="TInstance"></typeparam>
 /// <param name="stateMachineConfigurator"></param>
 /// <returns></returns>
 public static ActivityConfigurator <TWorkflow, TInstance> Finally <TWorkflow, TInstance>(
     this StateMachineConfigurator <TWorkflow, TInstance> stateMachineConfigurator)
     where TWorkflow : class
     where TInstance : class
 {
     return(stateMachineConfigurator.Finally(DoNothing));
 }
Пример #3
0
 /// <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));
 }
Пример #4
0
        public static StateConfigurator <TWorkflow, TInstance> DuringAny <TWorkflow, TInstance>(
            this StateMachineConfigurator <TWorkflow, TInstance> stateMachineConfigurator)
            where TWorkflow : class
            where TInstance : class
        {
            var stateConfigurator = new AnyStateConfigurator <TWorkflow, TInstance>();

            stateMachineConfigurator.AddConfigurator(stateConfigurator);

            return(stateConfigurator);
        }
Пример #5
0
        public static StateConfigurator <TWorkflow, TInstance> Initially <TWorkflow, TInstance>(
            this StateMachineConfigurator <TWorkflow, TInstance> stateMachineConfigurator,
            Action <StateConfigurator <TWorkflow, TInstance> > configurationAction)
            where TWorkflow : class
            where TInstance : class
        {
            var configurator = new StateConfiguratorImpl <TWorkflow, TInstance>(stateMachineConfigurator,
                                                                                StateMachineWorkflow.InitialStateName);

            stateMachineConfigurator.AddConfigurator(configurator);

            configurationAction(configurator);

            return(configurator);
        }
Пример #6
0
        public static StateConfigurator <TWorkflow, TInstance> During <TWorkflow, TInstance>(
            this StateMachineConfigurator <TWorkflow, TInstance> stateMachineConfigurator,
            Expression <Func <TWorkflow, State> > stateExpression,
            Action <StateConfigurator <TWorkflow, TInstance> > configurationAction)
            where TWorkflow : class
            where TInstance : class
        {
            var configurator = new StateConfiguratorImpl <TWorkflow, TInstance>(stateMachineConfigurator, stateExpression);

            stateMachineConfigurator.AddConfigurator(configurator);

            configurationAction(configurator);

            return(configurator);
        }
Пример #7
0
        /// <summary>
        /// Finally is triggered upon entry to the Final state
        /// </summary>
        /// <typeparam name="TWorkflow"></typeparam>
        /// <typeparam name="TInstance"></typeparam>
        /// <param name="stateMachineConfigurator"></param>
        /// <param name="configurationAction"></param>
        /// <returns></returns>
        public static ActivityConfigurator <TWorkflow, TInstance> Finally <TWorkflow, TInstance>(
            this StateMachineConfigurator <TWorkflow, TInstance> stateMachineConfigurator,
            Action <ActivityConfigurator <TWorkflow, TInstance> > configurationAction)
            where TWorkflow : class
            where TInstance : class
        {
            var stateConfigurator = stateMachineConfigurator.DuringAny();

            Expression <Func <State, Event> > selector = x => x.Entry;
            string eventName = StateMachineWorkflow.FinalStateName + "." + selector.MemberName();

            var activityConfigurator = new SimpleActivityConfigurator <TWorkflow, TInstance>(stateConfigurator, eventName);

            stateConfigurator.AddConfigurator(activityConfigurator);

            configurationAction(activityConfigurator);

            return(activityConfigurator);
        }
        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);
        }
Пример #9
0
 StateConfiguratorImpl(StateMachineConfigurator <TWorkflow, TInstance> stateMachineConfigurator)
 {
     _stateMachineConfigurator = stateMachineConfigurator;
     _configurators            = new List <StateBuilderConfigurator <TWorkflow, TInstance> >();
 }
Пример #10
0
 public StateConfiguratorImpl(StateMachineConfigurator <TWorkflow, TInstance> stateMachineConfigurator,
                              string stateName)
     : this(stateMachineConfigurator)
 {
     _getState = builder => builder.Model.GetState(stateName);
 }
Пример #11
0
 public StateConfiguratorImpl(StateMachineConfigurator <TWorkflow, TInstance> stateMachineConfigurator,
                              Expression <Func <TWorkflow, State> > stateExpression)
     : this(stateMachineConfigurator)
 {
     _getState = builder => builder.Model.GetState(stateExpression);
 }