1 using Microsoft.Extensions.Logging;
3 using System.Collections.Generic;
6 using System.Threading.Tasks;
20 logger.LogTrace(value ?
"Activated" :
"Deactivated");
26 public IReadOnlyCollection<ChannelRepresentation> Channels {
get;
private set; }
29 public IEnumerable<CustomCommand> CustomCommands
31 get => customCommands;
34 customCommands = (value ??
throw new InvalidOperationException(
"value cannot be null!"))
35 .Select(customCommand =>
37 customCommand.SetHandler(customCommandHandler);
41 logger.LogTrace(
"Custom commands set.");
53 readonly ILogger<ChatTrackingContext>
logger;
89 IEnumerable<ChannelRepresentation> initialChannels,
90 ILogger<ChatTrackingContext> logger,
93 this.customCommandHandler = customCommandHandler ??
throw new ArgumentNullException(nameof(customCommandHandler));
94 Channels = initialChannels?.ToList() ??
throw new ArgumentNullException(nameof(initialChannels));
95 this.logger = logger ??
throw new ArgumentNullException(nameof(logger));
96 this.onDispose = onDispose ??
throw new ArgumentNullException(nameof(onDispose));
98 synchronizationLock =
new object();
106 lock (synchronizationLock)
116 if (channelSink == null)
117 throw new ArgumentNullException(nameof(channelSink));
119 lock (synchronizationLock)
121 if (this.channelSink != null)
122 throw new InvalidOperationException(
"channelSink already set!");
124 this.channelSink = channelSink;
129 public Task
UpdateChannels(IEnumerable<ChannelRepresentation> newChannels, CancellationToken cancellationToken)
131 var completed = newChannels.ToList();
133 lock (synchronizationLock)
135 Channels = completed;
136 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.