1 using Microsoft.Extensions.Logging;
3 using System.Collections.Generic;
6 using System.Threading.Tasks;
22 logger.LogTrace(value ?
"Activated" :
"Deactivated");
28 public IReadOnlyCollection<ChannelRepresentation> Channels {
get;
private set; }
31 public IEnumerable<CustomCommand> CustomCommands
33 get => customCommands;
36 customCommands = (value ??
throw new InvalidOperationException(
"value cannot be null!"))
37 .Select(customCommand =>
39 customCommand.SetHandler(customCommandHandler);
43 logger.LogTrace(
"Custom commands set.");
55 readonly ILogger<ChatTrackingContext>
logger;
91 IEnumerable<ChannelRepresentation> initialChannels,
92 ILogger<ChatTrackingContext> logger,
95 this.customCommandHandler = customCommandHandler ??
throw new ArgumentNullException(nameof(customCommandHandler));
96 Channels = initialChannels?.ToList() ??
throw new ArgumentNullException(nameof(initialChannels));
97 this.logger = logger ??
throw new ArgumentNullException(nameof(logger));
98 this.onDispose = onDispose ??
throw new ArgumentNullException(nameof(onDispose));
100 synchronizationLock =
new object();
108 lock (synchronizationLock)
118 if (channelSink == null)
119 throw new ArgumentNullException(nameof(channelSink));
121 lock (synchronizationLock)
123 if (this.channelSink != null)
124 throw new InvalidOperationException(
"channelSink already set!");
126 this.channelSink = channelSink;
131 public Task
UpdateChannels(IEnumerable<ChannelRepresentation> newChannels, CancellationToken cancellationToken)
133 logger.LogTrace(
"UpdateChannels...");
134 var completed = newChannels.ToList();
136 lock (synchronizationLock)
138 Channels = completed;
139 updateTask = channelSink?.
UpdateChannels(newChannels, cancellationToken) ?? Task.CompletedTask;
bool active
Backing field for Active.
Use server authentication
readonly object synchronizationLock
object for modifying onDispose, channelSink, and Channels.
Action onDispose
The Action to run when Disposed.
Notifyee of when ChannelRepresentations in a IChatTrackingContext are updated.
readonly ILogger< ChatTrackingContext > logger
The ILogger for the ChatTrackingContext.
Task UpdateChannels(IEnumerable< ChannelRepresentation > newChannels, CancellationToken cancellationToken)
Called when newChannels are set.
void SetChannelSink(IChannelSink channelSink)
Sets the channelSink for the IChatTrackingContext.
IChannelSink channelSink
The IChannelSink if any.
Represents a command made from DM code
Handles Commands.ICommands that map to those defined in a IChatTrackingContext
Represents a tracking of dynamic chat json files
Task UpdateChannels(IEnumerable< ChannelRepresentation > newChannels, CancellationToken cancellationToken)
Called when newChannels are set.
ChatTrackingContext(ICustomCommandHandler customCommandHandler, IEnumerable< ChannelRepresentation > initialChannels, ILogger< ChatTrackingContext > logger, Action onDispose)
Initializes a new instance of the ChatTrackingContext .
readonly ICustomCommandHandler customCommandHandler
The ICustomCommandHandler for the ChatTrackingContext.
IReadOnlyCollection< CustomCommand > customCommands
Backing field for CustomCommands.