Example #1
0
 public StateMachineWithRollbackProvider(
     IStateMachineProvider <TContext, TStateId, TStatefulTaskWithRollback> realProvider,
     bool continueRollbackOnFailed)
 {
     _realProvider             = realProvider.ThrowIfNull(nameof(realProvider));
     _continueRollbackOnFailed = continueRollbackOnFailed;
 }
Example #2
0
 public static IStateMachineProvider <TContext, TStateId, TStatefulTask> CatchExceptions <TContext, TStateId, TStatefulTask>(
     this IStateMachineProvider <TContext, TStateId, TStatefulTask> provider,
     Action <Exception>?handler)
     where TStatefulTask : class, IStatefulTask <TContext, TStateId>
 {
     return(provider.CatchExceptions(continueExecutionOnFailed: false, handler));
 }
Example #3
0
        public Engine(IWorkItemRepository repository, IActivityRunner activityRunner,
            IStateMachineProvider stateMachineProvider)
        {
            if (repository == null) throw new ArgumentNullException("repository");
            if (activityRunner == null) throw new ArgumentNullException("activityRunner");
            if (stateMachineProvider == null) throw new ArgumentNullException("stateMachineProvider");

            _repository = repository;
            _activityRunner = activityRunner;
            _stateMachineProvider = stateMachineProvider;

            _stateQueue = new ActionBlock<int>(id => UpdateState(id),
                new ExecutionDataflowBlockOptions
                {
                    MaxDegreeOfParallelism = 1
                });

            _workerQueue = new ActionBlock<int>(id => RunActivity(id),
                new ExecutionDataflowBlockOptions
                {
                    MaxDegreeOfParallelism = int.MaxValue
                });

            _stateQueue.Completion.ContinueWith(t => { _workerQueue.Complete(); }, TaskContinuationOptions.OnlyOnFaulted);

            _workerQueue.Completion.ContinueWith(t => { ((IDataflowBlock) _stateQueue).Fault(t.Exception); },
                TaskContinuationOptions.OnlyOnFaulted);
        }
Example #4
0
 public static IStateMachineProvider <TContext, TStateId, TStatefulTask> CatchExceptions <TContext, TStateId, TStatefulTask>(
     this IStateMachineProvider <TContext, TStateId, TStatefulTask> provider,
     bool continueExecutionOnFailed)
     where TStatefulTask : class, IStatefulTask <TContext, TStateId>
 {
     return(provider.CatchExceptions(continueExecutionOnFailed, handler: null));
 }
Example #5
0
 public StateMachineSafeProvider(
     IStateMachineProvider <TContext, TStateId, TStatefulTask> realProvider,
     bool continueExecutionOnFailed,
     Action <Exception>?handler)
 {
     _realProvider = realProvider.ThrowIfNull(nameof(realProvider));
     _continueExecutionOnFailed = continueExecutionOnFailed;
     _handler = handler ?? (ex => Logger.Exception(ex));
 }
Example #6
0
 public static IStateMachineProvider <TContext, TStateId, IStatefulTaskWithRollback <TContext, TStateId> > WithRollbackOnException <TContext, TStateId, TStatefulTaskWithRollback>(
     this IStateMachineProvider <TContext, TStateId, TStatefulTaskWithRollback> provider,
     bool continueRollbackOnFailed)
     where TStatefulTaskWithRollback : class, IStatefulTaskWithRollback <TContext, TStateId>
 {
     return(new StateMachineWithRollbackProvider <TContext, TStateId, TStatefulTaskWithRollback>(
                provider, continueRollbackOnFailed
                ));
 }
Example #7
0
 public static IStateMachineProvider <TContext, TStateId, TStatefulTask> CatchExceptions <TContext, TStateId, TStatefulTask>(
     this IStateMachineProvider <TContext, TStateId, TStatefulTask> provider,
     bool continueExecutionOnFailed,
     Action <Exception>?handler)
     where TStatefulTask : class, IStatefulTask <TContext, TStateId>
 {
     return(new StateMachineSafeProvider <TContext, TStateId, TStatefulTask>(
                provider, continueExecutionOnFailed, handler
                ));
 }
Example #8
0
        public MainViewModel(IStateMachineProvider stateMachineProvider, IMessageBroker messageBroker, IDialogs dialogs)
        {
            this.dialogs = dialogs;

            stateMachine          = stateMachineProvider.GetStateMachine();
            messageBroker.OnSend += AppendMessage;

            InitializeStates();
            InitializeCommands();
            UpdateCurrentState();
            SetStateMachineInfo();
        }
Example #9
0
        public static TContext Execute <TContext, TStateId, TStatefulTask>(
            this IStateMachineProvider <TContext, TStateId, TStatefulTask> provider)
            where TStatefulTask : class, IStatefulTask <TContext, TStateId>
        {
            provider.ThrowIfNull(nameof(provider));

            using var enumerator = provider.GetStateMachineEnumerator();
            while (enumerator.MoveNext())
            {
                // All actions perform in MoveNext.
            }

            return(enumerator.Context);
        }
Example #10
0
        public BarStateflowProvider(IRepository <Bar> repository,
                                    IStateMachineProvider stateMachineProvider)
        {
            if (repository == null)
            {
                throw new ArgumentNullException(nameof(repository));
            }
            if (stateMachineProvider == null)
            {
                throw new ArgumentNullException(nameof(stateMachineProvider));
            }

            _repository           = repository;
            _stateMachineProvider = stateMachineProvider;
        }
Example #11
0
        public static Task <IStateMachine <EFooState, EFooAction> > GetStateMachineAsync(
            this IStateMachineProvider provider,
            Foo entity,
            CancellationToken cancellationToken
            )
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            return(provider.GetStateMachineAsync <Foo, EFooState, EFooAction>(
                       entity,
                       x => x.State,
                       (x, state) => x.ChangeState(state),
                       cancellationToken
                       ));
        }
Example #12
0
 public EngineTests()
 {
     _activityRunner = Substitute.For<IActivityRunner>();
     _stateMachineProvider = Substitute.For<IStateMachineProvider>();
     _engine = new Engine(_repository, _activityRunner, _stateMachineProvider);
 }
Example #13
0
 public static IStateMachineProvider <TContext, TStateId, IStatefulTaskWithRollback <TContext, TStateId> > WithRollbackOnException <TContext, TStateId, TStatefulTaskWithRollback>(
     this IStateMachineProvider <TContext, TStateId, TStatefulTaskWithRollback> provider)
     where TStatefulTaskWithRollback : class, IStatefulTaskWithRollback <TContext, TStateId>
 {
     return(provider.WithRollbackOnException(continueRollbackOnFailed: true));
 }