Ejemplo n.º 1
0
        /// <summary>
        /// Construct a <see cref="ChatManager"/>
        /// </summary>
        /// <param name="providerFactory">The value of <see cref="providerFactory"/></param>
        /// <param name="ioManager">The value of <see cref="ioManager"/></param>
        /// <param name="commandFactory">The value of <see cref="commandFactory"/></param>
        /// <param name="serverControl">The <see cref="IServerControl"/> to populate <see cref="restartRegistration"/> with</param>
        /// <param name="asyncDelayer">The value of <see cref="asyncDelayer"/></param>
        /// <param name="loggerFactory">The value of <see cref="loggerFactory"/></param>
        /// <param name="logger">The value of <see cref="logger"/></param>
        /// <param name="initialChatBots">The <see cref="IEnumerable{T}"/> used to populate <see cref="activeChatBots"/></param>
        public ChatManager(IProviderFactory providerFactory, IIOManager ioManager, ICommandFactory commandFactory, IServerControl serverControl, IAsyncDelayer asyncDelayer, ILoggerFactory loggerFactory, ILogger <ChatManager> logger, IEnumerable <Models.ChatBot> initialChatBots)
        {
            this.providerFactory = providerFactory ?? throw new ArgumentNullException(nameof(providerFactory));
            this.ioManager       = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
            this.commandFactory  = commandFactory ?? throw new ArgumentNullException(nameof(commandFactory));
            if (serverControl == null)
            {
                throw new ArgumentNullException(nameof(serverControl));
            }
            this.asyncDelayer  = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer));
            this.loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
            this.logger        = logger ?? throw new ArgumentNullException(nameof(logger));
            activeChatBots     = initialChatBots?.ToList() ?? throw new ArgumentNullException(nameof(initialChatBots));

            restartRegistration = serverControl.RegisterForRestart(this);

            synchronizationLock = new object();

            builtinCommands    = new Dictionary <string, ICommand>();
            providers          = new Dictionary <long, IProvider>();
            mappedChannels     = new Dictionary <ulong, ChannelMapping>();
            trackingContexts   = new List <IChatTrackingContext>();
            handlerCts         = new CancellationTokenSource();
            connectionsUpdated = new TaskCompletionSource <object>();
            channelIdCounter   = 1;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WatchdogBase"/> <see langword="class"/>.
        /// </summary>
        /// <param name="chat">The value of <see cref="Chat"/></param>
        /// <param name="sessionControllerFactory">The value of <see cref="SessionControllerFactory"/></param>
        /// <param name="dmbFactory">The value of <see cref="DmbFactory"/></param>
        /// <param name="reattachInfoHandler">The value of <see cref="reattachInfoHandler"/></param>
        /// <param name="databaseContextFactory">The value of <see cref="databaseContextFactory"/></param>
        /// <param name="byondTopicSender">The value of <see cref="byondTopicSender"/></param>
        /// <param name="eventConsumer">The value of <see cref="eventConsumer"/></param>
        /// <param name="jobManager">The value of <see cref="jobManager"/></param>
        /// <param name="serverControl">The <see cref="IServerControl"/> to populate <see cref="restartRegistration"/> with</param>
        /// <param name="asyncDelayer">The value of <see cref="AsyncDelayer"/>.</param>
        /// <param name="logger">The value of <see cref="Logger"/></param>
        /// <param name="initialLaunchParameters">The initial value of <see cref="ActiveLaunchParameters"/>. May be modified</param>
        /// <param name="instance">The value of <see cref="instance"/></param>
        /// <param name="autoStart">The value of <see cref="autoStart"/></param>
        protected WatchdogBase(
            IChat chat,
            ISessionControllerFactory sessionControllerFactory,
            IDmbFactory dmbFactory,
            IReattachInfoHandler reattachInfoHandler,
            IDatabaseContextFactory databaseContextFactory,
            IByondTopicSender byondTopicSender,
            IEventConsumer eventConsumer,
            IJobManager jobManager,
            IServerControl serverControl,
            IAsyncDelayer asyncDelayer,
            ILogger logger,
            DreamDaemonLaunchParameters initialLaunchParameters,
            Api.Models.Instance instance,
            bool autoStart)
        {
            Chat = chat ?? throw new ArgumentNullException(nameof(chat));
            SessionControllerFactory = sessionControllerFactory ?? throw new ArgumentNullException(nameof(sessionControllerFactory));
            DmbFactory                  = dmbFactory ?? throw new ArgumentNullException(nameof(dmbFactory));
            AsyncDelayer                = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer));
            this.reattachInfoHandler    = reattachInfoHandler ?? throw new ArgumentNullException(nameof(reattachInfoHandler));
            this.databaseContextFactory = databaseContextFactory ?? throw new ArgumentNullException(nameof(databaseContextFactory));
            this.byondTopicSender       = byondTopicSender ?? throw new ArgumentNullException(nameof(byondTopicSender));
            this.eventConsumer          = eventConsumer ?? throw new ArgumentNullException(nameof(eventConsumer));
            this.jobManager             = jobManager ?? throw new ArgumentNullException(nameof(jobManager));
            Logger = logger ?? throw new ArgumentNullException(nameof(logger));
            ActiveLaunchParameters = initialLaunchParameters ?? throw new ArgumentNullException(nameof(initialLaunchParameters));
            this.instance          = instance ?? throw new ArgumentNullException(nameof(instance));
            this.autoStart         = autoStart;

            if (serverControl == null)
            {
                throw new ArgumentNullException(nameof(serverControl));
            }

            chat.RegisterCommandHandler(this);

            ActiveLaunchParameters  = initialLaunchParameters;
            releaseServers          = false;
            ActiveParametersUpdated = new TaskCompletionSource <object>();

            restartRegistration = serverControl.RegisterForRestart(this);
            try
            {
                Semaphore = new SemaphoreSlim(1);
            }
            catch
            {
                restartRegistration.Dispose();
                throw;
            }
        }