示例#1
0
        public async Task <StreamWriteResult> SaveEvents(EventStreamId eventStreamId, long streamVersion, List <DomainEvent> events)
        {
            if (events.Any() == false)
            {
                return(new StreamWriteResult(-1));
            }

            var commitId = Guid.NewGuid();

            var expectedVersion = streamVersion == 0 ? ExpectedVersion.NoStream : streamVersion - 1;
            var eventsToSave    = events.Select(domainEvent => ToEventData(commitId, domainEvent)).ToList();

            var result = await _connectionProvider.Connection.AppendToStreamAsync(
                stream : eventStreamId.ToString(),
                expectedVersion : expectedVersion,
                events : eventsToSave);

            return(new StreamWriteResult(result.NextExpectedVersion));
        }
示例#2
0
 public async Task <IList <DomainEvent> > GetEventsByStreamId(EventStreamId eventStreamId)
 {
     return(await GetEventsFromStreamVersion(eventStreamId.StreamName, StreamPosition.Start, eventStreamId.ResolveLinks));
 }