private static void AppendToStream() { using (var stream = store.OpenStream(StreamId)) { var @event = new SomeDomainEvent { Value = "Second event." }; stream.Add(new EventMessage { Body = @event }); stream.CommitChanges(Guid.NewGuid()); } }
private static void LoadFromSnapshotForwardAndAppend() { var latestSnapshot = store.Advanced.GetSnapshot(StreamId, int.MaxValue); using (var stream = store.OpenStream(latestSnapshot, int.MaxValue)) { var @event = new SomeDomainEvent { Value = "Third event (first one after a snapshot)." }; stream.Add(new EventMessage { Body = @event }); stream.CommitChanges(Guid.NewGuid()); } }
private static void OpenOrCreateStream() { // we can call CreateStream(StreamId) if we know there isn't going to be any data. // or we can call OpenStream(StreamId, 0, int.MaxValue) to read all commits, // if no commits exist then it creates a new stream for us. using (var stream = store.OpenStream(StreamId, 0, int.MaxValue)) { var @event = new SomeDomainEvent { Value = "Initial event." }; stream.Add(new EventMessage { Body = @event }); stream.CommitChanges(Guid.NewGuid()); } }