public async Task ExecuteAsync(CancellationToken stoppingToken) { _logger.LogInformation($"Starting NetDaemon runtime version {Version}."); _stoppingToken = stoppingToken; _homeAssistantRunner.OnConnect .Select(async c => await OnHomeAssistantClientConnected(c, stoppingToken).ConfigureAwait(false)) .Subscribe(); _homeAssistantRunner.OnDisconnect .Select(async s => await OnHomeAssistantClientDisconnected(s).ConfigureAwait(false)) .Subscribe(); try { await _homeAssistantRunner.RunAsync( _haSettings.Host, _haSettings.Port, _haSettings.Ssl, _haSettings.Token, _haSettings.WebsocketPath, TimeSpan.FromSeconds(TimeoutInSeconds), stoppingToken).ConfigureAwait(false); } catch (OperationCanceledException) { // Ignore and just stop } _logger.LogInformation("Exiting NetDaemon runtime."); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { _cancelToken = stoppingToken; await _homeAssistantRunner.RunAsync( _haSettings.Host, _haSettings.Port, _haSettings.Ssl, _haSettings.Token, TimeSpan.FromSeconds(TimeoutInSeconds), stoppingToken).ConfigureAwait(false); // Stop application if this is exited and use _cancelToken as token _hostLifetime.StopApplication(); }