コード例 #1
0
        public void SendToAqi(Guid deviceId, string requestString)
        {
            _logger.LogInformation($"SendToAqi for device ID: {deviceId}");
            var device = _devicesRepository.GetDeviceById(deviceId);

            if (device != null && device.SendToAqiEco && !string.IsNullOrEmpty(device.AqiEcoUpdateUrl))
            {
                _logger.LogInformation($"SendToAqi - data will be send");
                Task.Run(async() =>
                {
                    var client   = new HttpClient();
                    var url      = $"{_settings.AqiEcoBaseUrl}{device.AqiEcoUpdateUrl}";
                    var response = await client.PostAsync(url, new JsonContent(requestString));
                    if (response.IsSuccessStatusCode)
                    {
                        _logger.LogInformation($"Code: {response.StatusCode}, {response.ReasonPhrase}");
                    }
                });
            }
        }