Exemplo n.º 1
0
 public async Task PublishAsync(string month)
 {
     await _commandPublisher.PublishAsync(_queueNames.Trigger, new TriggerMessage()
     {
         Month = month
     });
 }
        public async Task ProcessMessageAsync(ICommand command)
        {
            var qMessage = (TriggerMessage)command;

            if (qMessage.AccountNumbers == null)
            {
                // get the list of user accounts
                var userAccounts = await _identityClient.GetUserAccounts();

                // publish the message in to the queue for each user
                foreach (var userAccount in userAccounts)
                {
                    var statementMessage = new StatementMessage()
                    {
                        Name = userAccount.Name, AccountNumber = userAccount.AccountNumber, Month = qMessage.Month, Currency = userAccount.Currency
                    };
                    await _commandPublisher.PublishAsync(_queueNames.Statement, statementMessage);
                }
            }
            else
            {
                foreach (var accountNumber in qMessage.AccountNumbers)
                {
                    var userAccount = await _identityClient.GetUserAccount(accountNumber);

                    var statementMessage = new StatementMessage()
                    {
                        Name = userAccount.Name, AccountNumber = userAccount.AccountNumber, Month = qMessage.Month, Currency = userAccount.Currency
                    };
                    await _commandPublisher.PublishAsync(_queueNames.Statement, statementMessage);
                }
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Add(Oefening oefening)
        {
            var command = new MaakOefeningAanCommand
            {
                Oefening = oefening
            };
            var result = await _commandPublisher.PublishAsync <MaakOefeningAanCommand>(command);

            return(Ok(result.Oefening.Id));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Register(RegisterViewModel viewModel, string button)
        {
            if (!Startup.RegisterEnabled || _signInManager.IsSignedIn(User))
            {
                return(Forbid());
            }

            if (button != "register")
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName = viewModel.Username
                };
                var result = await _userManager.CreateAsync(user, viewModel.Password);

                if (result.Succeeded)
                {
                    var commandResult = await _commandPublisher.PublishAsync(
                        new MaakKlantAanCommand
                    {
                        Klant = new Klant
                        {
                            Voornaam   = viewModel.FirstName,
                            Achternaam = viewModel.LastName
                        }
                    });

                    result = await _userManager.AddClaimsAsync(user, new[]
                    {
                        new Claim(JwtClaimTypes.Name, $"{viewModel.FirstName} {viewModel.LastName}"),
                        new Claim(FitAuthClaims.FitOefeningRead, FitAuthClaims.True),
                        new Claim(FitAuthClaims.FitOefeningPrestatieRead, FitAuthClaims.True),
                        new Claim(FitAuthClaims.FitOefeningPrestatieAdd, FitAuthClaims.True),
                        new Claim(Claims.KlantId, commandResult.Klant.Id.ToString()),
                    });



                    if (result.Succeeded)
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(Redirect(Environment.GetEnvironmentVariable(EnvNames.RegisterRedirectUrl)));
                    }
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }
            return(View("Register", viewModel));
        }
Exemplo n.º 5
0
 public async Task DispatchIntegrationEventAsync(IEvent @event)
 {
     if (_integrationEventHandlers.TryGetValue(@event.GetType(), out IReadOnlyCollection <object> handlers))
     {
         foreach (object handler in handlers)
         {
             IEnumerable <ICommand> commands = ((dynamic)handler).DetermineCommandsToExecute((dynamic)@event);
             await _commandPublisher.PublishAsync(commands);
         }
     }
 }
Exemplo n.º 6
0
        public async Task <IActionResult> Add(Prestatie prestatie)
        {
            prestatie.Datum   = DateTime.Now;
            prestatie.KlantId = GetKlantIdFromToken();

            var command = new RegistreerPrestatieCommand
            {
                Prestatie = prestatie
            };
            var result = await _commandPublisher.PublishAsync <RegistreerPrestatieCommand>(command);

            return(Ok(result.Prestatie));
        }
Exemplo n.º 7
0
        public async Task ImportOefeningenIntoSystem(IList <Oefening> oefeningen, Guid klantId)
        {
            foreach (var oefening in oefeningen)
            {
                var returnCommand = await _commandPublisher.PublishAsync <MaakOefeningAanCommand>(
                    new MaakOefeningAanCommand
                {
                    Oefening = oefening
                });

                foreach (var prestatie in oefening.Prestaties)
                {
                    prestatie.OefeningId = returnCommand.Oefening.Id;
                    prestatie.KlantId    = klantId;
                    await _commandPublisher.PublishAsync <RegistreerPrestatieCommand>(
                        new RegistreerPrestatieCommand
                    {
                        Prestatie = prestatie
                    });
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        ///   Schedules a command for retry, if it is eligible for doing so.
        /// </summary>
        ///
        /// <typeparam name="TCommand">The type of the command to be scheduled.</typeparam>
        ///
        /// <param name="command">The command to be .</param>
        /// <param name="retryThresholds">The retry thresholds to apply when assigning the retry backoff.</param>
        /// <param name="rng">The random number generator to use for computing retry jitter.</param>
        /// <param name="clock">The clock to use for calculating the retry delay.</param>
        /// <param name="commandPublisher">The publisher to use for scheduling the command to be retried.</param>
        ///
        /// <returns><c>true</c> if the command was scheduled for retry; <c>false</c> if it was not eligible for retry.</returns>
        ///
        /// <remarks>
        ///     If scheduled to be retried, the incoming <paramref name="command"/> will have it's <see cref="CommandBase.PreviousAttemptsToHandleCount" />
        ///     incremented by this method.  Otherwise, it will be unaltered.
        /// </remarks>
        ///
        protected virtual async Task <bool> ScheduleCommandForRetryIfEligibleAsync <TCommand>(TCommand command,
                                                                                              CommandRetryThresholds retryThresholds,
                                                                                              Random rng,
                                                                                              IClock clock,
                                                                                              ICommandPublisher <TCommand> commandPublisher) where TCommand : CommandBase
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            if (retryThresholds == null)
            {
                throw new ArgumentNullException(nameof(retryThresholds));
            }

            if (rng == null)
            {
                throw new ArgumentNullException(nameof(rng));
            }

            if (clock == null)
            {
                throw new ArgumentNullException(nameof(clock));
            }

            if (commandPublisher == null)
            {
                throw new ArgumentNullException(nameof(commandPublisher));
            }

            // If the command is out of retries, then take no further action.

            var attempts = command.PreviousAttemptsToHandleCount;

            if (attempts >= retryThresholds.CommandRetryMaxCount)
            {
                return(false);
            }

            ++attempts;
            command.PreviousAttemptsToHandleCount = attempts;

            // Publish the retry using an exponential backoff with random jitter.

            var retryInstant = clock.GetCurrentInstant().Plus(Duration.FromSeconds((Math.Pow(2, attempts) * retryThresholds.CommandRetryExponentialSeconds) + (rng.NextDouble() * retryThresholds.CommandRetryJitterSeconds)));
            await commandPublisher.PublishAsync(command, retryInstant);

            return(true);
        }
Exemplo n.º 9
0
        public CreeerModuleCommandResponse SendCreeerModuleCommand(Module module)
        {
            CreeerModuleCommand command = new CreeerModuleCommand()
            {
                Cohort         = module.Cohort,
                Competenties   = module.Competenties,
                ModuleCode     = module.ModuleCode,
                ModuleNaam     = module.ModuleNaam,
                Eindeisen      = module.Eindeisen,
                Studiefase     = module.Studiefase,
                VerplichtVoor  = module.VerplichtVoor,
                AanbevolenVoor = module.AanbevolenVoor
            };

            CreeerModuleCommandResponse result = _publisher.PublishAsync <CreeerModuleCommandResponse>(command).Result;

            return(result);
        }