Esempio n. 1
0
    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.");
    }
Esempio n. 2
0
    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();
    }