Table of Contents

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

windowSystem ConsoleWindowSystem

The console window system to display notifications in.

logService ILogService

Optional log service for diagnostic logging.

Exceptions

ArgumentNullException

Thrown when windowSystem is null.

Properties

ActiveCount

Gets the number of active notifications.

public int ActiveCount { get; }

Property Value

int

ActiveNotifications

Gets all active notifications.

public IReadOnlyList<NotificationInfo> ActiveNotifications { get; }

Property Value

IReadOnlyList<NotificationInfo>

CurrentState

Gets the current notification state.

public NotificationState CurrentState { get; }

Property Value

NotificationState

HasNotifications

Gets a value indicating whether any notifications are currently displayed.

public bool HasNotifications { get; }

Property Value

bool

Methods

DismissAll()

Dismisses all active notifications.

public void DismissAll()

DismissNotification(Window)

Dismisses a notification by its window.

public bool DismissNotification(Window window)

Parameters

window Window

The 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

notificationId string

The 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

notificationId string

The 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

notificationId string

The 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

title string

The notification title.

message string

The notification message.

severity NotificationSeverity

The severity level.

blockUi bool

Whether to block UI (modal).

timeout int?

Auto-dismiss timeout in milliseconds (0 or null = no timeout).

parentWindow Window

Optional 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

EventHandler

NotificationDismissed

Occurs when a notification is dismissed.

public event EventHandler<NotificationEventArgs>? NotificationDismissed

Event Type

EventHandler<NotificationEventArgs>

NotificationShown

Occurs when a notification is shown.

public event EventHandler<NotificationEventArgs>? NotificationShown

Event Type

EventHandler<NotificationEventArgs>

StateChanged

Occurs when notification state changes.

public event EventHandler<NotificationState>? StateChanged

Event Type

EventHandler<NotificationState>