Пример #1
0
 public void End()
 {
     if (player1Score > player2Score)
     {
         //publish an event notifying that the match ended and Player1 is the winner
         domainEventDispatcher.Publish <MatchEnded>(new MatchEnded(PlayerType.Player1));
     }
     else
     {
         //publish an event notifying that the match ended and Player1 is the winner
         domainEventDispatcher.Publish <MatchEnded>(new MatchEnded(PlayerType.Player2));
     }
 }
Пример #2
0
        protected override void Dispatch(QueueItem queueItem)
        {
            var domainEventQueueItem = queueItem as QueueItem <IDomainEvent>;

            if (domainEventQueueItem == null)
            {
                var contextItem = queueItem as QueueItem <IDomainEventHandlerContext>;
                Contract.Assume(contextItem != null);

                _domainEventDispatcher.Publish(contextItem.Items);
            }
            else
            {
                _domainEventDispatcher.Publish(domainEventQueueItem.Items);
            }
        }
Пример #3
0
 public void Play(PlayType play)
 {
     //delayed event to notify of the move choosen by the player
     _dispatcher.Add <PlayMade>(new PlayMade(_player, play));
     if (play == PlayType.None)
     {
         _dispatcher.Publish <InvalidPlay>(new InvalidPlay(_player, play));
     }
 }
Пример #4
0
        protected override void TransactionCommitted(EventProviderTransaction transaction)
        {
            // get domain events
            var domainEvents = transaction.GetDomainEvents();

            // get metadata
            var metadata = new MetaCollection(transaction.Metadata);

            // create contexts
            var contexts = domainEvents.Select(x => new DomainEventHandlerContext(x, metadata))
                           .ToArray();

            // public contexts
            _dispatcher.Publish(contexts);
        }
Пример #5
0
        public static async Task <DbContext> DispatchEventsAsync(this DbContext context,
                                                                 IDomainEventDispatcher eventDispatcher, ILogger logger, CancellationToken cancellationToken)
        {
            logger.LogDebug("Start dispatching events");
            while (true)
            {
                var allDomainEvents = context.ChangeTracker.Entries <IHasDomainEvent>()
                                      .Select(x => x.Entity.DomainEvents)
                                      .SelectMany(x => x);
                var domainEventEntity = allDomainEvents.FirstOrDefault(domainEvent => !domainEvent.IsPublished);
                if (domainEventEntity == null)
                {
                    break;
                }

                domainEventEntity.IsPublished = true;
                await eventDispatcher.Publish(domainEventEntity, cancellationToken);
            }

            return(context);
        }
Пример #6
0
        public override void Handle(ProcessDomainEventMessage message, string correlationId)
        {
            Contract.Requires(message?.DomainEvent != null);

            _dispatcher.Publish(message.DomainEvent);
        }