Exemple #1
0
        public async Task Run()
        {
            PrintAppInfo();

            Console.CancelKeyPress += (s, e) =>
            {
                e.Cancel = true;
                _cancellation.Cancel();
            };

            _logger.Info("Read stable device info...");
            StableDeviceInfo stableDeviceInfo = await _stableDeviceCollector.Read();

            _logger.Info(_jsonSerializer.SerializeWithFormatting(stableDeviceInfo));

            _logger.Info("Read volatile device info...");
            VolatileDeviceInfo volatileDeviceInfo = await _volatileDeviceCollector.Read();

            _logger.Info(_jsonSerializer.SerializeWithFormatting(volatileDeviceInfo));

            _logger.Info("Send stable device info ...");
            await _serverConnector.Send(stableDeviceInfo);

            _logger.Info("Send volatile device info ...");
            await _serverConnector.Send(volatileDeviceInfo);
        }
        public async Task Send(StableDeviceInfo deviceInfo)
        {
            await RequestTokenIfRequired();

            var request = CreateRequest("/stable", deviceInfo, Method.PUT);

            _restClient.BaseUrl = _serverUrl;
            IRestResponse response = await _restClient.ExecuteTaskAsync(request, _cancellation.Token);

            if (!response.IsSuccessful)
            {
                throw new HttpException((int)response.StatusCode, "send stable device info failed: " +
                                        (string.IsNullOrEmpty(response.Content) ? "no response" : response.Content));
            }
        }
Exemple #3
0
        public async Task Send(StableDeviceInfo deviceInfo)
        {
            try
            {
                var request = CreateRequest("/stableDevice", deviceInfo, Method.POST);
                await AddHeaders(request);

                var response = _restClient.Execute(request);
                if (!response.IsSuccessful)
                {
                    throw new HttpException(
                              (int)response.StatusCode,
                              "send stable device info failed: " +
                              (string.IsNullOrEmpty(response.Content)
                                            ? "no response"
                                            : response.Content));
                }
            }
            catch (Exception ex)
            {
                _logger.Error($"Error: {ex.Message}");
            }
        }