public void Send(ICommand command) { var commandType = command.GetType(); var validator = _validatorsFactory(commandType); if (validator != null) { var validatorType = validator.GetType(); var actionPossible = (ActionPossible)validatorType.InvokeMember("Execute", BindingFlags.InvokeMethod, null, validator, new object[] { command }); if (actionPossible.IsImpossible) { _eventsBus.Publish(new ActionImposibleEvent(actionPossible.Errors)); return; } } var handler = _handlersFactory(commandType); var handlerType = handler.GetType(); handlerType.InvokeMember("Handle", BindingFlags.InvokeMethod, null, handler, new object[] { command }); _eventsBus.Publish(new CommandCompletedEvent(commandType.Name)); }
public TResult Send <TResult>(IQuery <TResult> query) { var queryType = query.GetType(); var validator = _validatorsFactory(queryType); if (validator != null) { var validatorType = validator.GetType(); var actionPossible = (ActionPossible)validatorType.InvokeMember("Execute", BindingFlags.InvokeMethod, null, validator, new object[] { query }); if (actionPossible.IsImpossible) { _eventsBus.Publish(new ActionImposibleEvent(actionPossible.Errors)); return(default(TResult)); } } var handler = _handlersFactory(queryType, typeof(TResult)); var handlerType = handler.GetType(); return((TResult)handlerType.InvokeMember("Handle", BindingFlags.InvokeMethod, null, handler, new object[] { query })); }
public async Task Handle(ImportCommand command) { logger.LogInformation("Importing transactions from file"); var lastOrder = await bankTransactionAccess.GetLastTransactionOrder(command.UserId); var transactions = importers.SelectMany(i => i.ImportTransactions(command.TransactionsFile, lastOrder).ToList()).ToList(); foreach (var transaction in transactions) { transaction.Order = ++lastOrder; var databaseTransaction = await bankTransactionAccess.AddToDatabase(transaction, command.UserId); if (databaseTransaction != null) { await eventsBus.Publish(new TransactionSavedEvent(command.UserId, transaction, databaseTransaction)); } else { --lastOrder; } } await eventsBus.Publish(new CommandCompletedEvent(command.UserId, command.Id)); logger.LogInformation("Transactions from file imported"); }
public async Task SendAsync <TCommand>(TCommand command) where TCommand : ICommand { try { await commandsBus.SendAsync(command); } catch (NonGenericException e) when(command is Command) { await eventsBus.Publish(CommandExceptionEvent.FromCommand(command as Command, e)); } catch when(command is Command) { await eventsBus.Publish(CommandExceptionEvent.FromCommand(command as Command, "Unknown error")); } }
public async Task Handle(AddGroupCommand command) { var bankTransaction = await groupAccess.GetBankTransactionById(command.BankTransactionId); if (bankTransaction == null) { throw new BankAnalizerException($"Bank transaction id {command.BankTransactionId} doesn't exist"); } var group = command.RuleId == default ? await groupAccess.GetGroupByName(command.GroupName, command.UserId) : await groupAccess.GetGroupByNameAndRuleId(command.GroupName, command.RuleId, command.UserId); if (group == null) { group = new Group { Name = command.GroupName }; group.User = await groupAccess.GetUser(command.UserId); if (command.RuleId != default) { group.Rule = new Rule { Id = command.RuleId } } ; } await groupAccess.AddBankTransactionToGroup(bankTransaction, group); _ = eventsBus.Publish(new GroupToTransactionAddedEvent(bankTransaction, group, command.UserId)); } }
public async Task Handle(SaveRuleCommand command) { using var context = contextFactory.GetContext(); Rule rule; if (command.Id != default) { rule = await context.Rules.SingleOrDefaultAsync(r => r.Id == command.Id) ?? new Rule(); } else { rule = new Rule(); } var isNewRule = rule.Id == default; mapper.Map(command, rule); if (isNewRule) { rule.Id = Guid.NewGuid(); await context.AddAsync(rule); } if (command.BankTransactionTypeId != null) { rule.BankTransactionType = await context.BankTransactionTypes.SingleAsync(b => b.Id == command.BankTransactionTypeId); } else { rule.BankTransactionType = null; } rule.User = await context.Users.FindAsync(command.UserId); using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { await context.SaveChangesAsync(); await eventsBus.Publish(new RuleSavedEvent(rule, command.UserId)); scope.Complete(); } await eventsBus.Publish(new CommandCompletedEvent(command)); }
public Task Handle(MeetingGroupProposalAcceptedNotification notification, CancellationToken cancellationToken) { _eventsBus.Publish(new MeetingGroupProposalAcceptedIntegrationEvent( notification.Id, notification.DomainEvent.OccurredOn, notification.DomainEvent.MeetingGroupProposalId.Value)); return(Task.CompletedTask); }
public void Handle(MoneyTransferCommand command) { var bankAccountFrom = _bankAccountRepository.GetById(command.SenderAccountId); BusinessRuleChecker.Handle(new IsTransferedAmountOfMoneyAvailableBusinessRule(bankAccountFrom, command)); bankAccountFrom.Balance -= command.Amount; _bankAccountRepository.Update(bankAccountFrom); _eventBus.Publish(new MoneyTransferedEvent(command.SenderAccountId, command.Amount, TransferMoneyStatus.SEND)); var bankAccountTo = _bankAccountRepository.GetById(command.ReceiverAccountId); bankAccountTo.Balance += command.Amount; _bankAccountRepository.Update(bankAccountTo); _eventBus.Publish(new MoneyTransferedEvent(command.ReceiverAccountId, command.Amount, TransferMoneyStatus.RECEIVE)); }
public Task Handle(SubscriptionCreatedNotification notification, CancellationToken cancellationToken) { _eventsBus.Publish(new SubscriptionExpirationDateChangedIntegrationEvent(notification.Id, notification.DomainEvent.OccurredOn, notification.DomainEvent.PayerId, notification.DomainEvent.ExpirationDate)); return(Task.CompletedTask); }
public Task Handle(PaymentRegisteredNotification notification, CancellationToken cancellationToken) { _eventsBus.Publish(new PaymentRegisteredIntegrationEvent( notification.Id, notification.DomainEvent.OccurredOn, notification.MeetingGroupPaymentRegisterId.Value, notification.DateTo)); return(Task.CompletedTask); }
public void Handle(RegisterUserCommand command) { _usersRepo.AddUser(command.Username); _events.Publish(new UserRegistered { Username = command.Username, RegistrationTime = DateTime.UtcNow }); }
public Task Handle(MeetingAttendeeAddedNotification notification, CancellationToken cancellationToken) { _eventsBus.Publish(new MeetingAttendeeAddedIntegrationEvent(Guid.NewGuid(), notification.DomainEvent.OccurredOn, notification.DomainEvent.MeetingId.Value, notification.DomainEvent.AttendeeId.Value, notification.DomainEvent.FeeValue, notification.DomainEvent.FeeCurrency)); return(Task.CompletedTask); }
public Task Handle(MemberGeneralAttributesEditedNotification notification, CancellationToken cancellationToken) { _eventsBus.Publish(new MemberGeneralAttributesEditedIntegrationEvent(notification.Id, notification.DomainEvent.OccurredOn, notification.DomainEvent.MemberId, notification.DomainEvent.FirstName, notification.DomainEvent.LastName, notification.DomainEvent.Picture)); return(Task.CompletedTask); }
public async Task Handle(MeetingFeePaidNotification notification, CancellationToken cancellationToken) { var meetingFee = await _aggregateStore.Load(new MeetingFeeId(notification.DomainEvent.MeetingFeeId)); var meetingFeeSnapshot = meetingFee.GetSnapshot(); _eventsBus.Publish(new MeetingFeePaidIntegrationEvent(notification.Id, notification.DomainEvent.OccurredOn, meetingFeeSnapshot.PayerId, meetingFeeSnapshot.MeetingId)); }
public async Task Handle(NewUserRegisteredNotification notification, CancellationToken cancellationToken) { await _eventsBus.Publish(new NewUserRegisteredIntegrationEvent( notification.Id, notification.DomainEvent.OccurredOn, notification.DomainEvent.UserRegistrationId.Value, notification.DomainEvent.Login, notification.DomainEvent.Email, notification.DomainEvent.FirstName, notification.DomainEvent.LastName, notification.DomainEvent.Name)); }
public Task Handle(PhraseCreatedNotification notification, CancellationToken cancellationToken) { _eventsBus.Publish(new PhraseCreatedIntegrationEvent(notification.Id, notification.DomainEvent.OccurredOn, notification.DomainEvent.PhraseId.Value, notification.DomainEvent.MatchId.Value, notification.DomainEvent.TeamId.Value, notification.DomainEvent.CreatedByUserId.Value, notification.DomainEvent.Description, notification.DomainEvent.Positive, notification.DomainEvent.UtcDateCreated)); return(Task.CompletedTask); }
private void PublishProductCreatedEvent(Product product) { _eventsBus.Publish(new ProductCreatedEvent { ProductId = product.Id, Code = product.Code, Barcode = product.Barcode, Description = product.Description, Price = product.Price, Manufacturer = product.Manufacturer.Name, ProductType = product.ProductType.Name }); }
public Task Handle(MeetingGroupProposedNotification notification, CancellationToken cancellationToken) { _eventsBus.Publish(new MeetingGroupProposedIntegrationEvent( notification.Id, notification.DomainEvent.OccurredOn, notification.DomainEvent.Id.Value, notification.DomainEvent.Name, notification.DomainEvent.Description, notification.DomainEvent.LocationCity, notification.DomainEvent.LocationCountryCode, notification.DomainEvent.ProposalUserId.Value, notification.DomainEvent.ProposalDate)); return(Task.CompletedTask); }
public void Handle(UserLogoutCommand command) { var invalidKey = new TblInvalidKeys { Key = command.Key, UserId = command.UserId }; _invalidKeysRepository.Create(invalidKey); _eventBus.Publish(new UserLogoutEvent { UserId = command.UserId }); }
public async Task Handle(SavePerson savePerson) { var record = new PersonRecord { FirstName = savePerson.FirstName, LastName = savePerson.LastName }; using (var context = new MySqlDbContext()) { await context.People.AddAsync(record); await context.SaveChangesAsync(); } await _eventsBus.Publish(new PersonSaved(record.Id)); }
public async Task <Unit> Handle(SavePerson savePerson, CancellationToken cancellationToken = default) { var record = new PersonRecord { FirstName = savePerson.FirstName, LastName = savePerson.LastName }; await using var context = new MySqlDbContext(); await context.People.AddAsync(record, cancellationToken); await context.SaveChangesAsync(cancellationToken); await _eventsBus.Publish(new PersonSaved(record.Id), cancellationToken); return(Unit.Value); }
public async Task <Unit> Handle(SaveAddress saveAddress, CancellationToken cancellationToken = default) { await using var context = new MySqlDbContext(); var record = new AddressRecord { City = saveAddress.City, PostalCode = saveAddress.PostalCode, Street = saveAddress.Street, Number = saveAddress.Number, AddressType = saveAddress.AddressType, PersonId = saveAddress.PersonId }; await context.Addresses.AddAsync(record, cancellationToken); await context.SaveChangesAsync(cancellationToken); await _eventsBus.Publish(new AddressSaved(record.Id, saveAddress.PersonId), cancellationToken); return(Unit.Value); }
public async Task Handle(SaveAddress saveAddress) { using (var context = new MySqlDbContext()) { var record = new AddressRecord { City = saveAddress.City, PostalCode = saveAddress.PostalCode, Street = saveAddress.Street, Number = saveAddress.Number, AddressType = saveAddress.AddressType, PersonId = saveAddress.PersonId }; await context.Addresses.AddAsync(record); await context.SaveChangesAsync(); await _eventsBus.Publish(new AddressSaved(record.Id, saveAddress.PersonId)); } }
public void Handle(CreateUserCommand command) { System.Console.WriteLine($"Create user {command.Name} {command.Surname} - handler"); _eventPublisher.Publish(new UserWasCreatedEvent(command.Name)); }
public void Publish <TEvent>(TEvent @event) where TEvent : IEvent { _eventsBus.Publish(@event); }