private void OnDeviceSelected(object sender, SelectionChangedEventArgs e) { string deviceIdString = (string)DeviceListBox.SelectedItem; ConnectedProperties.IsEnabled = false; if (!String.IsNullOrEmpty(deviceIdString)) { _deviceTwin = new DeviceTwinAndMethod(ConnectionStringBox.Text, deviceIdString); ConnectedProperties.IsEnabled = true; } SelectedDeviceName.Text = deviceIdString; // ToDo: There should be an easy mechanism to enumerate all sub-controls and clear them all // (or populate them with information from the device twin). // TheAppsStatus.Clear(); TheAppsConfigurator.Clear(); }
private async void ReadDTReported() { DeviceTwinData deviceTwinData = await _deviceTwin.GetDeviceTwinData(); Debug.WriteLine("json = " + deviceTwinData.reportedPropertiesJson); JObject desiredObject = (JObject)JsonConvert.DeserializeObject(deviceTwinData.reportedPropertiesJson); JToken windowsToken; if (!desiredObject.TryGetValue(DMJSonConstants.DTWindowsIoTNameSpace, out windowsToken) || windowsToken.Type != JTokenType.Object) { return; } JObject windowsObject = (JObject)windowsToken; foreach (JProperty jsonProp in windowsObject.Children()) { if (jsonProp.Name == "timeInfo" && jsonProp.Value.Type == JTokenType.Object) { Debug.WriteLine(jsonProp.Value.ToString()); TimeReportedState.FromJson((JObject)jsonProp.Value); } else if (jsonProp.Name == TimeSvcReportedState.SectionName && jsonProp.Value.Type == JTokenType.Object) { Debug.WriteLine(jsonProp.Value.ToString()); TimeSvcReportedState.FromJson((JObject)jsonProp.Value); } else if (jsonProp.Name == CertificatesDataContract.SectionName && jsonProp.Value.Type == JTokenType.Object) { Debug.WriteLine(jsonProp.Value.ToString()); var reportedProperties = CertificatesDataContract.ReportedProperties.FromJsonObject((JObject)jsonProp.Value); CertificatesInfoToUI(reportedProperties); } else if (jsonProp.Name == DeviceInfoDataContract.SectionName) { Debug.WriteLine(jsonProp.Value.ToString()); if (jsonProp.Value is JObject) { DeviceInfoReportedState.FromJsonObject((JObject)jsonProp.Value); } else { MessageBox.Show("Expected json object as a value for " + DeviceInfoReportedState.SectionName); } } else if (jsonProp.Name == ExternalStorageDataContract.SectionName) { Debug.WriteLine(jsonProp.Value.ToString()); if (jsonProp.Value is JObject) { var reportedProperties = ExternalStorageDataContract.ReportedProperties.FromJsonObject((JObject)jsonProp.Value); AzureStorageReportedConnectionString.Text = reportedProperties.connectionString; } else { MessageBox.Show("Expected json object as a value for " + DeviceInfoReportedState.SectionName); } } else if (jsonProp.Name == DmAppStoreUpdateDataContract.SectionName) { Debug.WriteLine(jsonProp.Value.ToString()); if (jsonProp.Value is JObject) { DmAppStoreUpdateReportedState.FromJsonObject((JObject)jsonProp.Value); } else { MessageBox.Show("Expected json object as a value for " + DmAppStoreUpdateDataContract.SectionName); } } else if (jsonProp.Name == RebootInfoDataContract.SectionName) { Debug.WriteLine(jsonProp.Value.ToString()); RebootInfoReportedState.FromJsonObject(jsonProp.Value); } else if (jsonProp.Name == RebootCmdDataContract.SectionName) { Debug.WriteLine(jsonProp.Value.ToString()); RebootCmdReportedState.FromJson(jsonProp.Value); } else if (jsonProp.Name == WindowsUpdatePolicyDataContract.SectionName) { Debug.WriteLine(jsonProp.Value.ToString()); WindowsUpdatePolicyReportedState.FromJsonObject(jsonProp.Value); } else if (jsonProp.Name == WindowsUpdatesDataContract.SectionName) { Debug.WriteLine(jsonProp.Value.ToString()); if (jsonProp.Value is JObject) { WindowsUpdatesConfigurationToUI((JObject)jsonProp.Value); } else { MessageBox.Show("Expected json object as a value for " + WindowsUpdatesDataContract.SectionName); } } else if (jsonProp.Name == WindowsTelemetryDataContract.SectionName) { Debug.WriteLine(jsonProp.Value.ToString()); if (jsonProp.Value is JObject) { WindowsTelemetryReportedState.FromJsonObject((JObject)jsonProp.Value); } else { MessageBox.Show("Expected json object as a value for " + WindowsTelemetryDataContract.SectionName); } } else if (jsonProp.Name == "apps") { Debug.WriteLine(jsonProp.Value.ToString()); TheAppsStatus.AppsStatusJsonToUI(jsonProp.Value); } else if (jsonProp.Name == "deviceHealthAttestation") { Debug.WriteLine(jsonProp.Value.ToString()); var jobj = JObject.Parse(jsonProp.Value.ToString()); DeviceHealthAttestationReportedState.FromJson(jobj); } else if (jsonProp.Name == "wifi") { Debug.WriteLine(jsonProp.Value.ToString()); this.WifiReportedState.FromJson(jsonProp.Value); } else if (jsonProp.Name == "eventTracingCollectors") { Debug.WriteLine(jsonProp.Value.ToString()); this.ReportedDiagnosticLogs.FromJson((JObject)jsonProp.Value); } } }