RazorDocs Search

Services

Type

InMemoryMessageStore

Stores reactivity messages in memory for the lifetime of the application process.

Type

IMessageStore

Defines storage operations for chat messages displayed in the reactivity feed.

Method

Add

void Add(MessageItemModel message)

Adds a message to the store.

Parameters

  • messageThe message item to persist.
Method

GetAll

IReadOnlyList<MessageItemModel> GetAll()

Returns the current messages ordered from newest to oldest.

Returns

A read-only snapshot of stored messages.

Type

InMemoryUserPresenceService

An in-memory implementation of IUserPresenceService using a thread-safe dictionary to track user activity.

Method

RecordActivity

int RecordActivity(string username)

Records the current UTC time as the specified user's last activity in the in-memory store.

Parameters

  • usernameThe username to record; cannot be null, empty, or whitespace.

Returns

The number of users whose last activity is within the current ActiveWindow.

Exceptions

  • System.ArgumentExceptionThrown when username is null, empty, or consists only of whitespace.
Method

GetActiveUsers

IEnumerable<UserPresenceInfo> GetActiveUsers()

Lists users whose last recorded activity falls within the current ActiveWindow.

Returns

A collection of UserPresenceInfo for users with last activity at or after (now - ActiveWindow), ordered by Username.

Method

Pulse

(IReadOnlyList<UserPresenceInfo> Removed, int ActiveCount) Pulse()

Removes users whose last activity is older than the sliding ActiveWindow and returns the removed entries along with the current count of active users.

Returns

`Removed`: a read-only list of user presence entries that were removed because their last activity preceded the ActiveWindow; `ActiveCount`: the number of users whose last activity is within the ActiveWindow.

Property

ActiveWindow

TimeSpan ActiveWindow { get; set; }

Gets or sets the time window within which a user is considered active since their last recorded activity. Must be a positive duration.

Exceptions

  • ArgumentOutOfRangeExceptionThrown when the value is less than or equal to TimeSpan.Zero.
Type

UserPresenceInfo

Represents current presence information for a user.

Parameters

  • UsernameThe unique username.
  • SafeUsernameA simplified version of the username safe for use in UI identifiers.
  • LastSeenThe timestamp of the user's last recorded activity.
Type

IUserPresenceService

Defines a service for tracking and managing user presence.

Method

RecordActivity

int RecordActivity(string username)

Record activity for the specified user and update their presence tracking.

Parameters

  • usernameThe username whose activity should be recorded.

Returns

The current number of active users after recording the activity.

Method

GetActiveUsers

IEnumerable<UserPresenceInfo> GetActiveUsers()

Retrieve presence information for users currently considered active.

Returns

A collection of UserPresenceInfo objects for users considered active at the time of the call.

Method

Pulse

(IReadOnlyList<UserPresenceInfo> Removed, int ActiveCount) Pulse()

Advance presence tracking and expire users considered inactive during this pulse.

Returns

A tuple where Removed is a read-only list of users removed during this pulse, and ActiveCount is the current number of active users after the pulse.

Type

UserPresenceBackgroundService

A background service that periodically pulses the user presence service and publishes updates to connected clients.

Method

RunAsync

Task RunAsync(CancellationToken stoppingToken)

Periodically pulses user presence, removes departed users from the reactive stream, and publishes updates to connected clients.

Parameters

  • stoppingTokenCancellation token used to stop the background loop.

Returns

A task that completes when the background loop stops.