public void Save(IEvent @event)
        {
            if (ContainsEvent(@event.Id))
            {
                return;
            }

            if (string.IsNullOrEmpty(@event.MachineName))
            {
                throw new Exception($"Machine name not specified on event {@event.Id}");
            }

            string serialized = EventSerialization.Serialize(@event);

            if (_events.ContainsKey(@event.AggregateId))
            {
                _events[@event.AggregateId].Add(serialized);
            }
            else
            {
                _events.Add(@event.AggregateId, new List <string> {
                    serialized
                });
            }
        }
        public IEnumerable <IEvent> GetEvents(Guid aggregateId)
        {
            List <string>        serializedEvents = _events[aggregateId];
            IEnumerable <IEvent> deserialized     = serializedEvents.Select(e => EventSerialization.Deserialize(e));

            return(deserialized.Cast <IEvent>());
        }
Beispiel #3
0
        public IEnumerable <IEvent> GetAllEventsFromMachine(string machineName)
        {
            Stopwatch            sw  = Stopwatch.StartNew();
            IEnumerable <IEvent> ret = GetSerializedEvents("select Serialized from events where MachineName = @MachineName COLLATE NOCASE;", new { MachineName = machineName })
                                       .Select(s => EventSerialization.Deserialize(s));

            _logger.Information("GetAllEventsFromMachine took {ElapsedMs}", sw.ElapsedMilliseconds);
            return(ret);
        }
Beispiel #4
0
        public IEnumerable <IEvent> GetEvents(Guid aggregateId)
        {
            List <string> serializedEvents =
                GetSerializedEvents("select Serialized from events WHERE AggregateId = @AggregateId", new { AggregateId = aggregateId.ToString() });

            IEnumerable <IEvent> deserializedEvents = serializedEvents.Select(s => EventSerialization.Deserialize(s));

            return(deserializedEvents.OrderBy(e => e.CreatedTimeUtc));
        }
Beispiel #5
0
        public static void InsertEvent(this SqliteConnection conn, IEvent @event)
        {
            string serialized = EventSerialization.Serialize(@event);

            string sql = @"INSERT INTO events(Id, AggregateId, AggregateType, CreatedTimeUtc, MachineName, Serialized)
                            VALUES(@Id, @AggregateId, @AggregateType, @CreatedTimeUtc, @MachineName, @Serialized);";

            conn.Execute(sql, new {
                Id          = @event.Id.ToString(),
                AggregateId = @event.AggregateId.ToString(),
                @event.AggregateType,
                @event.CreatedTimeUtc,
                @event.MachineName,
                Serialized = serialized
            });
        }
Beispiel #6
0
        public async Task PushEventsAsync(IEnumerable <IEvent> events)
        {
            Stopwatch sw = Stopwatch.StartNew();

            foreach (IEnumerable <IEvent> chunk in events.Chunk(EventPushBatchSize))
            {
                string serialized = await EventSerialization.SerializeAsync(chunk.ToList());

                StringContent content = new StringContent(serialized, Encoding.UTF8, "application/json");

                int serializedKiloByteCount = UnicodeEncoding.UTF8.GetByteCount(serialized) / 1024;
                _logger.Information("About to push {EventCount} events. Serialized size: {eventsSizeKb} kb", events.Count(), serializedKiloByteCount);

                HttpResponseMessage putResponse = await _client.PutAsync("/reitunes/saveevents", content);

                putResponse.EnsureSuccessStatusCode();
            }

            _logger.Information("Pushing all events took {ElapsedMs} ms", sw.ElapsedMilliseconds);
        }
Beispiel #7
0
 public IEnumerable <IEvent> GetAllEvents()
 {
     return(GetAllSerializedEvents().Select(s => EventSerialization.Deserialize(s)));
 }
        //TODO: this is stupid and slow, find a better way
        public IEnumerable <IEvent> GetAllEvents()
        {
            IEnumerable <string> serializedEvents = _events.Values.SelectMany(e => e);

            return(serializedEvents.Select(e => EventSerialization.Deserialize(e)));
        }
Beispiel #9
0
        public async Task <IEnumerable <IEvent> > PullAllEventsAsync()
        {
            List <string> allSerializedEvents = await PullAllSerializedEventsAsync();

            Stopwatch            sw  = Stopwatch.StartNew();
            IEnumerable <IEvent> ret = await Task.Run(() => allSerializedEvents.Select(e => EventSerialization.Deserialize(e)));

            _logger.Information("Deserializing {EventCount} events took {ElapsedMs} ms", ret.Count(), sw.ElapsedMilliseconds);

            return(ret);
        }