Exemplo n.º 1
0
        public async Task RunNotCompletedEdcEventsHandlerAsync([TimerTrigger("%Jobs:HandleNotCompletedEdcEvents:Schedule%")] TimerInfo timer)
        {
            await FunctionTemplate("HandleNotCompletedEdcEvents", async() =>
            {
                var tillDate = DateTime.UtcNow.AddMinutes(-_edcConfiguration.MessageTimeToLiveInMinutes);

                var notCompletedEventLogs = await _eventLogService.GetAsync(log =>
                                                                            log.StateId != (int)EventStateEnum.Completed &&
                                                                            log.CreationTime < tillDate);

                foreach (var eventLog in notCompletedEventLogs)
                {
                    _logger.Event($"{_jobsConfiguration.LogEventId}.HandleNotCompletedEdcEvents").With
                    .Message($"Event Failed: EventId:{eventLog.EventId}, EventName: {eventLog.EventTypeName}, EventContent: { JsonConvert.SerializeObject(eventLog.Content)}")
                    .AsError();

                    if (eventLog.TimesSent >= _jobsConfiguration.HandleNotCompletedEdcEvents.MaxAttemptsCountBeforeEmailSending)
                    {
                        var baseEmailTemplate = _emailTemplateProvider.GetBaseTemplateHtml();

                        var serviceBusErrorEmailTemplate = _emailTemplateProvider.GetTemplateHtml(
                            _jobsConfiguration.HandleNotCompletedEdcEvents.ServiceBusErrorEmailTemplateName);

                        await _emailService.SendNotificationAsync(new ServiceBusErrorEmailNotification(
                                                                      new ServiceBusErrorEmailNotificationTemplateModel(eventLog.EventId),
                                                                      baseEmailTemplate, serviceBusErrorEmailTemplate,
                                                                      new RecipientDto(_jobsConfiguration.HandleNotCompletedEdcEvents.ServiceBusErrorEmailRecipients, null)));
                    }

                    eventLog.StateId = (int)EventStateEnum.PublishedFailed;
                    await _eventLogService.UpdateAsync(eventLog);
                    await _edcPublishService.RepublishAsync(eventLog.EventId);
                }
            });
        }
Exemplo n.º 2
0
        public async Task SendEmailConfirmationEmailAsync(User user)
        {
            var token = await _tokenProviderService.GenerateEmailConfirmationTokenAsync(user);

            var callbackLink = UrlHelperExtensions.ApiCallbackLink(_authApiUrlConfiguration.ConfirmEmailUrl, token);

            var baseEmailTemplate = _emailTemplateProvider.GetBaseTemplateHtml();

            var emailConfirmationEmailTemplate = _emailTemplateProvider.GetTemplateHtml(
                _emailTemplatesConfiguration.EmailConfirmationEmailTemplateName);

            await _emailService.SendNotificationAsync(new UserConfirmationEmailNotification(
                                                          new UserConfirmationEmailModel(callbackLink, user.Email),
                                                          emailConfirmationEmailTemplate,
                                                          baseEmailTemplate,
                                                          new RecipientDto(user.Email, user.UserName)));
        }