Esempio n. 1
0
 private static EventHandlingError CreateEventHandlingError(StorableEvent e) =>
 new EventHandlingError
 {
     AggregateId     = e.AggregateId,
     SequenceNumber  = e.SequenceNumber,
     SerializedEvent = e.Body,
     StreamName      = e.StreamName,
     EventTypeName   = e.Type,
     EventId         = e.Id
 };
Esempio n. 2
0
 /// <summary>
 /// Creates a domain event from a <see cref="StorableEvent" />.
 /// </summary>
 /// <param name="storableEvent">The storable event.</param>
 /// <returns>A deserialized domain event.</returns>
 public static IEvent ToDomainEvent(this StorableEvent storableEvent) =>
 Serializer.DeserializeEvent(
     storableEvent.StreamName,
     storableEvent.Type,
     storableEvent.AggregateId,
     storableEvent.SequenceNumber,
     storableEvent.Timestamp,
     storableEvent.Body,
     storableEvent.Id,
     serializerSettings.Value,
     etag: storableEvent.ETag);
Esempio n. 3
0
 private static EventHandlingError CreateEventHandlingError(StorableEvent e)
 {
     return(new EventHandlingError
     {
         Actor = e.Actor,
         AggregateId = e.AggregateId,
         SequenceNumber = e.SequenceNumber,
         SerializedEvent = e.Body,
         StreamName = e.StreamName,
         EventTypeName = e.Type,
         OriginalId = e.Id
     });
 }
Esempio n. 4
0
        private static Domain.EventHandlingError SerializationError(Exception ex, StorableEvent e)
        {
            var error = new EventHandlingDeserializationError(
                ex,
                e.Body,
                e.AggregateId,
                e.SequenceNumber,
                e.Timestamp,
                e.Actor,
                e.StreamName,
                e.Type);

            error.Metadata.AbsoluteSequenceNumber = e.Id;
            return(error);
        }
Esempio n. 5
0
 private void IncludeReadModelsNeeding(StorableEvent storedEvent)
 {
     if (unsubscribedReadModelInfos.Count > 0)
     {
         foreach (var readmodelInfo in unsubscribedReadModelInfos.ToArray())
         {
             if (storedEvent.Id >= readmodelInfo.CurrentAsOfEventId + 1)
             {
                 var handler = projectors.Single(p => ReadModelInfo.NameForProjector(p) == readmodelInfo.Name);
                 disposables.Add(bus.Subscribe(handler));
                 unsubscribedReadModelInfos.Remove(readmodelInfo);
                 subscribedReadModelInfos.Add(readmodelInfo);
             }
         }
     }
 }
Esempio n. 6
0
        private async Task <IEvent> UpdateProjectorsAndCursors(
            ExclusiveEventStoreCatchupQuery query,
            StorableEvent storedEvent,
            long eventsProcessedOutOfBatch,
            DateTimeOffset now)
        {
            var @event = storedEvent.ToDomainEvent();

            if (@event != null)
            {
                using (var work = CreateUnitOfWork(@event))
                {
                    var errors = new ConcurrentBag <Domain.EventHandlingError>();

                    using (CaptureErrorsFor(@event, into: errors))
                    {
                        await bus.PublishAsync(@event);
                    }

                    var infos = work.Resource <DbContext>().Set <ReadModelInfo>();

                    subscribedReadModelInfos
                    .Where(i => errors.All(err => err.Handler != i.Handler))
                    .ForEach(i =>
                    {
                        infos.Attach(i);
                        i.LastUpdated           = now;
                        i.CurrentAsOfEventId    = storedEvent.Id;
                        i.LatencyInMilliseconds = (now - @event.Timestamp).TotalMilliseconds;
                        i.BatchRemainingEvents  = query.BatchMatchedEventCount - eventsProcessedOutOfBatch;

                        if (eventsProcessedOutOfBatch == 1)
                        {
                            i.BatchStartTime   = now;
                            i.BatchTotalEvents = query.BatchMatchedEventCount;
                        }

                        if (i.InitialCatchupStartTime == null)
                        {
                            i.InitialCatchupStartTime   = now;
                            i.InitialCatchupTotalEvents = eventStoreTotalCount;
                        }

                        if (i.InitialCatchupEndTime == null)
                        {
                            if (i.CurrentAsOfEventId >= initialCatchupIsDoneAfterEventId)
                            {
                                i.InitialCatchupEndTime         = now;
                                i.InitialCatchupRemainingEvents = 0;
                            }
                            else
                            {
                                // initial catchup is still in progress
                                i.InitialCatchupRemainingEvents = query.TotalMatchedEventCount -
                                                                  eventsProcessedOutOfBatch;
                            }
                        }
                    });

                    work.VoteCommit();
                }
            }
            else
            {
                throw new SerializationException($"Deserialization: Event type '{storedEvent.StreamName}.{storedEvent.Type}' not found");
            }

            return(@event);
        }
Esempio n. 7
0
 private static EventHandlingError CreateEventHandlingError(StorableEvent e) =>
     new EventHandlingError
     {
         Actor = e.Actor,
         AggregateId = e.AggregateId,
         SequenceNumber = e.SequenceNumber,
         SerializedEvent = e.Body,
         StreamName = e.StreamName,
         EventTypeName = e.Type,
         OriginalId = e.Id
     };