/// <summary>Persists the <paramref name="eventStream"/> in the store as a single and atomic commit.</summary> /// <exception cref="ConcurrencyException">Occurs when there is already a newer version of the event provider stored in the event store.</exception> /// <param name="eventStream">The <see cref="UncommittedEventStream"/> to commit.</param> public void Store(UncommittedEventStream eventStream) { if (!eventStream.Any()) { return; } using (var connection = new SqlConnection(_connectionString)) { connection.Open(); try { using (var transaction = connection.BeginTransaction()) { try { if (eventStream.HasSingleSource) { var firstEvent = eventStream.First(); var newVersion = firstEvent.InitialVersionOfEventSource + eventStream.Count(); StoreEventsFromSource(eventStream.SourceId, newVersion, eventStream, transaction); } else { StoreMultipleSources(eventStream, transaction); } transaction.Commit(); } catch { transaction.Rollback(); throw; } } } finally { connection.Close(); } } }
/// <summary>Persists the <paramref name="eventStream"/> in the store as a single and atomic commit.</summary> /// <exception cref="ConcurrencyException">Occurs when there is already a newer version of the event provider stored in the event store.</exception> /// <param name="eventStream">The <see cref="UncommittedEventStream"/> to commit.</param> public void Store(UncommittedEventStream eventStream) { if (!eventStream.Any()) return; using (var connection = new SqlConnection(_connectionString)) { connection.Open(); try { using (var transaction = connection.BeginTransaction()) { try { if (eventStream.HasSingleSource) { var firstEvent = eventStream.First(); var newVersion = firstEvent.InitialVersionOfEventSource + eventStream.Count(); StoreEventsFromSource(eventStream.SourceId, newVersion, eventStream, transaction); } else { StoreMultipleSources(eventStream, transaction); } transaction.Commit(); } catch { transaction.Rollback(); throw; } } } finally { connection.Close(); } } }