示例#1
0
        public async Task PersistEventsAsync(IEnumerable <object> @event)
        {
            if (!UsingEventSourcing)
            {
                throw new Exception("Event cannot be persisted without using Event Sourcing.");
            }

            var persistedEvents = @event.Select((x, i) => new PersistedEvent(x, Index + 1 + i)).ToList();

            await _eventStore.PersistEventsAsync(_actorId, persistedEvents);

            Index += persistedEvents.Count;

            foreach (var persistedEvent in persistedEvents)
            {
                _applyEvent(persistedEvent);

                if (!_snapshotStrategy.ShouldTakeSnapshot(persistedEvent))
                {
                    continue;
                }

                var persistedSnapshot = new PersistedSnapshot(_getState(), persistedEvent.Index);

                await _snapshotStore.PersistSnapshotAsync(_actorId, persistedSnapshot.Index,
                                                          persistedSnapshot.State);
            }
        }
示例#2
0
        public async Task PersistSnapshotAsync(object snapshot)
        {
            var persistedSnapshot = new PersistedSnapshot(snapshot, Index);

            await _snapshotStore.PersistSnapshotAsync(_actorId, persistedSnapshot.Index, snapshot);

            _applySnapshot(persistedSnapshot);
        }
        public async Task PersistEventAsync(object @event)
        {
            if (!UsingEventSourcing)
            {
                throw new Exception("Event cannot be persisted without using Event Sourcing.");
            }

            var persistedEvent = new PersistedEvent(@event, (Index + 1));

            await _eventStore.PersistEventAsync(_actorId, persistedEvent.Index, persistedEvent.Data);

            Index++;

            _applyEvent(persistedEvent);

            if (_snapshotStrategy.ShouldTakeSnapshot(persistedEvent))
            {
                var persistedSnapshot = new PersistedSnapshot(_getState(), persistedEvent.Index);

                await _snapshotStore.PersistSnapshotAsync(_actorId, persistedSnapshot.Index, persistedSnapshot.State);
            }
        }
示例#4
0
        public Task PersistSnapshotAsync(object snapshot)
        {
            var persistedSnapshot = new PersistedSnapshot(snapshot, Index);

            return(_snapshotStore.PersistSnapshotAsync(_actorId, persistedSnapshot.Index, snapshot));
        }