Пример #1
0
        public async Task <long> GetEventsAsync(string actorName, long indexStart, long indexEnd,
                                                Action <object> callback)
        {
            var count = indexEnd == long.MaxValue ? indexEnd - 1 : indexEnd - indexStart + 1;
            var start = indexStart;

            if (indexStart > 0)
            {
                start = indexStart - 1;
                count++;
            }

            var slice = await _connection.ReadEvents(_eventStreamNameStrategy(actorName), start, count, _stringToType);

            var events = slice.Events.ToList();

            if (start != indexStart && events.Count > 0)
            {
                events.RemoveAt(0);
            }

            foreach (var @event in events)
            {
                callback(@event);
            }

            return(slice.Version);
        }
Пример #2
0
        public async Task <TSaga> GetSaga(Guid correlationId)
        {
            var streamName = StreamName(correlationId);
            var data       = await _connection.ReadEvents(streamName, 512, _assemblyName);

            if (data == null)
            {
                return(null);
            }

            var saga = SagaFactory();

            saga.Initialize(data.Events);
            saga.CorrelationId   = correlationId;
            saga.ExpectedVersion = data.LastVersion;
            return(saga);
        }