/// <inheritdoc/> public async Task ActivateEndpointAsync(string id, string secret, CancellationToken ct) { await _lock.WaitAsync(); try { if (_twinHosts.TryGetValue(id, out var twin) && twin.Running) { _logger.Debug("{id} twin already running.", id); return; } _logger.Debug("{id} twin starting...", id); _twinHosts.Remove(id); var host = new TwinHost(this, _config, id, secret, _logger); _twinHosts.Add(id, host); // // This starts and waits for the twin to be started - versus attaching which // represents the state of the actived and supervised twins in the supervisor // device twin. // await host.Started; _logger.Information("{id} twin started.", id); } finally { _lock.Release(); } }
/// <summary> /// Stop one twin /// </summary> /// <param name="id"></param> /// <param name="twin"></param> /// <returns></returns> private async Task StopOneTwinAsync(string id, TwinHost twin) { _logger.Debug("{id} twin is stopping...", id); try { // Stop host async await twin.StopAsync(); } catch (Exception ex) { // BUGBUG: IoT Hub client SDK throws general exceptions independent // of what actually happened. Instead of parsing the message, // just continue. _logger.Debug(ex, "{id} twin stopping raised exception, continue...", id); } finally { twin.Dispose(); } _logger.Information("{id} twin stopped.", id); }
/// <inheritdoc/> public async Task AttachEndpointAsync(string id, string secret) { await _lock.WaitAsync(); try { if (_twinHosts.TryGetValue(id, out var twin)) { _logger.Debug("{id} twin already attached.", id); return; } _logger.Debug("Attaching endpoint {id} twin...", id); var host = new TwinHost(this, _config, id, secret, _logger); _twinHosts.Add(id, host); _logger.Information("{id} twin attached to module.", id); } finally { _lock.Release(); } }
/// <inheritdoc/> public async Task ActivateEndpointAsync(string id, string secret, CancellationToken ct) { try { await _lock.WaitAsync(); if (_twinHosts.TryGetValue(id, out var twin) && twin.Running) { _logger.Debug("{id} twin already running.", id); return; } _logger.Debug("{id} twin starting...", id); _twinHosts.Remove(id); var host = new TwinHost(this, _config, id, secret); _twinHosts.Add(id, host); await host.Started; _logger.Information("{id} twin started.", id); } finally { _lock.Release(); } }