DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/Email/EmailNotificationTransportService.cs

49 lines
1.5 KiB
C#
Raw Normal View History

2023-12-21 12:31:25 +05:00
using AsbCloudApp.Data;
using AsbCloudApp.Services.Notifications;
using AsbCloudInfrastructure.Background;
using Microsoft.Extensions.Configuration;
2022-02-28 14:44:26 +05:00
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services.Email
2022-02-28 14:44:26 +05:00
{
public class EmailNotificationTransportService : INotificationTransportService
2022-02-28 14:44:26 +05:00
{
private readonly IConfiguration configuration;
private readonly BackgroundWorker backgroundWorker;
2022-02-28 14:44:26 +05:00
2023-12-21 12:31:25 +05:00
public EmailNotificationTransportService(BackgroundWorker backgroundWorker,
IConfiguration configuration)
2022-02-28 14:44:26 +05:00
{
2023-12-21 12:31:25 +05:00
this.configuration = configuration;
2022-02-28 14:44:26 +05:00
this.backgroundWorker = backgroundWorker;
}
public int IdTransportType => 1;
2023-12-21 12:31:25 +05:00
public Task SendAsync(NotificationDto notification, CancellationToken cancellationToken)
2022-02-28 14:44:26 +05:00
{
var work = new WorkToSendEmail(notification, configuration);
if (!backgroundWorker.Works.Any(w => w.Id == work.Id))
2022-02-28 14:44:26 +05:00
{
2023-11-03 17:02:44 +05:00
backgroundWorker.Enqueue(work);
2022-04-11 18:00:34 +05:00
}
return Task.CompletedTask;
}
public Task SendRangeAsync(IEnumerable<NotificationDto> notifications, CancellationToken cancellationToken)
{
var tasks = notifications
.Select(notification => SendAsync(notification, cancellationToken));
return Task.WhenAll(tasks);
2022-02-28 14:44:26 +05:00
}
2023-12-21 12:31:25 +05:00
2022-02-28 14:44:26 +05:00
}
}