2using System.Collections.Generic;
5using System.Threading.Tasks;
7using Microsoft.Extensions.Logging;
25 logger.LogTrace(
"Activated");
27 logger.LogTrace(
"Deactivated");
34 public IReadOnlyCollection<ChannelRepresentation>
Channels {
get;
private set; }
42 customCommands = (value ??
throw new InvalidOperationException(
"value cannot be null!"))
43 .Select(customCommand =>
49 logger.LogTrace(
"Custom commands set.");
61 readonly ILogger<ChatTrackingContext>
logger;
97 IEnumerable<ChannelRepresentation> initialChannels,
98 ILogger<ChatTrackingContext>
logger,
102 Channels = initialChannels?.ToList() ??
throw new ArgumentNullException(nameof(initialChannels));
103 this.logger =
logger ??
throw new ArgumentNullException(nameof(
logger));
128 if (this.channelSink !=
null)
129 throw new InvalidOperationException(
"channelSink already set!");
136 public Task
UpdateChannels(IEnumerable<ChannelRepresentation> newChannels, CancellationToken cancellationToken)
138 logger.LogTrace(
"UpdateChannels...");
139 var completed = newChannels.ToList();
IReadOnlyCollection< CustomCommand > customCommands
Backing field for CustomCommands.
readonly ICustomCommandHandler customCommandHandler
The ICustomCommandHandler for the ChatTrackingContext.
void SetChannelSink(IChannelSink channelSink)
Sets the channelSink for the IChatTrackingContext.
IEnumerable< CustomCommand > CustomCommands
IReadOnlyCollection<T> of CustomCommands in the IChatTrackingContext.
bool active
Backing field for Active.
IChannelSink channelSink
The IChannelSink if any.
readonly ILogger< ChatTrackingContext > logger
The ILogger for the ChatTrackingContext.
Task UpdateChannels(IEnumerable< ChannelRepresentation > newChannels, CancellationToken cancellationToken)
Called when newChannels are set. A Task representing the running operation.
ChatTrackingContext(ICustomCommandHandler customCommandHandler, IEnumerable< ChannelRepresentation > initialChannels, ILogger< ChatTrackingContext > logger, Action onDispose)
Initializes a new instance of the ChatTrackingContext class.
Action onDispose
The Action to run when Disposed.
readonly object synchronizationLock
lock object for modifying onDispose, channelSink, and Channels.
bool Active
If the CustomCommands should be used.
IReadOnlyCollection< ChannelRepresentation > Channels
IReadOnlyCollection<T> of ChannelRepresentations in the IChatTrackingContext.
Represents a command made from DM code.
Notifyee of when ChannelRepresentations in a IChatTrackingContext are updated.
Task UpdateChannels(IEnumerable< ChannelRepresentation > newChannels, CancellationToken cancellationToken)
Called when newChannels are set.
Represents a tracking of dynamic chat json files.
Handles Commands.ICommands that map to those defined in a IChatTrackingContext.