Beispiel #1
0
        public MobTransitionResult Go(IEvent @event, Tuple <TEntity1, TEntity2> mob)
        {
            if (Stators.Count != 2)
            {
                throw StatorConfigurationException.MobEntitiesAndStateMachinesCountNotEquals(2, Stators.Count);
            }

            var rollbackActions   = new List <Action>();
            var transitionActions = new List <Func <Tuple <Type, bool, FailureTypes> > >();

            PrepareDelegates(mob.Item1, @event, rollbackActions, transitionActions);
            PrepareDelegates(mob.Item2, @event, rollbackActions, transitionActions);

            try
            {
                return(ProcessResult(transitionActions.Select(x => x?.Invoke()).ToArray()));
            }
            catch
            {
                if (_withRollbackOnFailure)
                {
                    rollbackActions.ForEach(x => x?.Invoke());
                }
                throw;
            }
        }
Beispiel #2
0
        public MobTransitionResult Go(IEvent @event, params object[] mob)
        {
            if (_typePreparersMap == null)
            {
                BuildMap(mob);
            }

            var entitiesCount = mob.Length;

            if (Stators.Count != entitiesCount)
            {
                throw StatorConfigurationException.MobEntitiesAndStateMachinesCountNotEquals(entitiesCount, Stators.Count);
            }

            var rollbackActions   = new List <Action>();
            var transitionActions = new List <Func <Tuple <Type, bool, FailureTypes> > >();

            foreach (var item in mob)
            {
                _typePreparersMap[item.GetType()](item, @event, rollbackActions, transitionActions);
            }

            try
            {
                return(ProcessResult(transitionActions.Select(x => x?.Invoke()).ToArray()));
            }
            catch
            {
                if (_withRollbackOnFailure)
                {
                    rollbackActions.ForEach(x => x?.Invoke());
                }
                throw;
            }
        }