public async Task TryRestore(IAggregateRoot aggregate, string aggregateId) { if (!(aggregate is ISnapshotable)) { return; } var snapshot = await snapshotStore.Read(aggregateId); if (snapshot != null) { RestoreSnapshot(aggregate, snapshot); } }
public async Task <IAggregate> Load(Type type, object id) { // Do we have a snapshot? Initialize the root from that var snapshot = await snapshotStore.Read(type, id); var position = snapshot?.Version ?? 0L; var root = snapshot?.SnapshotData; // Read events from the stream (starting at the snapshot's version) var stream = new Stream(Categories.Events, type, id); IEnumerable <StoredMessage> messages = null; var events = new List <IEvent>(); do { messages = await messageStore.Read(stream, position, READ_BUFFER_SIZE); events.AddRange(messages.Select(x => (IEvent)x.Data)); position += messages.Count(); }while (messages.Count() == READ_BUFFER_SIZE); // Instantiate the aggregate return((IAggregate)Activator.CreateInstance(type, root, position, events)); }
public async Task <Snapshot> Read(Type type, object id) { return(await snapshotStore.Read(type, id)); }