Exemplo n.º 1
0
        /// <summary>
        ///     Notify a single user.
        /// </summary>
        /// <param name="context">The background context.</param>
        public override async Task ExecuteAsync(BackgroundTaskContext context)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var notificationContext = (NotificationContext)context.Value;

            // Check if we can reach the user that should be notified.
            if (!await _notificationRegistrationRepository.ExistsAsync(notificationContext.NotifiedUserId))
            {
                _logger.LogTrace($"Couldn't get notification registration for user {notificationContext.NotifiedUserId}");
                return;
            }

            var pushDetails = await _userRepository.GetPushDetailsAsync(notificationContext.NotifiedUserId);

            await _notificationClient.SendNotificationAsync(pushDetails, notificationContext.Notification);

            _logger.LogTrace($"Sent notification to user {notificationContext.NotifiedUserId}");
        }