/// <summary> /// Get additional details on a specific device. /// If a DeviceList is present this list is also updated with the additional details. /// </summary> /// <param name="monitorId">Monitor ID that the device is registered on</param> /// <param name="deviceId">Device ID to get additional details for</param> /// <returns>Device Details for the specified device.</returns> public async Task <DeviceDetails> GetDeviceDetails(int monitorId, string deviceId) { using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Config["accesstoken"]); var callData = $"{apiAddress}/app/monitors/{monitorId}/devices/{deviceId}"; var response = await httpClient.GetAsync(callData); await CheckResponseStatus(response, httpClient, callData); var json = await response.Content.ReadAsStringAsync(); var deviceDetails = JsonConvert.DeserializeObject <DeviceDetails>(json); if (DeviceList == null || DeviceList.Count <= 0) { return(deviceDetails); } var device = DeviceList.FirstOrDefault(x => x.Id == deviceId); if (device == null) { return(deviceDetails); } var pos = DeviceList.FindIndex(x => x.Id == deviceId); DeviceList.RemoveAt(pos); device = deviceDetails.Device; DeviceList.Insert(pos, device); return(deviceDetails); } }
/// <summary> /// If a DeviceList is present this list is also updated with the additional details. /// </summary> /// <param name="deviceId">Device ID of the device</param> /// <param name="deviceDetails">Device Details for the specified device.</param> private void UpdateDeviceList(string deviceId, DeviceDetails deviceDetails) { if (DeviceList != null && DeviceList.Count > 0) { var device = DeviceList.FirstOrDefault(x => x.Id == deviceId); if (device != null) { var pos = DeviceList.FindIndex(x => x.Id == deviceId); DeviceList.RemoveAt(pos); device = deviceDetails.Device; DeviceList.Insert(pos, device); } } }