From 85d0aca9a8756d37d6389066f7d842dacccd9bff Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Thu, 21 Dec 2023 14:48:08 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D1=80=D0=B5=D0=B7=D1=83=D0=BB=D1=8C=D1=82=D0=B0=D1=82?= =?UTF-8?q?=D0=B0=D0=BC=20=D1=80=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Background/WorkToSendEmail.cs | 11 ++++++++++- .../Email/EmailNotificationTransportService.cs | 15 ++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/AsbCloudInfrastructure/Background/WorkToSendEmail.cs b/AsbCloudInfrastructure/Background/WorkToSendEmail.cs index 06e88342..96136cde 100644 --- a/AsbCloudInfrastructure/Background/WorkToSendEmail.cs +++ b/AsbCloudInfrastructure/Background/WorkToSendEmail.cs @@ -22,7 +22,7 @@ namespace AsbCloudInfrastructure.Background private string smtpServer; private bool IsConfigured; - public WorkToSendEmail(string workId, NotificationDto notification, IConfiguration configuration) : base(workId) + public WorkToSendEmail(NotificationDto notification, IConfiguration configuration) : base(MakeWorkId(notification)) { this.notification = notification; @@ -81,5 +81,14 @@ namespace AsbCloudInfrastructure.Background Trace.TraceInformation($"Send email to {user.Email} subj:{notification.Title} html body count {notification.Message.Length}"); } + + + private static string MakeWorkId(NotificationDto notification) + { + var hash = notification.IdUser.GetHashCode(); + hash ^= notification.Title.GetHashCode(); + hash ^= notification.Message.GetHashCode(); + return hash.ToString("x"); + } } } diff --git a/AsbCloudInfrastructure/Services/Email/EmailNotificationTransportService.cs b/AsbCloudInfrastructure/Services/Email/EmailNotificationTransportService.cs index d24d150f..f41bd7ad 100644 --- a/AsbCloudInfrastructure/Services/Email/EmailNotificationTransportService.cs +++ b/AsbCloudInfrastructure/Services/Email/EmailNotificationTransportService.cs @@ -12,8 +12,8 @@ namespace AsbCloudInfrastructure.Services.Email public class EmailNotificationTransportService : INotificationTransportService { + private readonly IConfiguration configuration; private readonly BackgroundWorker backgroundWorker; - private IConfiguration configuration; public EmailNotificationTransportService(BackgroundWorker backgroundWorker, IConfiguration configuration) @@ -26,10 +26,9 @@ namespace AsbCloudInfrastructure.Services.Email public Task SendAsync(NotificationDto notification, CancellationToken cancellationToken) { - var workId = MakeWorkId(notification.IdUser, notification.Title, notification.Message); - if (!backgroundWorker.Works.Any(w => w.Id == workId)) + var work = new WorkToSendEmail(notification, configuration); + if (!backgroundWorker.Works.Any(w => w.Id == work.Id)) { - var work = new WorkToSendEmail(workId, notification, configuration); backgroundWorker.Enqueue(work); } @@ -44,12 +43,6 @@ namespace AsbCloudInfrastructure.Services.Email return Task.WhenAll(tasks); } - private static string MakeWorkId(int idUser, string subject, string content) - { - var hash = idUser.GetHashCode(); - hash ^= subject.GetHashCode(); - hash ^= content.GetHashCode(); - return hash.ToString("x"); - } + } }