public static Action <TNotification> BuildIntegrator <TConsumerData, TNotification, TLeftProvider, TRightProvider>( Action <TConsumerData, TNotification, TLeftProvider, TRightProvider> consumer, IDictionary <TypeContract, IReadOnlyCollection <CorrelationMap> > correlationMapsByConsumerDataContract, NotificationsByCorrelations notificationsByCorrelations, TLeftProvider leftProvider, TRightProvider rightProvider, IDictionary <TypeContract, Func <TConsumerData, JsonContent, TConsumerData> > consumerDataMappersByNotificationContract, Func <DateTimeOffset> clock) where TConsumerData : new() where TNotification : IDomainEvent { return(notification => { var handlerDataCorrelationMaps = correlationMapsByConsumerDataContract[typeof(TConsumerData).Contract()]; consumer ( FoldHandlerData ( MapsWithMappers(handlerDataCorrelationMaps, consumerDataMappersByNotificationContract), HandlerDataCorrelationsBy(handlerDataCorrelationMaps, notification), notificationsByCorrelations, consumerDataMappersByNotificationContract, new TConsumerData(), new NoEventId() ), notification, leftProvider, rightProvider ); }); }
public static Func <Event, NotificationsByPublisher> BuildPublisher <TPublisherData, TNotification>( Func <TPublisherData, TNotification, IEnumerable <IDomainEvent> > publisher, IDictionary <TypeContract, IReadOnlyCollection <CorrelationMap> > correlationMapsByPublisherDataContract, NotificationsByCorrelations notificationsByCorrelations, Func <IDomainEvent, IEnumerable <Correlation> > correlationsByNotification, IDictionary <TypeContract, Func <TPublisherData, JsonContent, TPublisherData> > publisherDataMappersByNotificationContract, Func <DateTimeOffset> clock) where TPublisherData : new() where TNotification : INotification { return(@event => { var handlerDataCorrelationMaps = correlationMapsByPublisherDataContract[typeof(TPublisherData).Contract()]; var notificaion = (TNotification)@event.Notification; return new NotificationsByPublisher { Notifications = publisher ( FoldHandlerData ( MapsWithMappers(handlerDataCorrelationMaps, publisherDataMappersByNotificationContract), HandlerDataCorrelationsBy(handlerDataCorrelationMaps, notificaion), notificationsByCorrelations, publisherDataMappersByNotificationContract, new TPublisherData(), @event.EventId ), notificaion ).Select ( n => new Tuple <IDomainEvent, IEnumerable <Correlation> > ( n, n.Correlations() ) ), PublisherDataCorrelations = HandlerDataCorrelationsBy ( correlationMapsByPublisherDataContract[typeof(TPublisherData).Contract()], notificaion ), When = clock() }; }); }
internal static void Handle( SubscriberMessage message, ProjectorsBySubscription <TProjectorUowProvider> projectorsBySubscription, NotificationsByCorrelations notificationsByCorrelations, Func <DateTimeOffset> clock, TProjectorUowProvider integrationProvider) { var consumer = projectorsBySubscription[message.Subscription]; consumer ( message.Event, notificationsByCorrelations, clock, integrationProvider ); }
internal static void Handle( SubscriberMessage message, PublishersBySubscription publishersBySubscription, NotificationsByCorrelations notificationsByCorrelations, Func <IEnumerable <Correlation>, int> publisherVersionByPublisherDataContractCorrelations, Func <DateTimeOffset> clock, Action <NotificationsByPublisherAndVersion> saveNotificationsByPublisherAndVersion, Action <IEnumerable <IDomainEvent> > notify) { var publisher = publishersBySubscription[message.Subscription]; var notificationsByPublisher = publisher( message.Event, notificationsByCorrelations, clock); var notificationsByPublisherAndVersion = Functions.AppendPublisherVersion( notificationsByPublisher, publisherVersionByPublisherDataContractCorrelations); saveNotificationsByPublisherAndVersion(notificationsByPublisherAndVersion); notify(notificationsByPublisher.Notifications.Select(x => x.Item1)); }
public static THandlerData FoldHandlerData <THandlerData>( IReadOnlyCollection <CorrelationMap> handlerDataCorrelationMaps, IEnumerable <Correlation> handlerDataCorrelations, NotificationsByCorrelations notificationsByCorrelations, IDictionary <TypeContract, Func <THandlerData, JsonContent, THandlerData> > handlerDataMappersByNotificationContract, THandlerData handlerData, EventId eventId) { if (!handlerDataCorrelationMaps.Any()) { return(handlerData); } var correlations = CorrelationsOfMatchingNotificationsBy ( handlerDataCorrelationMaps: handlerDataCorrelationMaps, handlerDataCorrelations: handlerDataCorrelations ).ToList(); if (!correlations.Any()) { return(handlerData); } var notifications = notificationsByCorrelations(correlations, eventId).ToList(); if (!notifications.Any()) { return(handlerData); } var content = new JsonContent(handlerData); handlerData = FoldHandlerData ( handlerDataMappersByNotificationContract, notifications, handlerData ); if (new JsonContent(handlerData).Equals(content)) { return(handlerData); } var unEvaluatedMaps = handlerDataCorrelationMaps .Where ( map => correlations .GroupBy(c => c.Contract) .Select(c => c.Key) .All(notificationContract => !notificationContract.Equals(map.NotificationContract)) ).ToList(); return(FoldHandlerData ( unEvaluatedMaps, HandlerDataCorrelationsByHandlerData(unEvaluatedMaps, handlerData), notificationsByCorrelations, handlerDataMappersByNotificationContract, handlerData, new NoEventId() )); }