Example #1
0
        /// <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);
        }
Example #2
0
        public CommittedEventStream Commit(UncommittedEventStream uncommittedEventStream)
        {
            var committedEventStream = new CommittedEventStream(uncommittedEventStream.EventSourceId);

            committedEventStream.Append(uncommittedEventStream);
            return(committedEventStream);
        }
Example #3
0
		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();
		}
Example #4
0
        public void Save(UncommittedEventStream eventsToSave)
        {
            using (_localizer.BeginScope())
            {
                _repository.Insert(eventsToSave);
                _eventSubscriptionManager.Process(eventsToSave);
                _eventStoreChangeManager.NotifyChanges(this);
            }
		}
Example #5
0
        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;
        }
Example #6
0
        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;
        }
Example #7
0
 public virtual void Rollback()
 {
     UncommittedEvents = new UncommittedEventStream(Id);
     Version           = Version.PreviousCommit();
 }
Example #8
0
 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));
        }
Example #10
0
 /// <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);
 }
Example #11
0
 public virtual void Rollback()
 {
     UncommittedEvents = new UncommittedEventStream(Id);
     Version = Version.PreviousCommit();
 }
Example #12
0
 public virtual void Commit()
 {
     UncommittedEvents = new UncommittedEventStream(Id);
     Version = Version.NextCommit();
 }
Example #13
0
 /// <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);
 }
Example #14
0
 public CommittedEventStream Commit(UncommittedEventStream uncommittedEventStream)
 {
     var committedEventStream = new CommittedEventStream(uncommittedEventStream.EventSourceId);
     committedEventStream.Append(uncommittedEventStream);
     return committedEventStream;
 }
Example #15
0
        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;
        }
Example #16
0
        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;
            }
        }
#pragma warning disable 1591 // Xml Comments
        public void Commit(UncommittedEventStream eventStream)
        {
            _scheduler.Start(() => _actualCoordinator.Commit(eventStream));
        }
Example #18
0
 /// <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);
 }
Example #19
0
 public void Save(UncommittedEventStream eventsToSave)
 {
 }