예제 #1
0
        private EventProviderTransaction CreateEventProviderTransaction(EventProvider eventProvider, SqlDomainEvent[] eventProviderEvents, SqlRevision[] eventProviderRevisions)
        {
            // create array for transactions revisions
            var revisions = new EventStreamRevision[eventProviderRevisions.Count()];

            SqlRevision revision = null;

            // loop through each revision adding domain events
            for (var revisionIterator = 0; revisionIterator < eventProviderRevisions.Length; revisionIterator++)
            {
                // get current revision
                revision = eventProviderRevisions[revisionIterator];

                // add revision to revision collection
                revisions[revisionIterator] = new DomainEventRevision(revision.EventProviderRevisionId,
                                                                      revision.EventProviderVersion,
                                                                      GetRevisionDomainEvents(eventProviderEvents, revision));
            }

            // return new event provider transaction
            return(new EventProviderTransaction(revision.TransactionId, eventProvider, _serializer.Deserialize <ICommand>(revision.CommandTypeId, revision.CommandData), new EventProviderDescriptor(revision.Descriptor), revisions, _serializer.Deserialize <List <Meta> >(revision.Metadata)));
        }
예제 #2
0
        private IDomainEvent[] GetRevisionDomainEvents(SqlDomainEvent[] eventProviderEvents, SqlRevision revision)
        {
            // get domain events for this revision ordered by sequence
            var revisionEvents = eventProviderEvents
                                 .Where(x => x.EventProviderRevisionId == revision.EventProviderRevisionId)
                                 .OrderBy(x => x.Sequence)
                                 .ToArray();

            var domainEvents = new IDomainEvent[revisionEvents.Length];

            // loop through each event to add to revision
            for (var revisionEventIterator = 0; revisionEventIterator < revisionEvents.Length; revisionEventIterator++)
            {
                // get current domain event
                var domainEvent = revisionEvents[revisionEventIterator];

                // deserialize domain event and add to collection
                domainEvents[revisionEventIterator] = _serializer.Deserialize <IDomainEvent>(domainEvent.EventTypeId, domainEvent.Data);
            }

            return(domainEvents);
        }