feat: publish dbussmsforward refactor
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user