public void Commit() { if (!string.IsNullOrEmpty(ResourceGroupName)) { IoTHubConnectionDetails.ResourceGroupName = ResourceGroupName; } if (!string.IsNullOrEmpty(IoTHubName)) { IoTHubConnectionDetails.IoTHubName = IoTHubName; } if (!string.IsNullOrEmpty(DeviceId)) { IoTHubConnectionDetails.DeviceId = DeviceId; } if (!string.IsNullOrEmpty(IoTHubConnectionString)) { IoTHubConnectionDetails.IoTHubConnectionString = IoTHubConnectionString; } if (!string.IsNullOrEmpty(DeviceConnectionString)) { IoTHubConnectionDetails.DeviceConnectionString = DeviceConnectionString; } if (!string.IsNullOrEmpty(EventHubsCompatiblePath)) { IoTHubConnectionDetails.EventHubsCompatiblePath = EventHubsCompatiblePath; } if (!string.IsNullOrEmpty(EventHubsCompatibleEndpoint)) { IoTHubConnectionDetails.EventHubsCompatibleEndpoint = EventHubsCompatibleEndpoint; } if (!string.IsNullOrEmpty(EventHubsConnectionString)) { IoTHubConnectionDetails.EventHubsConnectionString = EventHubsConnectionString; } if (!string.IsNullOrEmpty(IotHubKeyName)) { IoTHubConnectionDetails.IotHubKeyName = IotHubKeyName; } if (!string.IsNullOrEmpty(EventHubsSasKey)) { IoTHubConnectionDetails.EventHubsSasKey = EventHubsSasKey; } IoTHubConnectionDetails.EHMethod1 = EHMethod1; AppSettings.SaveSettingsToAppData(); }
// Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; // if (localSettings.Values.Keys.Contains("ConDetail")) // { // Windows.Storage.ApplicationDataCompositeValue composite = // (Windows.Storage.ApplicationDataCompositeValue)localSettings.Values["ConDetail"]; // if (composite != null) // { // //Ref: https://stackoverflow.com/questions/9404523/set-property-value-using-property-name // Type type = typeof(IoTHubConnectionDetails); // IoTHubConnectionDetails is static class with public static properties // foreach (var property in type.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static)) //(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)) // { // string propertyName = property.Name; // if (composite.Keys.Contains(propertyName)) // { // //Want to implement Cons.propertyName = composite[propertyName]; // var propertyInfo = type.GetProperty(propertyName); //, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static); // propertyInfo.SetValue(type, composite[propertyName], null); // } // } // } // } // if (localSettings.Values.Keys.Contains("AutoStartDevice")) // { // chkAutoStart.IsChecked = (bool) localSettings.Values["AutoStartDevice"]; // } // if (localSettings.Values.Keys.Contains("KeepDeviceListening")) // { // chKeepDeviceListening.IsChecked = (bool)localSettings.Values["KeepDeviceListening"]; // } // if (localSettings.Values.Keys.Contains("DeviceTimeout")) // { // if (localSettings.Values["DeviceTimeout"] is double) // { // double _deviceTimeout = (double)localSettings.Values["DeviceTimeout"]; // tbDeviceTimeout.Text = _deviceTimeout.ToString(); // } // else // tbDeviceTimeout.Text = DeviceStreamingCommon.DeviceTimeoutDef.ToString(); // } // else // tbDeviceTimeout.Text = DeviceStreamingCommon.DeviceTimeoutDef.ToString(); // if (localSettings.Values.Keys.Contains("SvcTimeout")) // { // if (localSettings.Values["SvcTimeout"] is double) // { // double _svcTimeout = (double)localSettings.Values["SvcTimeout"]; // tbSvcTimeout.Text = _svcTimeout.ToString(); // } // else // tbSvcTimeout.Text = DeviceStreamingCommon.SvcTimeoutDef.ToString(); // } // else // tbSvcTimeout.Text = DeviceStreamingCommon.SvcTimeoutDef.ToString(); //} //private void SaveConnectionSettingsToAzureConnections(ConDetail ccondetail) //{ // conDetail = ccondetail; // AzureConnections.MyConnections.IoTHubConnectionString = ccondetail.IoTHubConnectionString; // AzureConnections.MyConnections.DeviceConnectionString = ccondetail.DeviceConnectionString; // AzureConnections.MyConnections.DeviceId = ccondetail.DeviceId; // service_cs = AzureConnections.MyConnections.IoTHubConnectionString; // device_id = AzureConnections.MyConnections.DeviceId; // device_cs = AzureConnections.MyConnections.DeviceConnectionString; //} //private void DoneSetConnectionDetails_Click(object sender, RoutedEventArgs e) //{ // if (Popup_SetConnectionDetails.IsOpen) // { // SaveConnectionSettingsToAzureConnections(conDetail); // Popup_SetConnectionDetails.IsOpen = false; // } // else if (Popup_GetConnectionDetails.IsOpen) // { // conDetail.DevString = AzureConnections.MyConnections.GetDeviceCSAsync(conDetail.ConString, conDetail.DevId); // Popup_GetConnectionDetails.IsOpen = false; // } // else if (Popup_CreateDeviceDetails.IsOpen) // { // conDetail.DevString = AzureConnections.MyConnections.AddDeviceAsync(conDetail.ConString, conDetail.DevId); // Popup_CreateDeviceDetails.IsOpen = false; // } // else if (Popup_Delete.IsOpen) // { // conDetail = new ConDetail(AzureConnections.MyConnections.IoTHubConnectionString, AzureConnections.MyConnections.DeviceConnectionString, AzureConnections.MyConnections.DeviceId); // conDetail.DevString = AzureConnections.MyConnections.RemoveDeviceAsync(conDetail.ConString, conDetail.DevId); // Popup_Delete.IsOpen = false; // conDetail.DevId = ""; // conDetail.DevString = ""; // } // SaveSettingsToAppData(); //} public static void SaveSettingsToAppData() { AppSettings.SaveSettingsToAppData(); }