2using System.Collections.Generic;
5using System.Threading.Tasks;
7using Microsoft.Extensions.Logging;
26 logger.LogTrace(
"Activated");
28 logger.LogTrace(
"Deactivated");
35 public IReadOnlyCollection<ChannelRepresentation>
Channels {
get;
private set; }
43 customCommands = (value ??
throw new InvalidOperationException(
"value cannot be null!"))
44 .Select(customCommand =>
50 logger.LogTrace(
"Custom commands set.");
62 readonly ILogger<ChatTrackingContext>
logger;
93 IEnumerable<ChannelRepresentation> initialChannels,
94 ILogger<ChatTrackingContext>
logger,
99 Channels = initialChannels?.ToList() ??
throw new ArgumentNullException(nameof(initialChannels));
100 this.logger =
logger ??
throw new ArgumentNullException(nameof(
logger));
112 var originalValue = Interlocked.CompareExchange(ref this.channelSink,
channelSink,
null);
113 if (originalValue !=
null)
114 throw new InvalidOperationException(
"channelSink already set!");
118 public ValueTask
UpdateChannels(IEnumerable<ChannelRepresentation> newChannels, CancellationToken cancellationToken)
120 logger.LogTrace(
"UpdateChannels...");
121 var completed = newChannels.ToList();
122 ValueTask updateTask;
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.
readonly ILogger< ChatTrackingContext > logger
The ILogger for the ChatTrackingContext.
ChatTrackingContext(ICustomCommandHandler customCommandHandler, IEnumerable< ChannelRepresentation > initialChannels, ILogger< ChatTrackingContext > logger, Action disposeAction)
Initializes a new instance of the ChatTrackingContext class.
volatile? IChannelSink channelSink
The IChannelSink if any.
readonly object synchronizationLock
lock object for modifying Channels and calling IChannelSink.UpdateChannels(IEnumerable<ChannelReprese...
ValueTask UpdateChannels(IEnumerable< ChannelRepresentation > newChannels, CancellationToken cancellationToken)
Called when newChannels are set. A ValueTask representing the running operation.
bool Active
If the CustomCommands should be used. This should only be set by the object that sets the CustomComma...
IReadOnlyCollection< ChannelRepresentation > Channels
IReadOnlyCollection<T> of ChannelRepresentations in the IChatTrackingContext.
Represents a command made from DM code.
Runs a given disposeAction on Dispose.
readonly Action disposeAction
The Action to run on Dispose.
bool IsDisposed
If Dispose was called.
Notifyee of when ChannelRepresentations in a IChatTrackingContext are updated.
ValueTask 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.