예제 #1
0
        /// <summary>
        /// Construct a <see cref="IWatchdog"/>
        /// </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="serverUpdater">The <see cref="IServerControl"/> for the <see cref="Watchdog"/></param>
        /// <param name="logger">The value of <see cref="logger"/></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="initialLaunchParameters">The initial value of <see cref="ActiveLaunchParameters"/></param>
        /// <param name="instance">The value of <see cref="instance"/></param>
        /// <param name="autoStart">The value of <see cref="autoStart"/></param>
        /// <param name="eventConsumer">The value of <see cref="eventConsumer"/></param>
        public Watchdog(IChat chat, ISessionControllerFactory sessionControllerFactory, IDmbFactory dmbFactory, IServerControl serverUpdater, ILogger <Watchdog> logger, IReattachInfoHandler reattachInfoHandler, IDatabaseContextFactory databaseContextFactory, IByondTopicSender byondTopicSender, IEventConsumer eventConsumer, DreamDaemonLaunchParameters initialLaunchParameters, Api.Models.Instance instance, bool autoStart)
        {
            this.chat = chat ?? throw new ArgumentNullException(nameof(chat));
            this.sessionControllerFactory = sessionControllerFactory ?? throw new ArgumentNullException(nameof(sessionControllerFactory));
            this.dmbFactory             = dmbFactory ?? throw new ArgumentNullException(nameof(dmbFactory));
            this.logger                 = logger ?? throw new ArgumentNullException(nameof(logger));
            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.instance               = instance ?? throw new ArgumentNullException(nameof(instance));
            this.autoStart              = autoStart;

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

            serverUpdater.RegisterForRestart(() => releaseServers = true);

            chat.RegisterCommandHandler(this);

            AlphaIsActive          = true;
            ActiveLaunchParameters = initialLaunchParameters;
            releaseServers         = false;
            semaphore = new SemaphoreSlim(1);
            activeParametersUpdated = new TaskCompletionSource <object>();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BasicWatchdog"/> <see langword="class"/>.
 /// </summary>
 /// <param name="chat">The <see cref="IChat"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="sessionControllerFactory">The <see cref="ISessionControllerFactory"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="dmbFactory">The <see cref="IDmbFactory"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="reattachInfoHandler">The <see cref="IReattachInfoHandler"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="databaseContextFactory">The <see cref="IDatabaseContextFactory"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="byondTopicSender">The <see cref="IByondTopicSender"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="eventConsumer">The <see cref="IEventConsumer"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="jobManager">The <see cref="IJobManager"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="serverControl">The <see cref="IServerControl"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="asyncDelayer">The <see cref="IAsyncDelayer"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="logger">The <see cref="ILogger"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="initialLaunchParameters">The <see cref="DreamDaemonLaunchParameters"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="instance">The <see cref="Api.Models.Instance"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="autoStart">The autostart value for the <see cref="WatchdogBase"/>.</param>
 public BasicWatchdog(
     IChat chat,
     ISessionControllerFactory sessionControllerFactory,
     IDmbFactory dmbFactory,
     IReattachInfoHandler reattachInfoHandler,
     IDatabaseContextFactory databaseContextFactory,
     IByondTopicSender byondTopicSender,
     IEventConsumer eventConsumer,
     IJobManager jobManager,
     IServerControl serverControl,
     IAsyncDelayer asyncDelayer,
     ILogger <BasicWatchdog> logger,
     DreamDaemonLaunchParameters initialLaunchParameters,
     Api.Models.Instance instance,
     bool autoStart)
     : base(
         chat,
         sessionControllerFactory,
         dmbFactory,
         reattachInfoHandler,
         databaseContextFactory,
         byondTopicSender,
         eventConsumer,
         jobManager,
         serverControl,
         asyncDelayer,
         logger,
         initialLaunchParameters,
         instance,
         autoStart)
 {
 }
예제 #3
0
 /// <summary>
 /// Construct a <see cref="SessionControllerFactory"/>
 /// </summary>
 /// <param name="processExecutor">The value of <see cref="processExecutor"/></param>
 /// <param name="byond">The value of <see cref="byond"/></param>
 /// <param name="byondTopicSender">The value of <see cref="byondTopicSender"/></param>
 /// <param name="cryptographySuite">The value of <see cref="cryptographySuite"/></param>
 /// <param name="application">The value of <see cref="application"/></param>
 /// <param name="instance">The value of <see cref="instance"/></param>
 /// <param name="ioManager">The value of <see cref="ioManager"/></param>
 /// <param name="chat">The value of <see cref="chat"/></param>
 /// <param name="networkPromptReaper">The value of <see cref="networkPromptReaper"/></param>
 /// <param name="platformIdentifier">The value of <see cref="platformIdentifier"/></param>
 /// <param name="loggerFactory">The value of <see cref="loggerFactory"/></param>
 public SessionControllerFactory(
     IProcessExecutor processExecutor,
     IByondManager byond,
     IByondTopicSender byondTopicSender,
     ICryptographySuite cryptographySuite,
     IApplication application,
     IIOManager ioManager,
     IChat chat,
     INetworkPromptReaper networkPromptReaper,
     IPlatformIdentifier platformIdentifier,
     ILoggerFactory loggerFactory,
     Api.Models.Instance instance)
 {
     this.processExecutor   = processExecutor ?? throw new ArgumentNullException(nameof(processExecutor));
     this.byond             = byond ?? throw new ArgumentNullException(nameof(byond));
     this.byondTopicSender  = byondTopicSender ?? throw new ArgumentNullException(nameof(byondTopicSender));
     this.cryptographySuite = cryptographySuite ?? throw new ArgumentNullException(nameof(cryptographySuite));
     this.application       = application ?? throw new ArgumentNullException(nameof(application));
     this.instance          = instance ?? throw new ArgumentNullException(nameof(instance));
     this.ioManager         = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
     this.chat = chat ?? throw new ArgumentNullException(nameof(chat));
     this.networkPromptReaper = networkPromptReaper ?? throw new ArgumentNullException(nameof(networkPromptReaper));
     this.platformIdentifier  = platformIdentifier ?? throw new ArgumentNullException(nameof(platformIdentifier));
     this.loggerFactory       = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
 }
예제 #4
0
        /// <summary>
        /// Construct a <see cref="SessionController"/>
        /// </summary>
        /// <param name="reattachInformation">The value of <see cref="reattachInformation"/></param>
        /// <param name="process">The value of <see cref="process"/></param>
        /// <param name="byondLock">The value of <see cref="byondLock"/></param>
        /// <param name="byondTopicSender">The value of <see cref="byondTopicSender"/></param>
        /// <param name="interopContext">The value of <see cref="interopContext"/></param>
        /// <param name="chat">The value of <see cref="chat"/></param>
        /// <param name="chatJsonTrackingContext">The value of <see cref="chatJsonTrackingContext"/></param>
        /// <param name="logger">The value of <see cref="logger"/></param>
        /// <param name="launchSecurityLevel">The value of <see cref="launchSecurityLevel"/></param>
        /// <param name="startupTimeout">The optional time to wait before failing the <see cref="LaunchResult"/></param>
        public SessionController(
            ReattachInformation reattachInformation,
            IProcess process,
            IByondExecutableLock byondLock,
            IByondTopicSender byondTopicSender,
            IJsonTrackingContext chatJsonTrackingContext,
            ICommContext interopContext,
            IChat chat,
            ILogger <SessionController> logger,
            DreamDaemonSecurity?launchSecurityLevel,
            uint?startupTimeout)
        {
            this.chatJsonTrackingContext = chatJsonTrackingContext;             // null valid
            this.reattachInformation     = reattachInformation ?? throw new ArgumentNullException(nameof(reattachInformation));
            this.byondTopicSender        = byondTopicSender ?? throw new ArgumentNullException(nameof(byondTopicSender));
            this.process        = process ?? throw new ArgumentNullException(nameof(process));
            this.byondLock      = byondLock ?? throw new ArgumentNullException(nameof(byondLock));
            this.interopContext = interopContext ?? throw new ArgumentNullException(nameof(interopContext));
            this.chat           = chat ?? throw new ArgumentNullException(nameof(chat));
            this.logger         = logger ?? throw new ArgumentNullException(nameof(logger));

            this.launchSecurityLevel = launchSecurityLevel;

            interopContext.RegisterHandler(this);

            portClosedForReboot = false;
            disposed            = false;
            apiValidationStatus = ApiValidationStatus.NeverValidated;
            released            = false;

            rebootTcs = new TaskCompletionSource <object>();

            process.Lifetime.ContinueWith(x => chatJsonTrackingContext.Active = false, TaskScheduler.Current);

            async Task <LaunchResult> GetLaunchResult()
            {
                var  startTime = DateTimeOffset.Now;
                Task toAwait   = process.Startup;

                if (startupTimeout.HasValue)
                {
                    toAwait = Task.WhenAny(process.Startup, Task.Delay(startTime.AddSeconds(startupTimeout.Value) - startTime));
                }

                await toAwait.ConfigureAwait(false);

                var result = new LaunchResult
                {
                    ExitCode    = process.Lifetime.IsCompleted ? (int?)await process.Lifetime.ConfigureAwait(false) : null,
                    StartupTime = process.Startup.IsCompleted ? (TimeSpan?)(DateTimeOffset.Now - startTime) : null
                };

                return(result);
            }

            LaunchResult = GetLaunchResult();

            logger.LogDebug("Created session controller. Primary: {0}, CommsKey: {1}, Port: {2}", IsPrimary, reattachInformation.AccessIdentifier, Port);
        }
 /// <summary>
 /// Construct a <see cref="WatchdogFactory"/>
 /// </summary>
 /// <param name="serverControl">The value of <see cref="serverControl"/></param>
 /// <param name="loggerFactory">The value of <see cref="loggerFactory"/></param>
 /// <param name="databaseContextFactory">The value of <see cref="databaseContextFactory"/></param>
 /// <param name="byondTopicSender">The value of <see cref="byondTopicSender"/></param>
 /// <param name="jobManager">The value of <see cref="jobManager"/></param>
 public WatchdogFactory(IServerControl serverControl, ILoggerFactory loggerFactory, IDatabaseContextFactory databaseContextFactory, IByondTopicSender byondTopicSender, IJobManager jobManager)
 {
     this.serverControl          = serverControl ?? throw new ArgumentNullException(nameof(serverControl));
     this.loggerFactory          = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
     this.databaseContextFactory = databaseContextFactory ?? throw new ArgumentNullException(nameof(databaseContextFactory));
     this.byondTopicSender       = byondTopicSender ?? throw new ArgumentNullException(nameof(byondTopicSender));
     this.jobManager             = jobManager ?? throw new ArgumentNullException(nameof(jobManager));
 }
        public GameAnnouncerModule(IByondTopicSender byondTopicSender, IOptions <ServerConfiguration> serverConfigurationOptions, IStringLocalizer <GameAnnouncerModule> stringLocalizer)
        {
            this.byondTopicSender = byondTopicSender ?? throw new ArgumentNullException(nameof(byondTopicSender));
            this.stringLocalizer  = stringLocalizer ?? throw new ArgumentNullException(nameof(stringLocalizer));
            serverConfiguration   = serverConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(serverConfigurationOptions));

            byondTopicSender.SendTimeout    = serverConfiguration.SendTimeout;
            byondTopicSender.ReceiveTimeout = serverConfiguration.ReceiveTimeout;
        }
예제 #7
0
 /// <summary>
 /// Construct a <see cref="WatchdogFactory"/>
 /// </summary>
 /// <param name="chat">The value of <see cref="chat"/></param>
 /// <param name="sessionControllerFactory">The value of <see cref="sessionControllerFactory"/></param>
 /// <param name="serverUpdater">The value of <see cref="serverUpdater"/></param>
 /// <param name="loggerFactory">The value of <see cref="loggerFactory"/></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="instance">The value of <see cref="instance"/></param>
 public WatchdogFactory(IChat chat, ISessionControllerFactory sessionControllerFactory, IServerControl serverUpdater, ILoggerFactory loggerFactory, IReattachInfoHandler reattachInfoHandler, IDatabaseContextFactory databaseContextFactory, IByondTopicSender byondTopicSender, IEventConsumer eventConsumer, Api.Models.Instance instance)
 {
     this.chat = chat ?? throw new ArgumentNullException(nameof(chat));
     this.sessionControllerFactory = sessionControllerFactory ?? throw new ArgumentNullException(nameof(sessionControllerFactory));
     this.serverUpdater            = serverUpdater ?? throw new ArgumentNullException(nameof(serverUpdater));
     this.loggerFactory            = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
     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.instance = instance ?? throw new ArgumentNullException(nameof(instance));
 }
예제 #8
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;
            }
        }
예제 #9
0
 /// <summary>
 /// Construct an <see cref="InstanceFactory"/>
 /// </summary>
 /// <param name="ioManager">The value of <see cref="ioManager"/></param>
 /// <param name="databaseContextFactory">The value of <see cref="databaseContextFactory"/></param>
 /// <param name="application">The value of <see cref="application"/></param>
 /// <param name="loggerFactory">The value of <see cref="loggerFactory"/></param>
 /// <param name="byondTopicSender">The value of <see cref="byondTopicSender"/></param>
 /// <param name="serverUpdater">The value of <see cref="serverUpdater"/></param>
 /// <param name="cryptographySuite">The value of <see cref="cryptographySuite"/></param>
 /// <param name="synchronousIOManager">The value of <see cref="synchronousIOManager"/></param>
 /// <param name="symlinkFactory">The value of <see cref="symlinkFactory"/></param>
 /// <param name="byondInstaller">The value of <see cref="byondInstaller"/></param>
 /// <param name="providerFactory">The value of <see cref="providerFactory"/></param>
 /// <param name="processExecutor">The value of <see cref="processExecutor"/></param>
 /// <param name="postWriteHandler">The value of <see cref="postWriteHandler"/></param>
 public InstanceFactory(IIOManager ioManager, IDatabaseContextFactory databaseContextFactory, IApplication application, ILoggerFactory loggerFactory, IByondTopicSender byondTopicSender, IServerControl serverUpdater, ICryptographySuite cryptographySuite, ISynchronousIOManager synchronousIOManager, ISymlinkFactory symlinkFactory, IByondInstaller byondInstaller, IProviderFactory providerFactory, IProcessExecutor processExecutor, IPostWriteHandler postWriteHandler)
 {
     this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
     this.databaseContextFactory = databaseContextFactory ?? throw new ArgumentNullException(nameof(databaseContextFactory));
     this.application            = application ?? throw new ArgumentNullException(nameof(application));
     this.loggerFactory          = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
     this.byondTopicSender       = byondTopicSender ?? throw new ArgumentNullException(nameof(byondTopicSender));
     this.serverUpdater          = serverUpdater ?? throw new ArgumentNullException(nameof(serverUpdater));
     this.cryptographySuite      = cryptographySuite ?? throw new ArgumentNullException(nameof(cryptographySuite));
     this.synchronousIOManager   = synchronousIOManager ?? throw new ArgumentNullException(nameof(synchronousIOManager));
     this.symlinkFactory         = symlinkFactory ?? throw new ArgumentNullException(nameof(symlinkFactory));
     this.byondInstaller         = byondInstaller ?? throw new ArgumentNullException(nameof(byondInstaller));
     this.providerFactory        = providerFactory ?? throw new ArgumentNullException(nameof(providerFactory));
     this.processExecutor        = processExecutor ?? throw new ArgumentNullException(nameof(processExecutor));
     this.postWriteHandler       = postWriteHandler ?? throw new ArgumentNullException(nameof(postWriteHandler));
 }
예제 #10
0
 /// <summary>
 /// Construct an <see cref="InstanceFactory"/>
 /// </summary>
 /// <param name="ioManager">The value of <see cref="ioManager"/></param>
 /// <param name="databaseContextFactory">The value of <see cref="databaseContextFactory"/></param>
 /// <param name="application">The value of <see cref="application"/></param>
 /// <param name="loggerFactory">The value of <see cref="loggerFactory"/></param>
 /// <param name="byondTopicSender">The value of <see cref="byondTopicSender"/></param>
 /// <param name="cryptographySuite">The value of <see cref="cryptographySuite"/></param>
 /// <param name="synchronousIOManager">The value of <see cref="synchronousIOManager"/></param>
 /// <param name="symlinkFactory">The value of <see cref="symlinkFactory"/></param>
 /// <param name="byondInstaller">The value of <see cref="byondInstaller"/></param>
 /// <param name="chatFactory">The value of <see cref="chatFactory"/></param>
 /// <param name="processExecutor">The value of <see cref="processExecutor"/></param>
 /// <param name="postWriteHandler">The value of <see cref="postWriteHandler"/></param>
 /// <param name="watchdogFactory">The value of <see cref="watchdogFactory"/></param>
 /// <param name="jobManager">The value of <see cref="jobManager"/></param>
 /// <param name="credentialsProvider">The value of <see cref="credentialsProvider"/></param>
 /// <param name="networkPromptReaper">The value of <see cref="networkPromptReaper"/></param>
 public InstanceFactory(IIOManager ioManager, IDatabaseContextFactory databaseContextFactory, IApplication application, ILoggerFactory loggerFactory, IByondTopicSender byondTopicSender, ICryptographySuite cryptographySuite, ISynchronousIOManager synchronousIOManager, ISymlinkFactory symlinkFactory, IByondInstaller byondInstaller, IChatFactory chatFactory, IProcessExecutor processExecutor, IPostWriteHandler postWriteHandler, IWatchdogFactory watchdogFactory, IJobManager jobManager, ICredentialsProvider credentialsProvider, INetworkPromptReaper networkPromptReaper)
 {
     this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
     this.databaseContextFactory = databaseContextFactory ?? throw new ArgumentNullException(nameof(databaseContextFactory));
     this.application            = application ?? throw new ArgumentNullException(nameof(application));
     this.loggerFactory          = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
     this.byondTopicSender       = byondTopicSender ?? throw new ArgumentNullException(nameof(byondTopicSender));
     this.cryptographySuite      = cryptographySuite ?? throw new ArgumentNullException(nameof(cryptographySuite));
     this.synchronousIOManager   = synchronousIOManager ?? throw new ArgumentNullException(nameof(synchronousIOManager));
     this.symlinkFactory         = symlinkFactory ?? throw new ArgumentNullException(nameof(symlinkFactory));
     this.byondInstaller         = byondInstaller ?? throw new ArgumentNullException(nameof(byondInstaller));
     this.chatFactory            = chatFactory ?? throw new ArgumentNullException(nameof(chatFactory));
     this.processExecutor        = processExecutor ?? throw new ArgumentNullException(nameof(processExecutor));
     this.postWriteHandler       = postWriteHandler ?? throw new ArgumentNullException(nameof(postWriteHandler));
     this.watchdogFactory        = watchdogFactory ?? throw new ArgumentNullException(nameof(watchdogFactory));
     this.jobManager             = jobManager ?? throw new ArgumentNullException(nameof(jobManager));
     this.credentialsProvider    = credentialsProvider ?? throw new ArgumentNullException(nameof(credentialsProvider));
     this.networkPromptReaper    = networkPromptReaper ?? throw new ArgumentNullException(nameof(networkPromptReaper));
 }
예제 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WindowsWatchdog"/> <see langword="class"/>.
 /// </summary>
 /// <param name="chat">The <see cref="IChat"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="sessionControllerFactory">The <see cref="ISessionControllerFactory"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="dmbFactory">The <see cref="IDmbFactory"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="reattachInfoHandler">The <see cref="IReattachInfoHandler"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="databaseContextFactory">The <see cref="IDatabaseContextFactory"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="byondTopicSender">The <see cref="IByondTopicSender"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="eventConsumer">The <see cref="IEventConsumer"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="jobManager">The <see cref="IJobManager"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="serverControl">The <see cref="IServerControl"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="asyncDelayer">The <see cref="IAsyncDelayer"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="ioManager">The value of <see cref="ioManager"/>.</param>
 /// <param name="symlinkFactory">The value of <see cref="symlinkFactory"/>.</param>
 /// <param name="logger">The <see cref="ILogger"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="initialLaunchParameters">The <see cref="DreamDaemonLaunchParameters"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="instance">The <see cref="Api.Models.Instance"/> for the <see cref="WatchdogBase"/>.</param>
 /// <param name="autoStart">The autostart value for the <see cref="WatchdogBase"/>.</param>
 public WindowsWatchdog(
     IChat chat,
     ISessionControllerFactory sessionControllerFactory,
     IDmbFactory dmbFactory,
     IReattachInfoHandler reattachInfoHandler,
     IDatabaseContextFactory databaseContextFactory,
     IByondTopicSender byondTopicSender,
     IEventConsumer eventConsumer,
     IJobManager jobManager,
     IServerControl serverControl,
     IAsyncDelayer asyncDelayer,
     IIOManager ioManager,
     ISymlinkFactory symlinkFactory,
     ILogger <WindowsWatchdog> logger,
     DreamDaemonLaunchParameters initialLaunchParameters,
     Api.Models.Instance instance, bool autoStart)
     : base(
         chat,
         sessionControllerFactory,
         dmbFactory,
         reattachInfoHandler,
         databaseContextFactory,
         byondTopicSender,
         eventConsumer,
         jobManager,
         serverControl,
         asyncDelayer,
         logger,
         initialLaunchParameters,
         instance,
         autoStart)
 {
     try
     {
         this.ioManager      = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
         this.symlinkFactory = symlinkFactory ?? throw new ArgumentNullException(nameof(symlinkFactory));
     }
     catch
     {
         Dispose();
         throw;
     }
 }
예제 #12
0
        /// <summary>
        /// Construct a <see cref="SessionController"/>
        /// </summary>
        /// <param name="reattachInformation">The value of <see cref="reattachInformation"/></param>
        /// <param name="process">The value of <see cref="process"/></param>
        /// <param name="byondLock">The value of <see cref="byondLock"/></param>
        /// <param name="byondTopicSender">The value of <see cref="byondTopicSender"/></param>
        /// <param name="interopContext">The value of <see cref="interopContext"/></param>
        /// <param name="chat">The value of <see cref="chat"/></param>
        /// <param name="chatJsonTrackingContext">The value of <see cref="chatJsonTrackingContext"/></param>
        /// <param name="logger">The value of <see cref="logger"/></param>
        /// <param name="startupTimeout">The optional time to wait before failing the <see cref="LaunchResult"/></param>
        public SessionController(ReattachInformation reattachInformation, IProcess process, IByondExecutableLock byondLock, IByondTopicSender byondTopicSender, IJsonTrackingContext chatJsonTrackingContext, ICommContext interopContext, IChat chat, ILogger <SessionController> logger, uint?startupTimeout)
        {
            this.chatJsonTrackingContext = chatJsonTrackingContext;             //null valid
            this.reattachInformation     = reattachInformation ?? throw new ArgumentNullException(nameof(reattachInformation));
            this.byondTopicSender        = byondTopicSender ?? throw new ArgumentNullException(nameof(byondTopicSender));
            this.process        = process ?? throw new ArgumentNullException(nameof(process));
            this.byondLock      = byondLock ?? throw new ArgumentNullException(nameof(byondLock));
            this.interopContext = interopContext ?? throw new ArgumentNullException(nameof(interopContext));
            this.chat           = chat ?? throw new ArgumentNullException(nameof(chat));
            this.logger         = logger ?? throw new ArgumentNullException(nameof(logger));

            interopContext.RegisterHandler(this);

            portClosedForReboot = false;
            disposed            = false;
            apiValidated        = false;
            released            = false;

            rebootTcs = new TaskCompletionSource <object>();

            async Task <LaunchResult> GetLaunchResult()
            {
                var  startTime = DateTimeOffset.Now;
                Task toAwait   = process.Startup;

                if (startupTimeout.HasValue)
                {
                    toAwait = Task.WhenAny(process.Startup, Task.Delay(startTime.AddSeconds(startupTimeout.Value) - startTime));
                }

                await toAwait.ConfigureAwait(false);

                var result = new LaunchResult
                {
                    ExitCode    = process.Lifetime.IsCompleted ? (int?)await process.Lifetime.ConfigureAwait(false) : null,
                    StartupTime = process.Startup.IsCompleted ? (TimeSpan?)(DateTimeOffset.Now - startTime) : null
                };

                return(result);
            };
            LaunchResult = GetLaunchResult();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="WindowsWatchdogFactory"/> <see langword="class"/>.
 /// </summary>
 /// <param name="serverControl">The <see cref="IServerControl"/> for the <see cref="WatchdogFactory"/>.</param>
 /// <param name="loggerFactory">The <see cref="ILoggerFactory"/> for the <see cref="WatchdogFactory"/>.</param>
 /// <param name="databaseContextFactory">The <see cref="IDatabaseContextFactory"/> for the <see cref="WatchdogFactory"/>.</param>
 /// <param name="byondTopicSender">The <see cref="IByondTopicSender"/> for the <see cref="WatchdogFactory"/>.</param>
 /// <param name="jobManager">The <see cref="IJobManager"/> for the <see cref="WatchdogFactory"/>.</param>
 /// <param name="asyncDelayer">The <see cref="IAsyncDelayer"/> for the <see cref="WatchdogFactory"/>.</param>
 /// <param name="symlinkFactory">The value of <see cref="symlinkFactory"/>.</param>
 /// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> for <see cref="GeneralConfiguration"/> for the <see cref="WatchdogFactory"/>.</param>
 public WindowsWatchdogFactory(
     IServerControl serverControl,
     ILoggerFactory loggerFactory,
     IDatabaseContextFactory databaseContextFactory,
     IByondTopicSender byondTopicSender,
     IJobManager jobManager,
     IAsyncDelayer asyncDelayer,
     ISymlinkFactory symlinkFactory,
     IOptions <GeneralConfiguration> generalConfigurationOptions)
     : base(
         serverControl,
         loggerFactory,
         databaseContextFactory,
         byondTopicSender,
         jobManager,
         asyncDelayer,
         generalConfigurationOptions)
 {
     this.symlinkFactory = symlinkFactory ?? throw new ArgumentNullException(nameof(symlinkFactory));
 }
 /// <summary>
 /// Construct a <see cref="WatchdogFactory"/>
 /// </summary>
 /// <param name="serverControl">The value of <see cref="ServerControl"/></param>
 /// <param name="loggerFactory">The value of <see cref="LoggerFactory"/></param>
 /// <param name="databaseContextFactory">The value of <see cref="DatabaseContextFactory"/></param>
 /// <param name="byondTopicSender">The value of <see cref="ByondTopicSender"/></param>
 /// <param name="jobManager">The value of <see cref="JobManager"/></param>
 /// <param name="asyncDelayer">The value of <see cref="AsyncDelayer"/></param>
 /// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="GeneralConfiguration"/></param>
 public WatchdogFactory(IServerControl serverControl, ILoggerFactory loggerFactory, IDatabaseContextFactory databaseContextFactory, IByondTopicSender byondTopicSender, IJobManager jobManager, IAsyncDelayer asyncDelayer, IOptions <GeneralConfiguration> generalConfigurationOptions)
 {
     ServerControl          = serverControl ?? throw new ArgumentNullException(nameof(serverControl));
     LoggerFactory          = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
     DatabaseContextFactory = databaseContextFactory ?? throw new ArgumentNullException(nameof(databaseContextFactory));
     ByondTopicSender       = byondTopicSender ?? throw new ArgumentNullException(nameof(byondTopicSender));
     JobManager             = jobManager ?? throw new ArgumentNullException(nameof(jobManager));
     AsyncDelayer           = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer));
     GeneralConfiguration   = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
 }