Пример #1
0
        public async Task HandleAsync(EntityCreatedEvent <Entities.Product> domainEvent, CancellationToken cancellationToken = default)
        {
            await _dispatcher.DispatchAsync(new AddAuditLogEntryCommand
            {
                AuditLogEntry = new AuditLogEntry
                {
                    UserId          = _currentUser.IsAuthenticated ? _currentUser.UserId : Guid.Empty,
                    CreatedDateTime = domainEvent.EventDateTime,
                    Action          = "CREATED_PRODUCT",
                    ObjectId        = domainEvent.Entity.Id.ToString(),
                    Log             = domainEvent.Entity.AsJsonString(),
                },
            });

            await _eventLogRepository.AddOrUpdateAsync(new EventLog
            {
                EventType       = "PRODUCT_CREATED",
                TriggeredById   = _currentUser.UserId,
                CreatedDateTime = domainEvent.EventDateTime,
                ObjectId        = domainEvent.Entity.Id.ToString(),
                Message         = domainEvent.Entity.AsJsonString(),
                Published       = false,
            }, cancellationToken);

            await _eventLogRepository.UnitOfWork.SaveChangesAsync(cancellationToken);
        }
Пример #2
0
        public void Handle(EntityCreatedEvent message)
        {
            if (_identityMap.ContainsKey(message.EntityID))
            {
                return;
            }

            var constructor =
                typeof(T)
                .GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)
                .Single(c =>
            {
                var parameters = c.GetParameters().ToList();
                if (parameters.Count == 1 && parameters.Single().ParameterType == typeof(EntityCreatedEvent))
                {
                    return(true);
                }

                return(false);
            });

            T entity = (T)constructor.Invoke(new object[] { message });

            //entity.AttachToModel(_parent.Model);
            _identityMap[entity.EntityID] = entity;
            _collection.Add(entity);
            entity.Parent = _parent;
        }
Пример #3
0
 public void Handle(EntityCreatedEvent message)
 {
     if (_whereEntityId(message.EntityID) && message.Changes.ContainsKey(_propertyName))
     {
         _triggerAction(message);
     }
 }
Пример #4
0
        private EntityCreatedEvent EventStreamRoundTripEvent(EntityCreatedEvent evt)
        {
            EventStreamHeader header = new EventStreamHeader(new VectorClock(), new Infrastructure.VectorClock(), Guid.NewGuid(), Guid.NewGuid());

            MemoryStream stream = new MemoryStream();

            using (EventStreamWriter writer = new EventStreamWriter(stream, header, false))
            {
                writer.WriteEvent(evt);
            }

            stream.Seek(0, SeekOrigin.Begin);

            using (stream)
                using (EventStreamReader reader = new EventStreamReader(stream))
                {
                    while (reader.Read())
                    {
                        if (reader.ItemType == ItemType.Event)
                        {
                            return((EntityCreatedEvent)reader.CurrentEvent);
                        }
                    }
                }

            throw new InvalidOperationException("The event could not be round tripped");
        }
Пример #5
0
 public void Handle(EntityCreatedEvent <SmsMessage> domainEvent)
 {
     // Handle the event here and we can also forward to external systems
     _smsMessageCreatedEventSender.Send(new SmsMessageCreatedEvent {
         Id = domainEvent.Entity.Id
     });
 }
        public void Handle(EntityCreatedEvent <FileEntry> domainEvent)
        {
            using (var scope = _serviceProvider.CreateScope())
            {
                var auditSerivce = scope.ServiceProvider.GetService <IAuditLogService>();
                var currentUser  = scope.ServiceProvider.GetService <ICurrentUser>();

                auditSerivce.AddOrUpdate(new AuditLogEntryDTO
                {
                    UserId          = currentUser.IsAuthenticated ? currentUser.UserId : Guid.Empty,
                    CreatedDateTime = domainEvent.EventDateTime,
                    Action          = "CREATED_FILEENTRY",
                    ObjectId        = domainEvent.Entity.Id.ToString(),
                    Log             = domainEvent.Entity.AsJsonString(),
                });

                IMessageSender <FileUploadedEvent> fileUploadedEventSender = scope.ServiceProvider.GetService <IMessageSender <FileUploadedEvent> >();

                // Forward to external systems
                fileUploadedEventSender.Send(new FileUploadedEvent
                {
                    FileEntry = domainEvent.Entity,
                });
            }
        }
Пример #7
0
        public void CreateSubTransaction()
        {
            Account     Account     = TestBudget.Budget.Accounts[0];
            Transaction transaction = new Transaction();

            transaction.MakeSplitTransaction();
            Account.Transactions.Add(transaction);

            var subTransaction = transaction.SubTransactions.Create();

            subTransaction.Amount = 100;

            TestBudget.BudgetModel.SaveChanges();
            Assert.That(TestBudget.TestEvents.Count, Is.EqualTo(1));

            GroupedFieldChangeEvent evt = TestBudget.TestEvents[0] as GroupedFieldChangeEvent;

            Assert.NotNull(evt);

            EntityCreatedEvent subTransactionCreatedEvent = evt.GroupedEvents[1] as EntityCreatedEvent;

            Assert.NotNull(subTransactionCreatedEvent);

            Assert.That(subTransactionCreatedEvent.EntityType, Is.EqualTo(nameof(SubTransaction)));
            Assert.That(subTransactionCreatedEvent.Changes[nameof(SubTransaction.Amount)].NewValue, Is.EqualTo(CurrencyConverter.ToLongValue(100M, subTransaction.GetCurrencyDenominator())));
            Assert.That(subTransactionCreatedEvent.Changes[nameof(SubTransactionSnapshot.Amount_Denominator)].NewValue, Is.EqualTo(subTransaction.GetCurrencyDenominator()));
            Assert.That(transaction.SubTransactions[0], Is.EqualTo(subTransaction));
        }
Пример #8
0
        public async Task HandleAsync(EntityCreatedEvent <FileEntry> domainEvent)
        {
            using (var scope = _serviceProvider.CreateScope())
            {
                var serviceProvider = scope.ServiceProvider;
                var currentUser     = serviceProvider.GetService <ICurrentUser>();
                var dispatcher      = serviceProvider.GetService <Dispatcher>();

                await dispatcher.DispatchAsync(new AddAuditLogEntryCommand
                {
                    AuditLogEntry = new AuditLogEntryDTO
                    {
                        UserId          = currentUser.IsAuthenticated ? currentUser.UserId : Guid.Empty,
                        CreatedDateTime = domainEvent.EventDateTime,
                        Action          = "CREATED_FILEENTRY",
                        ObjectId        = domainEvent.Entity.Id.ToString(),
                        Log             = domainEvent.Entity.AsJsonString(),
                    },
                });

                var fileUploadedEventSender = serviceProvider.GetService <IMessageSender <FileUploadedEvent> >();

                // Forward to external systems
                await fileUploadedEventSender.SendAsync(new FileUploadedEvent
                {
                    FileEntry = domainEvent.Entity,
                });
            }
        }
        public void Handle(EntityCreatedEvent <DataProcessingRegistration> domainEvent)
        {
            var model = new DataProcessingRegistrationReadModel();

            BuildFromSource(model, domainEvent.Entity);

            _readModelRepository.Add(model);
        }
Пример #10
0
 public void Handle(EntityCreatedEvent <FileEntry> domainEvent)
 {
     // Handle the event here and we can also forward to external systems
     _fileUploadedEventSender.Send(new FileUploadedEvent
     {
         FileEntry = domainEvent.Entity,
     });
 }
 public void Handle(EntityCreatedEvent message)
 {
     if (!_budgetModel.IsSavingLocally)
     {
         var snapshot = _createEntityFromEvent(message).GetSnapshot();
         _snapshotStore.StoreSnapshot(snapshot);
     }
 }
Пример #12
0
        internal Budget(EntityCreatedEvent evt)
            : base(evt)
        {
            MasterCategories = RegisterChildEntityCollection(new EntityCollection <MasterCategory>(this));
            IncomeCategories = new IncomeCategoryFinder();
            Payees           = RegisterChildEntityCollection(new EntityCollection <Payee>(this));
            Accounts         = RegisterChildEntityCollection(new EntityCollection <Account>(this));

            ValidationEnabled = true;
        }
Пример #13
0
        public override void OnNext(EntityCreatedEvent <Forum> value)
        {
            //if successful
            _publisher.Publish(new LoggingEvent(value.Data.Name));

            var newTask = new Tasks {
                Name = "New Task", Forum = value.Data
            };

            _tasksRepo.Add(newTask);
        }
Пример #14
0
        public void Handle(EntityCreatedEvent <ItSystemUsage> domainEvent)
        {
            var model = new ItSystemUsageOverviewReadModel();

            BuildFromSource(model, domainEvent.Entity);

            _readModelRepository.Add(model); //Add one immediately

            //Schedule additional update to refresh once deferred updates are applied
            _pendingReadModelUpdateRepository.Add(PendingReadModelUpdate.Create(domainEvent.Entity, PendingReadModelUpdateSourceCategory.ItSystemUsage));
        }
Пример #15
0
        public Task HandleAsync(EntityCreatedEvent <Order> domainEvent)
        {
            var userName        = domainEvent.CreatedByUser;
            var order           = domainEvent.Sender;
            var orderDto        = BuildOrderDto(userName, order);
            var mongoCollection = _mongoDatabase.GetCollection <OrderDto>("LastOrders");

            mongoCollection.Insert(orderDto);
            UpdateCache(mongoCollection, userName);

            return(Task.FromResult(0));
        }
Пример #16
0
        public Task HandleAsync(EntityCreatedEvent <Order> domainEvent)
        {
            try
            {
                var context = GlobalHost.ConnectionManager.GetHubContext <OrderHub>();
                context.Clients.User(domainEvent.CreatedByUser).newOrder(domainEvent.Sender);
            }
            catch (Exception exception)
            {
            }

            return(Task.FromResult(0));
        }
 public void Handle(EntityCreatedEvent message)
 {
     if (message.Changes.ContainsKey(nameof(Transaction.Amount)) &&
         message.Changes.ContainsKey(nameof(Transaction.Parent)))
     {
         if (message.Changes.TryGetValue(nameof(Transaction.Parent), out FieldChange parentFieldChange) &&
             parentFieldChange is TypedFieldChange <EntityReference> typedParentFieldChange)
         {
             EntityReference parentReference = typedParentFieldChange.TypedNewValue;
             if (parentReference.EntityType == nameof(Account))
             {
                 UpdateAccountBalance(parentReference.EntityID);
             }
         }
     }
 }
        public void Handle(EntityCreatedEvent <Entities.Product> domainEvent)
        {
            using (var scope = _serviceProvider.CreateScope())
            {
                var auditSerivce = scope.ServiceProvider.GetService <IAuditLogService>();
                var currentUser  = scope.ServiceProvider.GetService <ICurrentUser>();

                auditSerivce.AddOrUpdate(new AuditLogEntryDTO
                {
                    UserId          = currentUser.IsAuthenticated ? currentUser.UserId: Guid.Empty,
                    CreatedDateTime = domainEvent.EventDateTime,
                    Action          = "CREATED_PRODUCT",
                    ObjectId        = domainEvent.Entity.Id.ToString(),
                    Log             = domainEvent.Entity.AsJsonString(),
                });
            }
        }
Пример #19
0
        public Task HandleAsync(EntityCreatedEvent <Order> domainEvent)
        {
            var transport =
                SMTP.GetInstance(
                    new NetworkCredential("*****@*****.**", "sq2zl2op"));

            var mailMessage = Mail.GetInstance();

            mailMessage.From = new MailAddress("*****@*****.**");
            mailMessage.AddTo(domainEvent.CreatedByUser);
            mailMessage.Subject = "Your mamazon order";
            mailMessage.Text    = "Ola k ase";

            transport.Deliver(mailMessage);

            return(Task.FromResult(0));
        }
        public async Task HandleAsync(EntityCreatedEvent <Product> domainEvent, CancellationToken cancellationToken = default)
        {
            using (var scope = _serviceProvider.CreateScope())
            {
                var auditSerivce = scope.ServiceProvider.GetService <ICrudService <AuditLogEntry> >();
                var currentUser  = scope.ServiceProvider.GetService <ICurrentUser>();

                await auditSerivce.AddOrUpdateAsync(new AuditLogEntry
                {
                    UserId          = currentUser.IsAuthenticated ? currentUser.UserId : Guid.Empty,
                    CreatedDateTime = domainEvent.EventDateTime,
                    Action          = "CREATED_PRODUCT",
                    ObjectId        = domainEvent.Entity.Id.ToString(),
                    Log             = domainEvent.Entity.AsJsonString(),
                });
            }
        }
Пример #21
0
        public void PreviousValueIsDefaultAfterRoundTrip()
        {
            /*
             * We don't want to serialize the Previous Value to the event store/stream, but we also
             * want to handle accessing the property gracefully
             */
            EntityCreatedEvent evt = new EntityCreatedEvent(nameof(Account), Guid.NewGuid().ToString());

            evt.AddChange("Decimal", FieldChange.Create <decimal>(500M, 100000M));
            evt.AddChange("Enum", FieldChange.Create <BudgetingTypes>(BudgetingTypes.OffBudget, BudgetingTypes.OnBudget));
            evt.AddChange("String", FieldChange.Create <string>(default(string), "Test"));
            evt.AddChange("Date", FieldChange.Create <DateTime>(default(DateTime), DateTime.Now));


            EntityCreatedEvent roundTripEvent = EventStreamRoundTripEvent(evt);

            Assert.That(roundTripEvent.Changes["Decimal"].PreviousValue, Is.EqualTo(default(decimal)));
            Assert.That(roundTripEvent.Changes["Enum"].PreviousValue, Is.EqualTo(default(BudgetingTypes)));
            Assert.That(roundTripEvent.Changes["String"].PreviousValue, Is.EqualTo(default(string)));
            Assert.That(roundTripEvent.Changes["Date"].PreviousValue, Is.EqualTo(default(DateTime)));
        }
        public override async Task <ActionResult <CreateDoctorResponse> > HandleAsync(CreateDoctorRequest request, CancellationToken cancellationToken)
        {
            var response = new CreateDoctorResponse(request.CorrelationId());

            var toAdd = _mapper.Map <Doctor>(request);

            toAdd = await _repository.AddAsync(toAdd);

            var dto = _mapper.Map <DoctorDto>(toAdd);

            response.Doctor = dto;

            // Note: These messages could be triggered from the Repository or DbContext events
            // In the DbContext you could look for entities marked with an interface saying they needed
            // to be synchronized via cross-domain events and publish the appropriate message.
            var appEvent = new EntityCreatedEvent(_mapper.Map <NamedEntity>(toAdd));

            _messagePublisher.Publish(appEvent);

            return(Ok(response));
        }
Пример #23
0
        public async Task HandleAsync(EntityCreatedEvent <Entities.Product> domainEvent)
        {
            using (var scope = _serviceProvider.CreateScope())
            {
                var serviceProvider = scope.ServiceProvider;
                var currentUser     = serviceProvider.GetService <ICurrentUser>();
                var dispatcher      = serviceProvider.GetService <Dispatcher>();

                await dispatcher.DispatchAsync(new AddAuditLogEntryCommand
                {
                    AuditLogEntry = new AuditLogEntryDTO
                    {
                        UserId          = currentUser.IsAuthenticated ? currentUser.UserId : Guid.Empty,
                        CreatedDateTime = domainEvent.EventDateTime,
                        Action          = "CREATED_PRODUCT",
                        ObjectId        = domainEvent.Entity.Id.ToString(),
                        Log             = domainEvent.Entity.AsJsonString(),
                    },
                });
            }
        }
        public async Task HandleAsync(EntityCreatedEvent <FileEntry> domainEvent, CancellationToken cancellationToken = default)
        {
            using (var scope = _serviceProvider.CreateScope())
            {
                var auditSerivce = scope.ServiceProvider.GetService <ICrudService <AuditLogEntry> >();
                var currentUser  = scope.ServiceProvider.GetService <ICurrentUser>();

                await auditSerivce.AddOrUpdateAsync(new AuditLogEntry
                {
                    UserId          = currentUser.IsAuthenticated ? currentUser.UserId : Guid.Empty,
                    CreatedDateTime = domainEvent.EventDateTime,
                    Action          = "CREATED_FILEENTRY",
                    ObjectId        = domainEvent.Entity.Id.ToString(),
                    Log             = domainEvent.Entity.AsJsonString(),
                });
            }

            // Forward to external systems
            await _fileUploadedEventSender.SendAsync(new FileUploadedEvent
            {
                FileEntry = domainEvent.Entity,
            });
        }
Пример #25
0
        public void EventStreamCanRoundTripFields()
        {
            EntityCreatedEvent evt = new EntityCreatedEvent(nameof(Account), Guid.NewGuid().ToString());

            evt.AddChange("Decimal", FieldChange.Create <decimal>(default(decimal), 100000M));
            evt.AddChange("Enum", FieldChange.Create <BudgetingTypes>(default(BudgetingTypes), BudgetingTypes.OnBudget));
            evt.AddChange("String", FieldChange.Create <string>(default(string), "Test"));
            evt.AddChange("Date", FieldChange.Create <DateTime>(default(DateTime), DateTime.Now));

            EntityCreatedEvent roundTripEvent = EventStreamRoundTripEvent(evt);

            Assert.That(roundTripEvent.Changes["Decimal"].NewValue.GetType(), Is.EqualTo(evt.Changes["Decimal"].NewValue.GetType()));
            Assert.That(roundTripEvent.Changes["Decimal"].NewValue, Is.EqualTo(evt.Changes["Decimal"].NewValue));

            Assert.That(roundTripEvent.Changes["Enum"].NewValue.GetType(), Is.EqualTo(evt.Changes["Enum"].NewValue.GetType()));
            Assert.That(roundTripEvent.Changes["Enum"].NewValue, Is.EqualTo(evt.Changes["Enum"].NewValue));

            Assert.That(roundTripEvent.Changes["String"].NewValue.GetType(), Is.EqualTo(evt.Changes["String"].NewValue.GetType()));
            Assert.That(roundTripEvent.Changes["String"].NewValue, Is.EqualTo(evt.Changes["String"].NewValue));

            Assert.That(roundTripEvent.Changes["Date"].NewValue.GetType(), Is.EqualTo(evt.Changes["Date"].NewValue.GetType()));
            Assert.That(roundTripEvent.Changes["Date"].NewValue, Is.EqualTo(evt.Changes["Date"].NewValue));
        }
Пример #26
0
        public async Task HandleAsync(EntityCreatedEvent <FileEntry> domainEvent, CancellationToken cancellationToken = default)
        {
            await _auditSerivce.AddOrUpdateAsync(new AuditLogEntry
            {
                UserId          = _currentUser.IsAuthenticated ? _currentUser.UserId : Guid.Empty,
                CreatedDateTime = domainEvent.EventDateTime,
                Action          = "CREATED_FILEENTRY",
                ObjectId        = domainEvent.Entity.Id.ToString(),
                Log             = domainEvent.Entity.AsJsonString(),
            });

            await _eventLogRepository.AddOrUpdateAsync(new EventLog
            {
                EventType       = "FILEENTRY_CREATED",
                TriggeredById   = _currentUser.UserId,
                CreatedDateTime = domainEvent.EventDateTime,
                ObjectId        = domainEvent.Entity.Id.ToString(),
                Message         = domainEvent.Entity.AsJsonString(),
                Published       = false,
            }, cancellationToken);

            await _eventLogRepository.UnitOfWork.SaveChangesAsync(cancellationToken);
        }
Пример #27
0
 internal MasterCategory(EntityCreatedEvent evt)
     : base(evt)
 {
     Categories = RegisterChildEntityCollection(new EntityCollection <Category>(this));
 }
Пример #28
0
 protected EntityBase(EntityCreatedEvent evt) : base(evt)
 {
 }
Пример #29
0
 public void Handle(EntityCreatedEvent <ExternalReference> domainEvent) => HandleExternalReference(domainEvent);
Пример #30
0
 public void Handle(EntityCreatedEvent <LocalBusinessType> domainEvent)
 {
     //Point to parent id since that's what the readmodel knows about
     _pendingReadModelUpdateRepository.Add(PendingReadModelUpdate.Create(domainEvent.Entity.OptionId, PendingReadModelUpdateSourceCategory.ItSystemUsage_BusinessType));
 }