/// <inheritdoc/> public void Commit(TransactionCorrelationId correlationId, UncommittedEventStream uncommittedEventStream) { var envelopes = _eventEnvelopes.CreateFrom(uncommittedEventStream.EventSource, uncommittedEventStream.EventsAndVersion); var envelopesAsArray = envelopes.ToArray(); var eventsAsArray = uncommittedEventStream.ToArray(); var eventsAndEnvelopes = new List <EventAndEnvelope>(); for (var eventIndex = 0; eventIndex < eventsAsArray.Length; eventIndex++) { var envelope = envelopesAsArray[eventIndex]; var @event = eventsAsArray[eventIndex]; eventsAndEnvelopes.Add(new EventAndEnvelope( envelope .WithTransactionCorrelationId(correlationId) .WithSequenceNumber(_eventSequenceNumbers.Next()) .WithSequenceNumberForEventType(_eventSequenceNumbers.NextForType(envelope.Event)), @event )); } _eventStore.Commit(eventsAndEnvelopes); _eventSourceVersions.SetFor(envelopesAsArray[0].EventSource, envelopesAsArray[0].EventSourceId, envelopesAsArray[envelopesAsArray.Length - 1].Version); var committedEventStream = new CommittedEventStream(uncommittedEventStream.EventSourceId, eventsAndEnvelopes); _committedEventStreamSender.Send(committedEventStream); }
public CommittedEventStream Commit(UncommittedEventStream uncommittedEventStream) { var committedEventStream = new CommittedEventStream(uncommittedEventStream.EventSourceId); committedEventStream.Append(uncommittedEventStream); return(committedEventStream); }
public void Save(Type aggregatedRootType, Guid aggregateId, UncommittedEventStream eventsToSave) { var eventEntities = eventsToSave.Select(e => Convert(aggregatedRootType, aggregateId, e)); foreach (var @event in eventEntities) { _context.Insert(@event); } _context.Commit(); }
public void Save(UncommittedEventStream eventsToSave) { using (_localizer.BeginScope()) { _repository.Insert(eventsToSave); _eventSubscriptionManager.Process(eventsToSave); _eventStoreChangeManager.NotifyChanges(this); } }
public CommittedEventStream Commit(UncommittedEventStream uncommittedEventStream) { var events = uncommittedEventStream.Select(e => e).ToArray(); var parameters = new List<OracleParameter>(); var insertStatementBuilder = new StringBuilder(); insertStatementBuilder.Append("BEGIN "); for (var position = 0; position < events.Length; position++) { insertStatementBuilder.Append(GetParameterizedInsertStatement(position)); parameters.AddRange(_eventParameters.BuildFromEvent(position, events[position])); } insertStatementBuilder.Append(" END;"); Tuple<int, long>[] returnedIds; try { OpenConnection(); var transaction = _connection.BeginTransaction(); try { using (var command = _connection.CreateCommand()) { command.Transaction = transaction; command.CommandText = insertStatementBuilder.ToString(); command.Parameters.AddRange(parameters.ToArray()); command.BindByName = true; command.ExecuteNonQuery(); returnedIds = ExtractReturnedIds(parameters); transaction.Commit(); } } catch (Exception) { transaction.Rollback(); throw; } } finally { EnsureConnectionClosed(_connection); } PopulateEventId(returnedIds, events); var committedEventStream = new CommittedEventStream(uncommittedEventStream.EventSourceId); if (events.Any()) committedEventStream.Append(events); return committedEventStream; }
public CommittedEventStream Commit(UncommittedEventStream uncommittedEventStream) { var committedEventStream = new CommittedEventStream(uncommittedEventStream.EventSourceId); foreach( var @event in uncommittedEventStream ) { var serialized = _serializer.ToJson(@event, SerializationExtensions.SerializationOptions); _client .ExecuteStoredProcedureAsync<long>(_insertEventStoredProcedure.SelfLink, serialized) .ContinueWith(t => @event.Id = t.Result) .Wait(); committedEventStream.Append(@event); } return committedEventStream; }
public virtual void Rollback() { UncommittedEvents = new UncommittedEventStream(Id); Version = Version.PreviousCommit(); }
public virtual void Commit() { UncommittedEvents = new UncommittedEventStream(Id); Version = Version.NextCommit(); }
#pragma warning disable 1591 // Xml Comments public void Commit(UncommittedEventStream eventStream) { _scheduler.Start(() => _actualCoordinator.Commit(eventStream)); }
/// <summary> /// Initializes an instance of <see cref="EventSource">EventSource</see> /// </summary> /// <param name="id"><see cref="Events.EventSourceId"/> of the event source</param> protected EventSource(EventSourceId id) { EventSourceId = id; UncommittedEvents = new UncommittedEventStream(this); }
/// <summary> /// Initializes an instance of <see cref="EventSource">EventSource</see> /// </summary> /// <param name="id">Id of the event source</param> protected EventSource(Guid id) { Id = id; UncommittedEvents = new UncommittedEventStream(id); }
public CommittedEventStream Commit(UncommittedEventStream uncommittedEventStream) { var committedEventStream = new CommittedEventStream(uncommittedEventStream.EventSourceId); committedEventStream.Append(uncommittedEventStream); return committedEventStream; }
public CommittedEventStream Commit(UncommittedEventStream uncommittedEventStream) { var eventArray = uncommittedEventStream.ToArray(); for (var eventIndex = 0; eventIndex < eventArray.Length; eventIndex++) { var @event = eventArray[eventIndex]; @event.Id = GetNextEventId(); var eventDocument = @event.ToBsonDocument(); AddMetaData(@event, eventDocument); _collection.Insert(eventDocument); } var committedEventStream = new CommittedEventStream(uncommittedEventStream.EventSourceId); committedEventStream.Append(uncommittedEventStream); return committedEventStream; }
public CommittedEventStream Commit(UncommittedEventStream uncommittedEventStream) { using (var session = _documentStore.OpenSession()) { var eventArray = uncommittedEventStream.ToArray(); for (var eventIndex = 0; eventIndex < eventArray.Length; eventIndex++) { var @event = eventArray[eventIndex]; //session.Advanced. session.Store(@event); } session.SaveChanges(); var committedEventStream = new CommittedEventStream(uncommittedEventStream.EventSourceId); committedEventStream.Append(uncommittedEventStream); return committedEventStream; } }
public void Save(UncommittedEventStream eventsToSave) { }