Exemplo n.º 1
0
        public ApplyStateContextFacts()
        {
            _methodData = MethodData.FromExpression(() => Console.WriteLine());
            _newStateMock = new Mock<State>();
            _newStateMock.Setup(x => x.Name).Returns(NewState);

            _transaction = new Mock<IWriteOnlyTransaction>();
            
            _filters = new List<IApplyStateFilter>();
            _handlers = new StateHandlerCollection();
        }
Exemplo n.º 2
0
        internal void ApplyState(
            StateHandlerCollection handlers, IEnumerable<IApplyStateFilter> filters)
        {
            if (handlers == null) throw new ArgumentNullException("handlers");
            if (filters == null) throw new ArgumentNullException("filters");

            using (var transaction = _connection.CreateWriteTransaction())
            {
                foreach (var handler in handlers.GetHandlers(OldStateName))
                {
                    handler.Unapply(this, transaction);
                }

                foreach (var filter in filters)
                {
                    filter.OnStateUnapplied(this, transaction);
                }

                transaction.SetJobState(JobId, NewState);

                foreach (var handler in handlers.GetHandlers(NewState.Name))
                {
                    handler.Apply(this, transaction);
                }

                foreach (var filter in filters)
                {
                    filter.OnStateApplied(this, transaction);
                }

                if (NewState.ExpireJobOnApply)
                {
                    transaction.ExpireJob(JobId, JobExpirationTimeout);
                }
                else
                {
                    transaction.PersistJob(JobId);
                }

                transaction.Commit();
            }
        }
 public StateHandlerCollectionFacts()
 {
     _collection = new StateHandlerCollection();
 }