Exemple #1
0
        public async Task Group(IQuerySession session, IEnumerable <IEvent> events, ITenantSliceGroup <Guid> grouping)
        {
            var licenceFeatureTogglesEvents = events
                                              .OfType <IEvent <LicenseFeatureToggled> >()
                                              .ToList();

            if (!licenceFeatureTogglesEvents.Any())
            {
                return;
            }

            // TODO -- let's build more samples first, but see if there's a useful
            // pattern for the next 3/4 operations later
            var licenceIds = licenceFeatureTogglesEvents
                             .Select(e => e.Data.LicenseId)
                             .ToList();

            var result = await session.Query <UserFeatureToggles>()
                         .Where(x => licenceIds.Contains(x.LicenseId))
                         .Select(x => new { x.Id, x.LicenseId })
                         .ToListAsync();

            var streamIds = (IDictionary <Guid, List <Guid> >)result.GroupBy(ks => ks.LicenseId, vs => vs.Id)
                            .ToDictionary(ks => ks.Key, vs => vs.ToList());

            grouping.AddEvents <LicenseFeatureToggled>(e => streamIds[e.LicenseId], licenceFeatureTogglesEvents);
        }
        public Task Group(
            IQuerySession session,
            IEnumerable <IEvent> events,
            ITenantSliceGroup <string> grouping
            )
        {
            var allocations = events
                              .OfType <IEvent <EmployeeAllocated> >();

            var monthlyAllocations = allocations
                                     .SelectMany(@event =>
                                                 @event.Data.Allocations.Select(
                                                     allocation => new
            {
                @event.Data.EmployeeId,
                Allocation = allocation,
                Month      = allocation.Day.ToStartOfMonth(),
                Source     = @event
            }
                                                     )
                                                 )
                                     .GroupBy(allocation =>
                                              new { allocation.EmployeeId, allocation.Month, allocation.Source }
                                              )
                                     .Select(monthlyAllocation =>
                                             new
            {
                Key   = $"{monthlyAllocation.Key.EmployeeId}|{monthlyAllocation.Key.Month:yyyy-MM-dd}",
                Event = monthlyAllocation.Key.Source.WithData(
                    new EmployeeAllocatedInMonth(
                        monthlyAllocation.Key.EmployeeId,
                        monthlyAllocation.Key.Month,
                        monthlyAllocation.Select(a => a.Allocation).ToList())
                    )
            }
                                             );

            foreach (var monthlyAllocation in monthlyAllocations)
            {
                grouping.AddEvents(
                    monthlyAllocation.Key,
                    new[] { monthlyAllocation.Event }
                    );
            }

            return(Task.CompletedTask);
        }
Exemple #3
0
 public void Apply(IEnumerable <IEvent> events, ITenantSliceGroup <TId> grouping)
 {
     grouping.AddEvents(_func, events);
 }