Esempio n. 1
0
        /// <summary>
        /// Get all events provided by an specified event source.
        /// </summary>
        /// <param name="eventSourceId">The id of the event source that owns the events.</param>
        /// <returns>All the events from the event source.</returns>
        public IEnumerable <ISourcedEvent> GetAllEventsSinceVersion(Guid id, long version)
        {
            var result = new List <ISourcedEvent>();

            // Create connection and command.
            using (var connection = new SqlConnection(_connectionString))
                using (var command = new SqlCommand(Queries.SelectAllEventsQuery, connection))
                {
                    // Add EventSourceId parameter and open connection.
                    command.Parameters.AddWithValue("EventSourceId", id);
                    command.Parameters.AddWithValue("EventSourceVersion", version);
                    connection.Open();

                    // Execute query and create reader.
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            StoredEvent <string> rawEvent = ReadEvent(reader);

                            var document = _translator.TranslateToCommon(rawEvent);
                            _converter.Upgrade(document);

                            var evnt = (ISourcedEvent)_formatter.Deserialize(document);
                            evnt.InitializeFrom(rawEvent);
                            result.Add(evnt);
                        }
                    }
                }

            return(result);
        }
Esempio n. 2
0
        private SourcedEvent ReadSourcedEvent(SqlDataReader reader)
        {
            StoredEvent <string> rawEvent = ReadEvent(reader);

            var document = _translator.TranslateToCommon(rawEvent);

            _converter.Upgrade(document);

            var evnt = (SourcedEvent)_formatter.Deserialize(document);

            evnt.InitializeFrom(rawEvent);
            return(evnt);
        }
Esempio n. 3
0
        /// <summary>Reads the current row in the <paramref name="reader"/> and translates it to a <see cref="CommittedEvent"/>.</summary>
        /// <param name="reader">The data record to read the current record from.</param>
        /// <returns>A fully populated <see cref="CommittedEvent"/> that contains the data from within the <paramref name="reader"/>.</returns>
        private CommittedEvent ReadEventFromDbReader(IDataRecord reader)
        {
            StoredEvent <string> rawEvent = ReadEvent(reader);

            var document = _translator.TranslateToCommon(rawEvent);

            _converter.Upgrade(document);

            var payload = _formatter.Deserialize(document.Data, document.EventName);

            // TODO: Legacy stuff... we do not have a dummy id with the current schema.
            var dummyCommitId = Guid.Empty;
            var evnt          = new CommittedEvent(dummyCommitId, document.EventIdentifier, document.EventSourceId, document.EventSequence, document.EventTimeStamp, payload, document.EventVersion);

            // TODO: Legacy stuff... should move.
            if (evnt is ISourcedEvent)
            {
                ((ISourcedEvent)evnt).InitializeFrom(rawEvent);
            }

            return(evnt);
        }