Beispiel #1
0
        public async Task ReplayAllEvents()
        {
            using (var conn = new SqlConnection(_connectionString))
            {
                conn.Open();
                await EnsureStreamTableExists(conn).ConfigureAwait(false);

                var command = new SqlCommand("select * from events order by created asc", conn);
                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var eventType = (string)reader["eventName"];
                        var type      = _eventTypeCache.GetEventTypeFromName(eventType);
                        if (type == null)
                        {
                            continue;
                        }

                        var e = (IEvent)JsonConvert.DeserializeObject((string)reader["payload"], type);
                        await EventHandler.Invoke(e).ConfigureAwait(false);
                    }
                }
            }
        }
Beispiel #2
0
        public async Task ReplayAllEvents()
        {
            CheckCreateEventsFolder();

            var files = Directory.GetFiles(_folderPath, "*.stream.txt", SearchOption.TopDirectoryOnly);

            // Open all streams at once
            using (var s = new EventStreams(files.Select(File.OpenText)))
            {
                FileSystemEventRecord e;
                while ((e = await s.GetNextEventInChronologicalOrder().ConfigureAwait(false)) != null)
                {
                    var type = _typeCache.GetEventTypeFromName(e.EventName);
                    if (type == null)
                    {
                        continue;
                    }

                    var payload = (IEvent)JsonConvert.DeserializeObject(e.EventPayload, type);
                    await EventHandler(payload).ConfigureAwait(false);
                }
            }
        }