public async Task GetTwinAsync()

in DeviceBridge/Services/ConnectionManager.cs [466:491]


        public async Task<Microsoft.Azure.Devices.Shared.Twin> GetTwinAsync(Logger logger, string deviceId, CancellationToken cancellationToken)
        {
            logger.Info("Getting twin for device {deviceId}", deviceId);

            // This method expects a connection to have been previously established
            if (!_clients.TryGetValue(deviceId, out DeviceClient client))
            {
                var e = new DeviceConnectionNotFoundException(deviceId);
                logger.Error(e, "Tried to get twin for device {deviceId} but an active connection was not found", deviceId);
                throw e;
            }

            Microsoft.Azure.Devices.Shared.Twin twin;

            try
            {
                twin = await client.GetTwinAsync(cancellationToken);
            }
            catch (Exception e)
            {
                throw TranslateSdkException(e, deviceId);
            }

            logger.Info("Successfully got twin for device {deviceId}", deviceId);
            return twin;
        }