Пример #1
0
        public virtual async Task <IReadOnlyCollection <IDomainEvent <TAggregate, TIdentity> > > LoadEventsAsync <TAggregate, TIdentity>(
            TIdentity id,
            CancellationToken cancellationToken)
            where TAggregate : IAggregateRoot <TIdentity>
            where TIdentity : IIdentity
        {
            var committedDomainEvents = await LoadCommittedEventsAsync <TAggregate, TIdentity>(id, cancellationToken).ConfigureAwait(false);

            var domainEvents = (IReadOnlyCollection <IDomainEvent <TAggregate, TIdentity> >)committedDomainEvents
                               .Select(e => EventJsonSerializer.Deserialize <TAggregate, TIdentity>(id, e))
                               .ToList();

            if (!domainEvents.Any())
            {
                return(domainEvents);
            }

            domainEvents = EventUpgradeManager.Upgrade(domainEvents);

            return(domainEvents);
        }
Пример #2
0
        public async Task <AllEventsPage> LoadAllEventsAsync(
            GlobalPosition globalPosition,
            int pageSize,
            CancellationToken cancellationToken)
        {
            if (pageSize <= 0)
            {
                throw new ArgumentOutOfRangeException("pageSize");
            }

            var allCommittedEventsPage = await LoadAllCommittedDomainEvents(
                globalPosition,
                pageSize,
                cancellationToken)
                                         .ConfigureAwait(false);

            var domainEvents = (IReadOnlyCollection <IDomainEvent>)allCommittedEventsPage.CommittedDomainEvents
                               .Select(e => EventJsonSerializer.Deserialize(e))
                               .ToList();

            domainEvents = EventUpgradeManager.Upgrade(domainEvents);
            return(new AllEventsPage(allCommittedEventsPage.NextGlobalPosition, domainEvents));
        }