Esempio n. 1
0
 public void Apply(IReadModelContext context, IDomainEvent <ThingyAggregate, ThingyId, ThingyDeletedEvent> domainEvent)
 {
     context.MarkForDeletion();
 }
Esempio n. 2
0
 public void Apply(IReadModelContext context, IDomainEvent <CompetitionAggregate, CompetitionId, CompetitionDeletedEvent> domainEvent)
 {
     context.MarkForDeletion();
 }
 public void Apply(IReadModelContext context, IDomainEvent<TestAggregate, TestId, PingEvent> e)
 {
     PingsReceived++;
 }
Esempio n. 4
0
 public void Apply(IReadModelContext context, IDomainEvent <ThingyAggregate, ThingyId, ThingyDomainErrorAfterFirstEvent> domainEvent)
 {
     Id = domainEvent.AggregateIdentity.Value;
     DomainErrorAfterFirstReceived = true;
 }
Esempio n. 5
0
 public void Apply(IReadModelContext context, IDomainEvent <SchoolAggregate, SchoolId, InitialAgreementAchieved> domainEvent)
 {
     _status = GetSchools.SchoolStatus.HasAgreedInitially;
 }
Esempio n. 6
0
 public void Apply(IReadModelContext context, IDomainEvent <SchoolAggregate, SchoolId, FixedTermAgreementSigned> domainEvent)
 {
     _status           = GetSchools.SchoolStatus.HasSignedAgreement;
     _agreementEndDate = domainEvent.AggregateEvent.AgreementEndDate;
 }
 public void Apply(IReadModelContext context, IDomainEvent <TestAggregate, TestId, PingEvent> e)
 {
     PingEventsReceived = true;
 }
Esempio n. 8
0
 protected abstract Task <ReadModelUpdateResult <TReadModel> > UpdateAsync(
     IReadModelContext readModelContext,
     IReadOnlyCollection <IDomainEvent> domainEvents,
     ReadModelEnvelope <TReadModel> readModelEnvelope,
     CancellationToken cancellationToken);
Esempio n. 9
0
 public void Apply(IReadModelContext context, IDomainEvent <Product, ProductId, MagicNumberIcremented> domainEvent)
 {
     _id          = domainEvent.AggregateIdentity.Value;
     MagicNumber += domainEvent.AggregateEvent.MagicNumber;
 }
 public void Apply(IReadModelContext context, IDomainEvent <AggregateB, IdB, EventB> domainEvent)
 {
     _indexes.Add(domainEvent.AggregateEvent.Index);
 }
Esempio n. 11
0
        public override async Task UpdateAsync(IReadOnlyCollection <ReadModelUpdate> readModelUpdates, IReadModelContext readModelContext, Func <IReadModelContext, IReadOnlyCollection <IDomainEvent>, ReadModelEnvelope <TReadModel>, CancellationToken, Task <ReadModelEnvelope <TReadModel> > > updateReadModel, CancellationToken cancellationToken)
        {
            foreach (var update in readModelUpdates)
            {
                var envelope = await GetAsync(update.ReadModelId, cancellationToken).ConfigureAwait(false);

                var updatedModel = await updateReadModel(readModelContext, update.DomainEvents, envelope, cancellationToken).ConfigureAwait(false);

                await _dynamoDBContext.SaveAsync(updatedModel.ReadModel, cancellationToken).ConfigureAwait(false);
            }
        }
Esempio n. 12
0
 public void Apply(IReadModelContext context, IDomainEvent <ThingyAggregate, ThingyId, ThingyPingEvent> domainEvent)
 {
     Id = domainEvent.AggregateEvent.PingId;
 }
 public void Apply(IReadModelContext context, IDomainEvent <ThingyAggregate, ThingyId, ThingyMessageAddedEvent> domainEvent)
 {
     ThingyId = domainEvent.AggregateIdentity.Value;
     Message  = domainEvent.AggregateEvent.ThingyMessage.Message;
 }
Esempio n. 14
0
 public void Apply(IReadModelContext context, IDomainEvent <CargoAggregate, CargoId, CargoBookedEvent> domainEvent)
 {
     Id    = domainEvent.AggregateIdentity;
     Route = domainEvent.AggregateEvent.Route;
 }
 public void Apply(IReadModelContext context, IDomainEvent <TestAggregate, TestId, DomainErrorAfterFirstEvent> e)
 {
     DomainErrorAfterFirstEventsReceived = true;
 }
Esempio n. 16
0
 public abstract Task UpdateAsync(
     IReadOnlyCollection <ReadModelUpdate> readModelUpdates,
     IReadModelContext readModelContext,
     Func <IReadModelContext, IReadOnlyCollection <IDomainEvent>, ReadModelEnvelope <TReadModel>, CancellationToken, Task <ReadModelEnvelope <TReadModel> > > updateReadModel,
     CancellationToken cancellationToken);
Esempio n. 17
0
 public void Apply(IReadModelContext context, IDomainEvent <OrderAggregate, OrderId, OrderCreated> domainEvent)
 {
     this.Id       = domainEvent.AggregateIdentity.Value;
     this.Username = domainEvent.AggregateEvent.User.Value;
 }
 public void Apply(IReadModelContext context, IDomainEvent <ThingyAggregate, ThingyId, ThingyPingEvent> domainEvent)
 {
     PingsReceived++;
 }
        public async Task UpdateAsync(
            IReadOnlyCollection <ReadModelUpdate> readModelUpdates,
            IReadModelContext readModelContext,
            Func <IReadModelContext, IReadOnlyCollection <IDomainEvent>, ReadModelEnvelope <TReadModel>, CancellationToken, Task <ReadModelEnvelope <TReadModel> > > updateReadModel,
            CancellationToken cancellationToken)
        {
            var readModelDescription = _readModelDescriptionProvider.GetReadModelDescription <TReadModel>();

            _log.Verbose(() =>
            {
                var readModelIds = readModelUpdates
                                   .Select(u => u.ReadModelId)
                                   .Distinct()
                                   .OrderBy(i => i)
                                   .ToList();
                return($"Updating read models of type '{typeof(TReadModel).PrettyPrint()}' with IDs '{string.Join(", ", readModelIds)}' in node '{readModelDescription.RootNodeName}'");
            });

            foreach (var readModelUpdate in readModelUpdates)
            {
                try
                {
                    TReadModel firebaseResult = null;

                    if (_firebaseReadStoreConfiguration.UseBackupStore)
                    {
                        firebaseResult = await _readModelBackUpStore.GetAsync <TReadModel>(readModelDescription.RootNodeName.Value, readModelUpdate.ReadModelId, cancellationToken);
                    }
                    else
                    {
                        var response = await _firebaseClient.GetAsync($"{readModelDescription.RootNodeName}/{readModelUpdate.ReadModelId}");

                        var dynamicResult = response.ResultAs <dynamic>();

                        if (dynamicResult != null)
                        {
                            Dictionary <string, bool> children = new Dictionary <string, bool>();

                            foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(dynamicResult))
                            {
                                children.Add(prop.Name, true);
                            }

                            firebaseResult          = new TReadModel();
                            firebaseResult.Children = children;
                        }
                    }

                    var readModelEnvelope = (firebaseResult != null)
                        ? ReadModelEnvelope <TReadModel> .With(readModelUpdate.ReadModelId, firebaseResult)
                        : ReadModelEnvelope <TReadModel> .Empty(readModelUpdate.ReadModelId);

                    readModelEnvelope = await updateReadModel(
                        readModelContext,
                        readModelUpdate.DomainEvents,
                        readModelEnvelope,
                        cancellationToken).ConfigureAwait(false);

                    if (_firebaseReadStoreConfiguration.UseBackupStore)
                    {
                        if (readModelEnvelope.ReadModel.Children != null && readModelEnvelope.ReadModel.Children.Count > 0)
                        {
                            await _readModelBackUpStore.UpdateAsync(readModelDescription.RootNodeName.Value, readModelUpdate.ReadModelId, readModelEnvelope.ReadModel, cancellationToken);

                            await _readModelBackUpStore.TryFirebaseCoupleOfTimesAsync <TReadModel, SetResponse, Dictionary <string, bool> >(_firebaseClient.SetAsync, readModelDescription.RootNodeName.Value, readModelUpdate.ReadModelId, readModelEnvelope.ReadModel.Children);
                        }
                        else
                        {
                            await _readModelBackUpStore.DeleteOneAsync <TReadModel>(readModelDescription.RootNodeName.Value, readModelUpdate.ReadModelId, cancellationToken);

                            await _readModelBackUpStore.TryFirebaseCoupleOfTimesAsync <TReadModel, FirebaseResponse>(_firebaseClient.DeleteAsync, readModelDescription.RootNodeName.Value, readModelUpdate.ReadModelId);
                        }
                    }
                    else
                    {
                        if (readModelEnvelope.ReadModel.Children != null && readModelEnvelope.ReadModel.Children.Count > 0)
                        {
                            await _firebaseClient.SetAsync($"{readModelDescription.RootNodeName}/{readModelUpdate.ReadModelId}", readModelEnvelope.ReadModel.Children);
                        }
                        else
                        {
                            await _firebaseClient.DeleteAsync($"{readModelDescription.RootNodeName}/{readModelUpdate.ReadModelId}");
                        }
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
Esempio n. 20
0
 public void Apply(IReadModelContext context, IDomainEvent <SchoolAggregate, SchoolId, PermanentAgreementSigned> domainEvent)
 {
     _status           = GetSchools.SchoolStatus.HasSignedAgreement;
     _agreementEndDate = null;
 }
Esempio n. 21
0
 public void Apply(IReadModelContext context, IDomainEvent <InventoryItemAggregate, InventoryItemId, InventoryItemRenamedEvent> domainEvent)
 {
     Name = domainEvent.AggregateEvent.NewName;
 }
Esempio n. 22
0
 public void Apply(IReadModelContext context, IDomainEvent <SchoolAggregate, SchoolId, SchoolResignedFromCooperation> domainEvent)
 {
     _status             = GetSchools.SchoolStatus.HasResigned;
     _resignationEndDate = domainEvent.AggregateEvent.PotentialNextContactDate;
 }
Esempio n. 23
0
 public void Apply(IReadModelContext context, IDomainEvent <InventoryItemAggregate, InventoryItemId, InventoryItemDeactivatedEvent> domainEvent)
 {
     context.MarkForDeletion();
 }
 public void Apply(IReadModelContext context, IDomainEvent<TestAggregate, TestId, DomainErrorAfterFirstEvent> e)
 {
     DomainErrorAfterFirstReceived = true;
 }
Esempio n. 25
0
 public void Apply(IReadModelContext context, IDomainEvent <InventoryItemAggregate, InventoryItemId, InventoryItemCreatedEvent> domainEvent)
 {
     Id   = domainEvent.AggregateIdentity.ToString();
     Name = domainEvent.AggregateEvent.Name;
 }
Esempio n. 26
0
 public void Apply(IReadModelContext context, IDomainEvent <ThingyAggregate, ThingyId, ThingyPingEvent> domainEvent)
 {
     Id = domainEvent.AggregateIdentity.Value;
     PingsReceived++;
 }
Esempio n. 27
0
        public async Task UpdateAsync(IReadOnlyCollection <ReadModelUpdate> readModelUpdates, IReadModelContext readModelContext, Func <IReadModelContext, IReadOnlyCollection <IDomainEvent>, ReadModelEnvelope <TReadModel>, CancellationToken, Task <ReadModelEnvelope <TReadModel> > > updateReadModel, CancellationToken cancellationToken)
        {
            var readModelDescription = _readModelDescriptionProvider.GetReadModelDescription <TReadModel>();

            _log.Verbose(() =>
            {
                var readModelIds = readModelUpdates
                                   .Select(u => u.ReadModelId)
                                   .Distinct()
                                   .OrderBy(i => i)
                                   .ToList();
                return($"Updating read models of type '{typeof(TReadModel).PrettyPrint()}' with _ids '{string.Join(", ", readModelIds)}' in collection '{readModelDescription.RootCollectionName}'");
            });

            foreach (var readModelUpdate in readModelUpdates)
            {
                var collection        = _mongoDatabase.GetCollection <TReadModel>(readModelDescription.RootCollectionName.Value);
                var readModelEnvelope = ReadModelEnvelope <TReadModel> .Empty(readModelUpdate.ReadModelId);

                readModelEnvelope = await updateReadModel(readModelContext, readModelUpdate.DomainEvents, readModelEnvelope, cancellationToken).ConfigureAwait(false);

                readModelEnvelope.ReadModel._id = ObjectIdGenerator.Instance.GenerateId(collection, readModelEnvelope.ReadModel);
                await collection.InsertOneAsync(
                    readModelEnvelope.ReadModel,
                    new InsertOneOptions { BypassDocumentValidation = true },
                    cancellationToken);
            }
        }
Esempio n. 28
0
 public void Apply(IReadModelContext context, IDomainEvent <CompetitionAggregate, CompetitionId, EntryTimeCorrectedEvent> domainEvent)
 {
     TimeInMillis = domainEvent.AggregateEvent.TimeInMillis;
 }
 public void Apply(IReadModelContext context,
                   IDomainEvent <Domain.Booking.Booking, BookingId, PassengerAddedEvent> domainEvent)
 {
     Passengers.Add(domainEvent.AggregateEvent.Passenger.ToReadModel());
 }
Esempio n. 30
0
 public void Apply(
     IReadModelContext context,
     IDomainEvent <ExampleAggregate, ExampleId, ExampleEvent> domainEvent)
 {
     MagicNumber.Add(domainEvent.AggregateEvent.MagicNumber);
 }
Esempio n. 31
0
 public void Apply(IReadModelContext context, IDomainEvent <TreatmentMachineAggregate, TreatmentMachineId, TreatmentMachineWithAdvancedCapabilityIsAddedEvent> domainEvent)
 {
     Id   = domainEvent.AggregateEvent.Id.Value;
     Name = domainEvent.AggregateEvent.Name;
     HasAdvancedCapability = true;
 }
Esempio n. 32
0
 public void Apply(IReadModelContext context, IDomainEvent <Aggregate, AggregateIdentity, Event> domainEvent)
 {
     Formula = domainEvent.AggregateEvent.Formula;
 }
Esempio n. 33
0
 public ReadModelProductDao(IReadModelContext context)
 {
     if (context == null) throw new ArgumentNullException(nameof(context));
     _context = context;
 }