private void SaveSettings(NetmoSettings _data) { string executingpath = System.Reflection.Assembly.GetExecutingAssembly().Location; FileInfo fi = new FileInfo(executingpath); string pfad = fi.DirectoryName; using (StreamWriter file = File.CreateText(pfad + System.IO.Path.DirectorySeparatorChar + "netmo.settings")) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, _data); } }
private void BtnSpeichern_Click(object sender, RoutedEventArgs e) { settings = new NetmoSettings { ClientId = txtClientId.Text, ClientSecret = txtClientSecret.Text, Password = Encryption.EncryptString(txtPassword.Password.ToString(), ENCRYPTKEY), Username = txtName.Text, DeviceId = txtDeviceId.Text }; SaveSettings(settings); MessageBox.Show("Die Einstellungen wurden gespeichert"); }
public MainWindow() { mw = this; InitializeComponent(); settings = LoadSettings(); if (settings != null) { settings.Password = Encryption.DecryptString(settings.Password, ENCRYPTKEY); this.txtDeviceId.Text = settings.DeviceId; this.txtName.Text = settings.Username; this.txtPassword.Password = settings.Password; this.txtClientSecret.Text = settings.ClientSecret; this.txtClientId.Text = settings.ClientId; } else { MessageBox.Show("No settings found, please configure and save the settings!"); } //var nvc = new List<KeyValuePair<string, string>>(); //nvc.Add(new KeyValuePair<string, string>("client_id", "5c18ff3c6b0affcc188bbe4a")); //nvc.Add(new KeyValuePair<string, string>("client_secret", "SjHyLVQnhaougeMNW9ahihewPGjbEiCl2zS")); //nvc.Add(new KeyValuePair<string, string>("grant_type", "password")); //nvc.Add(new KeyValuePair<string, string>("username", System.Configuration.ConfigurationManager.AppSettings["usr"])); //nvc.Add(new KeyValuePair<string, string>("password", System.Configuration.ConfigurationManager.AppSettings["pwd"])); connector = new Connector(settings.ClientId, settings.ClientSecret, settings.Username, settings.Password, settings.DeviceId); var netatmodata = connector.GetNetatmoWeatherData(); int i = 0; foreach (var item in NetmoDevice.nd) { if (i >= netatmodata.Body.Devices.Length) { item.Visibility = Visibility.Collapsed; break; } item.Init(netatmodata.Body.Devices[i]); i++; } GenerateTabs(netatmodata); }
public NetmoSettings LoadSettings() { NetmoSettings settings = null; string executingpath = System.Reflection.Assembly.GetExecutingAssembly().Location; FileInfo fi = new FileInfo(executingpath); string settingsfile = fi.DirectoryName + System.IO.Path.DirectorySeparatorChar + "netmo.settings"; if (!File.Exists(settingsfile)) { return(null); } using (StreamReader sr = new StreamReader(settingsfile)) { string filetext = sr.ReadToEnd(); settings = JsonConvert.DeserializeObject <NetmoSettings>(filetext); } return(settings); }