Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UpdaterService"/> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="twitchMessageService">The twitch message service.</param>
        /// <param name="discordMessageService">The discord message service.</param>
        /// <param name="steamCmdService">The steam command service.</param>
        /// <param name="messageTemplates">The message templates.</param>
        /// <param name="autorestartService">The autorestart service.</param>
        /// <param name="rconMessageService">The rcon message service.</param>
        public UpdaterService(
            ILogger <UpdaterService> logger,
            IOptionsSnapshot <Settings> settings,
            ITwitchMessageService twitchMessageService,
            IDiscordMessageService discordMessageService,
            ISteamCmdService steamCmdService,
            IOptionsSnapshot <Messages> messageTemplates,
            IAutoRestartServerService autorestartService,
            IRconMessageService rconMessageService)
        {
            _logger                = logger;
            _settings              = settings.Value;
            _autorestartService    = autorestartService;
            _twitchMessageService  = twitchMessageService;
            _discordMessageService = discordMessageService;
            _rconMessageService    = rconMessageService;
            _steamCmdService       = steamCmdService;
            _twitchMessages        = messageTemplates.Value.Twitch;
            _discordMessages       = messageTemplates.Value.Discord;
            _rconMessages          = messageTemplates.Value.RCON;
            _logger.LogInformation("Updater Service has Started");

            if (_settings.Update.ShouldInstallSteamCmdIfMissing)
            {
                InstallSteamCMD();
            }

            if (_settings.Update.ShouldInstallAtlasServerIfMissing)
            {
                Process process = Process.GetProcesses().FirstOrDefault(c => c.ProcessName.Contains(_settings.Atlas.ServerProcessName));
                if (process is null)
                {
                    _steamCmdService.InstallAndUpdateAtlasServer();
                }
            }


            _updateTimer = new System.Timers.Timer(_settings.Update.UpdateCheckInterval * 1000 * 60)
            {
                AutoReset = true,
                Enabled   = false
            };

            if (_settings.General.ShouldRestartAtlasOnNotRunning)
            {
                SetupServerProcessMonitor();
            }

            if (_settings.General.RestartServerAfterHours != 0)
            {
                _autorestartService.StartTimer();
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AutoRestartServerService"/> class.
 /// </summary>
 /// <param name="discordMessageService">The discord message service.</param>
 /// <param name="twitchMessageService">The twitch message service.</param>
 /// <param name="settings">The settings.</param>
 /// <param name="messageTemplates">The message templates.</param>
 /// <param name="logger">The logger.</param>
 /// <param name="steamCmdService">The steam command service.</param>
 /// <param name="rconMessageService">The rcon message service.</param>
 public AutoRestartServerService(IDiscordMessageService discordMessageService,
                                 ITwitchMessageService twitchMessageService,
                                 IOptionsSnapshot <Settings> settings,
                                 IOptionsSnapshot <Messages> messageTemplates,
                                 ILogger <AutoRestartServerService> logger,
                                 ISteamCmdService steamCmdService,
                                 IRconMessageService rconMessageService)
 {
     _settings              = settings.Value;
     _logger                = logger;
     _steamCmdService       = steamCmdService;
     _discordMessageService = discordMessageService;
     _rconMessageService    = rconMessageService;
     _twitchMessageService  = twitchMessageService;
     _twitchMessages        = messageTemplates.Value.Twitch;
     _discordMessages       = messageTemplates.Value.Discord;
     _rconMessages          = messageTemplates.Value.RCON;
 }