Example #1
0
#pragma warning restore 1591 // Xml Comments


        /// <summary>
        /// Get handle method from an <see cref="EventSource"/> for a specific <see cref="IEvent"/>, if any
        /// </summary>
        /// <param name="eventSource"><see cref="EventSource"/> to get method from</param>
        /// <param name="event"><see cref="IEvent"/> to get method for</param>
        /// <returns><see cref="MethodInfo"/> containing information about the handle method, null if none exists</returns>
        public static MethodInfo GetOnMethod(this EventSource eventSource, IEvent @event)
        {
            var eventType     = @event.GetType();
            var handleMethods = GetHandleMethodsFor(eventSource.GetType());

            return(handleMethods.ContainsKey(eventType) ? handleMethods[eventType] : null);
        }
Example #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;
        }
Example #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;
            }
        }
Example #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;
        }
Example #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;
        }
Example #6
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);
 }