コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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));
        }
コード例 #3
0
 public async Task <Snapshot> Read(Type type, object id)
 {
     return(await snapshotStore.Read(type, id));
 }