Правка по результатам ревью

This commit is contained in:
Olga Nemt 2023-12-21 14:48:08 +05:00
parent 17629b54c4
commit 85d0aca9a8
2 changed files with 14 additions and 12 deletions

View File

@ -22,7 +22,7 @@ namespace AsbCloudInfrastructure.Background
private string smtpServer; private string smtpServer;
private bool IsConfigured; 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; 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}"); 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");
}
} }
} }

View File

@ -12,8 +12,8 @@ namespace AsbCloudInfrastructure.Services.Email
public class EmailNotificationTransportService : INotificationTransportService public class EmailNotificationTransportService : INotificationTransportService
{ {
private readonly IConfiguration configuration;
private readonly BackgroundWorker backgroundWorker; private readonly BackgroundWorker backgroundWorker;
private IConfiguration configuration;
public EmailNotificationTransportService(BackgroundWorker backgroundWorker, public EmailNotificationTransportService(BackgroundWorker backgroundWorker,
IConfiguration configuration) IConfiguration configuration)
@ -26,10 +26,9 @@ namespace AsbCloudInfrastructure.Services.Email
public Task SendAsync(NotificationDto notification, CancellationToken cancellationToken) public Task SendAsync(NotificationDto notification, CancellationToken cancellationToken)
{ {
var workId = MakeWorkId(notification.IdUser, notification.Title, notification.Message); var work = new WorkToSendEmail(notification, configuration);
if (!backgroundWorker.Works.Any(w => w.Id == workId)) if (!backgroundWorker.Works.Any(w => w.Id == work.Id))
{ {
var work = new WorkToSendEmail(workId, notification, configuration);
backgroundWorker.Enqueue(work); backgroundWorker.Enqueue(work);
} }
@ -44,12 +43,6 @@ namespace AsbCloudInfrastructure.Services.Email
return Task.WhenAll(tasks); 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");
}
} }
} }