27 lines
1.0 KiB
C#
27 lines
1.0 KiB
C#
using DbusSmsForward.Notifications;
|
|
using DbusSmsForward.SMSModel;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace DbusSmsForward.Services;
|
|
|
|
public sealed class NotificationDispatcher(IEnumerable<INotificationSender> senders, ILogger<NotificationDispatcher> logger)
|
|
{
|
|
private readonly IReadOnlyList<INotificationSender> _senders = senders.Where(static s => s.IsEnabled).ToList();
|
|
|
|
public async Task DispatchAsync(SmsContentModel sms, string body, string deviceName, CancellationToken cancellationToken)
|
|
{
|
|
foreach (INotificationSender sender in _senders)
|
|
{
|
|
try
|
|
{
|
|
await sender.SendAsync(sms, body, deviceName, cancellationToken);
|
|
logger.LogInformation("Notification sender {Sender} completed for {PhoneNumber}", sender.Name, sms.TelNumber);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.LogError(ex, "Notification sender {Sender} failed for {PhoneNumber}", sender.Name, sms.TelNumber);
|
|
}
|
|
}
|
|
}
|
|
}
|