Files
ScadaBridge/src/ZB.MOM.WW.ScadaBridge.CentralUI/Services/NotificationChannelCatalog.cs
T

37 lines
1.6 KiB
C#

using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
using ZB.MOM.WW.ScadaBridge.NotificationOutbox.Delivery;
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Services;
/// <summary>
/// Default <see cref="INotificationChannelCatalog"/> that derives the supported channels
/// from the registered <see cref="INotificationDeliveryAdapter"/> set. The central Host
/// registers the Email + SMS adapters (see <c>AddNotificationOutbox</c>) into the same DI
/// container that hosts the Central UI, so projecting each adapter's
/// <see cref="INotificationDeliveryAdapter.Type"/> yields exactly the channels the central
/// node can actually deliver — no hardcoded <c>{Email, Sms}</c> list to drift.
/// </summary>
public sealed class NotificationChannelCatalog : INotificationChannelCatalog
{
/// <summary>
/// Initializes the catalog from the registered delivery adapters, snapshotting the
/// distinct channel set once (the adapter registrations are fixed for the process
/// lifetime). Ordering follows the <see cref="NotificationType"/> enum so the UI Type
/// selector renders in a stable order regardless of adapter registration order.
/// </summary>
/// <param name="adapters">The registered delivery adapters (one per channel).</param>
public NotificationChannelCatalog(IEnumerable<INotificationDeliveryAdapter> adapters)
{
ArgumentNullException.ThrowIfNull(adapters);
SupportedChannels = adapters
.Select(a => a.Type)
.Distinct()
.OrderBy(t => (int)t)
.ToArray();
}
/// <inheritdoc />
public IReadOnlyList<NotificationType> SupportedChannels { get; }
}