Class NotificationStateService
- Namespace
- SharpConsoleUI.Core
- Assembly
- SharpConsoleUI.dll
Centralized service for managing notification state. Tracks active notifications, provides dismissal methods, and fires events.
public class NotificationStateService : IDisposable
- Inheritance
-
NotificationStateService
- Implements
- Inherited Members
Constructors
NotificationStateService(ConsoleWindowSystem, ILogService?)
Initializes a new instance of the NotificationStateService class.
public NotificationStateService(ConsoleWindowSystem windowSystem, ILogService? logService = null)
Parameters
windowSystemConsoleWindowSystemThe console window system to display notifications in.
logServiceILogServiceOptional log service for diagnostic logging.
Exceptions
- ArgumentNullException
Thrown when
windowSystemis null.
Properties
ActiveCount
Gets the number of active notifications.
public int ActiveCount { get; }
Property Value
ActiveNotifications
Gets all active notifications.
public IReadOnlyList<NotificationInfo> ActiveNotifications { get; }
Property Value
CurrentState
Gets the current notification state.
public NotificationState CurrentState { get; }
Property Value
HasNotifications
Gets a value indicating whether any notifications are currently displayed.
public bool HasNotifications { get; }
Property Value
Methods
DismissAll()
Dismisses all active notifications.
public void DismissAll()
DismissNotification(Window)
Dismisses a notification by its window.
public bool DismissNotification(Window window)
Parameters
windowWindowThe notification window to dismiss.
Returns
- bool
True if the notification was found and dismissed; otherwise, false.
DismissNotification(string)
Dismisses a notification by ID.
public bool DismissNotification(string notificationId)
Parameters
notificationIdstringThe notification ID to dismiss.
Returns
- bool
True if the notification was found and dismissed; otherwise, false.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
GetNotification(string)
Gets a notification by ID.
public NotificationInfo? GetNotification(string notificationId)
Parameters
notificationIdstringThe notification ID to find.
Returns
- NotificationInfo
The notification info if found; otherwise, null.
NotificationExists(string)
Checks if a notification with the given ID exists.
public bool NotificationExists(string notificationId)
Parameters
notificationIdstringThe notification ID to check.
Returns
- bool
True if the notification exists; otherwise, false.
ShowNotification(string, string, NotificationSeverity, bool, int?, Window?)
Shows a notification with the specified parameters.
public string ShowNotification(string title, string message, NotificationSeverity severity, bool blockUi = false, int? timeout = 5000, Window? parentWindow = null)
Parameters
titlestringThe notification title.
messagestringThe notification message.
severityNotificationSeverityThe severity level.
blockUiboolWhether to block UI (modal).
timeoutint?Auto-dismiss timeout in milliseconds (0 or null = no timeout).
parentWindowWindowOptional parent window for modal notifications.
Returns
- string
The notification ID for later reference.
Events
AllNotificationsDismissed
Occurs when all notifications are dismissed.
public event EventHandler? AllNotificationsDismissed
Event Type
NotificationDismissed
Occurs when a notification is dismissed.
public event EventHandler<NotificationEventArgs>? NotificationDismissed
Event Type
NotificationShown
Occurs when a notification is shown.
public event EventHandler<NotificationEventArgs>? NotificationShown
Event Type
StateChanged
Occurs when notification state changes.
public event EventHandler<NotificationState>? StateChanged