private async void GetPropertiesAsync() { if (DeviceList.SelectedItems.Count != 1) { MessageBox.Show("Only one device can be selected."); return; } DeviceSummary ds = (DeviceSummary)DeviceList.SelectedItem; DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(ds.ConnectionString, TransportType.Mqtt); DeviceTwinClient deviceTwinClient = new DeviceTwinClient(deviceClient); JObject root = await deviceTwinClient.GetRootAsync(); DesiredPropertyValueBox.Text = root["properties"]["desired"].ToString(); ReportedPropertyValueBox.Text = root["properties"]["reported"].ToString(); }
private async void SendReportedAsync() { JObject reportedValues = (JObject)JsonConvert.DeserializeObject(ReportedPropertyValueBox.Text); uint count = 0; foreach (DeviceSummary ds in DeviceList.SelectedItems) { Log("Updating device '" + ds.DeviceId + "'..."); DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(ds.ConnectionString, TransportType.Mqtt); DeviceTwinClient deviceTwinClient = new DeviceTwinClient(deviceClient); await deviceTwinClient.UpdateReportedPropertiesAsync(reportedValues, Log); ++count; } Log("Sent to " + count + " devices."); MessageBox.Show("Sent to " + count + " devices."); }