public async Task SalvarEvento <TEvent>(TEvent evento) where TEvent : Event
 {
     await _eventStoreService.GetConnection().AppendToStreamAsync(
         evento.AggregateId.ToString(),
         ExpectedVersion.Any,
         FormatarEvento(evento));
 }
示例#2
0
        public async Task <IEnumerable <StoredEvent> > ObterEventos(Guid aggregateId)
        {
            var eventos = await _eventStoreService.GetConnection()
                          .ReadStreamEventsBackwardAsync(aggregateId.ToString(), 0, 500, false);

            var listaEventos = new List <StoredEvent>();

            foreach (var resolveEvent in eventos.Events)
            {
                var dataEncoded = Encoding.UTF8.GetString(resolveEvent.Event.Data);

                var jsonData = JsonConvert.DeserializeObject <BaseEvent>(dataEncoded);

                var evento = new StoredEvent(
                    resolveEvent.Event.EventId,
                    resolveEvent.Event.EventType,
                    jsonData.Timestamp,
                    dataEncoded
                    );

                listaEventos.Add(evento);
            }

            return(listaEventos);
        }
示例#3
0
 public async Task PersistEvent <TEvent>(TEvent @event) where TEvent : Event
 {
     await _eventStoreService.GetConnection().AppendToStreamAsync(
         @event.AggregateId.ToString(),
         ExpectedVersion.Any,
         ToEventData(@event));
 }
示例#4
0
 public async Task SaveEvent <TEvent>(TEvent @event) where TEvent : Event
 {
     try
     {
         await _eventStoreService.GetConnection().AppendToStreamAsync(
             @event.AggregateId.ToString(),
             ExpectedVersion.Any,
             FormatEvent(@event));
     }
     catch (Exception ex)
     {
     }
 }