Ejemplo n.º 1
0
        public EventSourceVersion GetLastCommittedVersion(EventSource eventSource, Guid eventSourceId)
        {
            var version = EventSourceVersion.Zero;
            _client
                .ExecuteStoredProcedureAsync<double>(_getLastCommittedVersionStoredProcedure.SelfLink, eventSourceId)
                .ContinueWith(t => version = EventSourceVersion.FromCombined(t.Result))
                .Wait();

            return version;
        }
Ejemplo n.º 2
0
        public CommittedEventStream GetForEventSource(EventSource eventSource, Guid eventSourceId)
        {
            var eventSourceType = eventSource.GetType();
            var query = Query.And(
                            Query.EQ("EventSourceId", eventSourceId),
                            Query.EQ("EventSource", eventSourceType.AssemblyQualifiedName)
                        );

            var cursor = _collection.FindAs<BsonDocument>(query);
            var documents = cursor.ToArray();
            var events = ToEvents(documents);
            var stream = new CommittedEventStream(eventSourceId);
            stream.Append(events);
            return stream;
        }
Ejemplo n.º 3
0
        public CommittedEventStream GetForEventSource(EventSource eventSource, Guid eventSourceId)
        {
            using (var session = _documentStore.OpenSession())
            {
                var eventSourceType = eventSource.GetType();

                var events = session.Query<IEvent>()
                                    .Where(
                                        e => e.EventSourceId == eventSourceId &&
                                             e.EventSource == eventSourceType.AssemblyQualifiedName
                                        ).ToArray();

                var stream = new CommittedEventStream(eventSourceId);
                stream.Append(events);
                return stream;
            }
        }
Ejemplo n.º 4
0
        public EventSourceVersion GetLastCommittedVersion(EventSource eventSource, Guid eventSourceId)
        {
            var eventSourceParam = new OracleParameter(EventParameters.EVENTSOURCE, OracleDbType.NVarchar2, 512);
            eventSourceParam.Value = eventSource.GetType().AssemblyQualifiedName;

            var eventSourceIdParam = new OracleParameter(EventParameters.EVENTSOURCEID, OracleDbType.Raw, 16);
            eventSourceIdParam.Value = eventSourceId.ToByteArray();

            var version = EventSourceVersion.Zero;

            try
            {
                OpenConnection();
                using (var command = _connection.CreateCommand())
                {
                    command.CommandText = LAST_VERSION_STATEMENT;
                    command.Parameters.Add(eventSourceIdParam);
                    command.Parameters.Add(eventSourceParam);
                    command.BindByName = true;
                    var reader = command.ExecuteReader(CommandBehavior.SingleResult);
                    if (reader.Read())
                    {
                        version = EventSourceVersion.FromCombined(Convert.ToDouble(reader.GetDecimal(0)));
                    }
                }
            }
            finally
            {
                EnsureConnectionClosed(_connection);
            }

            return version;
        }
Ejemplo n.º 5
0
        public CommittedEventStream GetForEventSource(EventSource eventSource, Guid eventSourceId)
        {
            var committedEventStream = new CommittedEventStream(eventSourceId);

            var eventSourceParam = new OracleParameter(EventParameters.EVENTSOURCE, OracleDbType.NVarchar2, 512);
            eventSourceParam.Value = eventSource.GetType().AssemblyQualifiedName;

            var eventSourceIdParam = new OracleParameter(EventParameters.EVENTSOURCEID, OracleDbType.Raw, 16);
            eventSourceIdParam.Value = eventSourceId.ToByteArray();

            var eventDtos = new List<EventDto>();

            try
            {
                OpenConnection();
                using (var command = _connection.CreateCommand())
                {
                    command.CommandText = READ_STATEMENT_FOR_EVENTS_BY_AGGREGATE_ROOT;
                    command.Parameters.Add(eventSourceIdParam);
                    command.Parameters.Add(eventSourceParam);
                    command.BindByName = true;
                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        eventDtos.Add(MapReaderToEventDto(reader));
                    }
                }
            }
            finally
            {
                EnsureConnectionClosed(_connection);
            }

            var retrievedEvents = eventDtos.Select(BuildEventInstanceFromDto)
                                    .Select(@event => _eventMigratorManager.Migrate(@event))
                                    .ToList();

            if (retrievedEvents.Any())
                committedEventStream.Append(retrievedEvents);

            return committedEventStream;
        }
Ejemplo n.º 6
0
        public EventSourceVersion GetLastCommittedVersion(EventSource eventSource, Guid eventSourceId)
        {
            using (var session = _documentStore.OpenSession())
            {
                var @event = session.Query<IEvent>()
                                .Where(e => e.EventSourceId == eventSourceId)
                                    .OrderByDescending(e => e.Version)
                                .FirstOrDefault();

                if (@event == null)
                    return EventSourceVersion.Zero;

                return @event.Version;
            }
        }
Ejemplo n.º 7
0
        public EventSourceVersion GetLastCommittedVersion(EventSource eventSource, Guid eventSourceId)
        {
            var query = Query.EQ("EventSourceId", eventSourceId);
            var sort = SortBy.Descending(Version);
            var @event = _collection.FindAs<BsonDocument>(query).SetSortOrder(sort).FirstOrDefault();
            if (@event == null)
                return EventSourceVersion.Zero;

            return EventSourceVersion.FromCombined(@event[Version].AsDouble);
        }
Ejemplo n.º 8
0
 public EventSourceVersion GetLastCommittedVersion(EventSource eventSource, Guid eventSourceId)
 {
     var eventStoreVersion = _eventStore.GetLastCommittedVersion(eventSource, eventSourceId);
     var sagaVersion = _saga.GetLastCommittedVersion(eventSource, eventSourceId);
     return new[] { eventStoreVersion, sagaVersion }.Max();
 }
Ejemplo n.º 9
0
 public CommittedEventStream GetCommittedEventsFor(EventSource eventSource, Guid eventSourceId)
 {
     var stream = _eventStore.GetForEventSource(eventSource, eventSourceId);
     var sagaStream = _saga.GetForEventSource(eventSource, eventSourceId);
     stream.Append(sagaStream);
     return stream;
 }
Ejemplo n.º 10
0
#pragma warning disable 1591
        public CommittedEventStream GetForEventSource(EventSource eventSource, Guid eventSourceId)
        {
            throw new NotImplementedException();
        }
Ejemplo n.º 11
0
 public EventSourceVersion GetLastCommittedVersion(EventSource eventSource, Guid eventSourceId)
 {
     return _eventStore.GetLastCommittedVersion(eventSource, eventSourceId);
 }
Ejemplo n.º 12
0
 public CommittedEventStream GetCommittedEventsFor(EventSource eventSource, Guid eventSourceId)
 {
     return _eventStore.GetForEventSource(eventSource, eventSourceId);
 }
Ejemplo n.º 13
0
 public EventSourceVersion GetLastCommittedVersion(EventSource eventSource, Guid eventSourceId)
 {
     return EventSourceVersion.Zero;
 }
Ejemplo n.º 14
0
#pragma warning disable 1591 // Xml Comments
        public CommittedEventStream GetForEventSource(EventSource eventSource, Guid eventSourceId)
        {
            return new CommittedEventStream(eventSourceId);
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Indicates whether the Event Source maintains state and requires to handles events to restore that state
 /// </summary>
 /// <param name="eventSource"><see cref="EventSource"/> to test for state</param>
 /// <returns>true if the Event Source does not maintain state</returns>
 public static bool IsStateless(this EventSource eventSource)
 {
     return(GetHandleMethodsFor(eventSource.GetType()).Count == 0);
 }