public string ToJsonString() { WindowsTelemetryDataContract.DesiredProperties desiredProperties = new WindowsTelemetryDataContract.DesiredProperties(); switch (LevelComboBox.SelectedIndex) { case 0: desiredProperties.level = WindowsTelemetryDataContract.JsonSecurity; break; case 1: desiredProperties.level = WindowsTelemetryDataContract.JsonBasic; break; case 2: desiredProperties.level = WindowsTelemetryDataContract.JsonEnhanced; break; case 3: desiredProperties.level = WindowsTelemetryDataContract.JsonFull; break; default: MessageBox.Show("Not implemented! Selected 'security'."); break; } return(desiredProperties.ToJsonString()); }
/// <summary> /// Set windows telemetry setting via device twin. /// </summary> private async void SetDesiredButton_ClickAsync(object sender, RoutedEventArgs e) { WindowsTelemetryDataContract.DesiredProperties desiredProperties = new WindowsTelemetryDataContract.DesiredProperties(); switch (DesiredCombobox.SelectedIndex) { case 0: desiredProperties.level = WindowsTelemetryDataContract.JsonSecurity; break; case 1: desiredProperties.level = WindowsTelemetryDataContract.JsonBasic; break; case 2: desiredProperties.level = WindowsTelemetryDataContract.JsonEnhanced; break; case 3: desiredProperties.level = WindowsTelemetryDataContract.JsonFull; break; default: _mainPage.ShowDialogAsync("Invaid Input", "Desired value not selected! Selected 'security'."); break; } string refreshingValue = "\"refreshing\""; string finalValue = "{" + desiredProperties.ToJsonString() + "}"; await _mainPage.UpdateTwinData(refreshingValue, finalValue); }
// IClientPropertyHandler public async Task <CommandStatus> OnDesiredPropertyChange(JToken desiredValue) { Logger.Log("WindowsTelemetryHandler.OnDesiredPropertyChange()", LoggingLevel.Verbose); if (!(desiredValue is JObject)) { throw new Error(ErrorCodes.INVALID_DESIRED_JSON_VALUE, "Invalid json value type for the " + PropertySectionName + " node."); } WindowsTelemetryDataContract.DesiredProperties desiredProperties = WindowsTelemetryDataContract.DesiredProperties.FromJsonObject((JObject)desiredValue); await SetLevelAsync(desiredProperties.level); return(CommandStatus.Committed); }