private void SaveEvents(Guid eventSourceId, IEnumerable<UncommittedEvent> events) { string eventSourceName = events.First().GetType().ToString(); long initialVersion = events.First().InitialVersionOfEventSource; long lastVersion = initialVersion + events.Count(); NcqrsEventStoreContext storeContext = new NcqrsEventStoreContext(eventSourceId, account, prefix); Guid commitId = storeContext.BeginCommit(); NcqrsEventSource lastSource = storeContext.LatestEventSource; if (lastSource == null) { lastSource = new NcqrsEventSource(eventSourceId, initialVersion, eventSourceName); } else if (lastSource.Version != initialVersion) { throw new ConcurrencyException(eventSourceId, initialVersion); } foreach (UncommittedEvent @event in events) { storeContext.Add(new NcqrsEvent(@event)); } lastSource.Version = lastVersion; storeContext.SaveSource(lastSource); storeContext.EndCommit(); }
private void SaveEvents(Guid eventSourceId, IEnumerable <UncommittedEvent> events) { string eventSourceName = events.First().GetType().ToString(); long initialVersion = events.First().InitialVersionOfEventSource; long lastVersion = initialVersion + events.Count(); NcqrsEventStoreContext storeContext = new NcqrsEventStoreContext(eventSourceId, account, prefix); Guid commitId = storeContext.BeginCommit(); NcqrsEventSource lastSource = storeContext.LatestEventSource; if (lastSource == null) { lastSource = new NcqrsEventSource(eventSourceId, initialVersion, eventSourceName); } else if (lastSource.Version != initialVersion) { throw new ConcurrencyException(eventSourceId, initialVersion); } foreach (UncommittedEvent @event in events) { storeContext.Add(new NcqrsEvent(@event)); } lastSource.Version = lastVersion; storeContext.SaveSource(lastSource); storeContext.EndCommit(); }
private void UpdateSource(NcqrsEventSource source) { if (_commitId == Guid.Empty) { throw new InvalidOperationException("Cannot update event sources without beginning a commit. Call the BeginCommit method"); } UpdateObject(source); }
private void AddSource(NcqrsEventSource source) { if (_commitId == Guid.Empty) { throw new InvalidOperationException("Cannot Add event sources without beginning a commit. Call the BeginCommit method"); } AddObject(EVENTSOURCETABLENAME, source); }
public void SaveSource(NcqrsEventSource source) { if (this.Entities.Contains(this.GetEntityDescriptor(source))) { UpdateSource(source); } else { AddSource(source); } }
private void UpdateSource(NcqrsEventSource source) { if (_commitId == Guid.Empty) { throw new InvalidOperationException("Cannot update event sources without beginning a commit. Call the BeginCommit method"); } UpdateObject(source); }
public void SaveSource(NcqrsEventSource source) { if (this.Entities.Contains(this.GetEntityDescriptor(source))) { UpdateSource(source); } else { AddSource(source); } }
private void AddSource(NcqrsEventSource source) { if (_commitId == Guid.Empty) { throw new InvalidOperationException("Cannot Add event sources without beginning a commit. Call the BeginCommit method"); } AddObject(EVENTSOURCETABLENAME, source); }