private void InitConfiguration() { configDirectory = System.Environment.GetEnvironmentVariable("USERPROFILE") + @"\Documents\config.csv"; if (File.Exists(configDirectory)) { string[] lines = File.ReadAllLines(configDirectory); foreach (string line in lines) { string[] splitted = line.Split(';'); if (splitted.Length == 2) { config.SaveFileToPath = splitted[1]; path.Content = config.SaveFileToPath; } else if (splitted.Length != 0) { HoyluDevice device = new HoyluDevice(splitted[0], splitted[1], splitted[2], splitted[3], splitted[4], splitted[5], splitted[6]); device.TimestampLastUsed = DateTime.ParseExact(splitted[7], datePattern, provider); var dateDifference = (DateTime.Today - device.TimestampLastUsed).TotalDays; var deviceAlreadyInList = hoyluDevices.Where(x => x.Name == device.Name).ToList(); if (dateDifference <= 7 && deviceAlreadyInList.Count == 0) { hoyluDevices.Add(device); registeredDevices.Items.Add(device); } } } } else { CreateInitFile(configDirectory); InitConfiguration(); //Erneuter Aufruf sodass Config Objekt befüllt wird } }
private void registeredDevices_SelectionChanged(object sender, SelectionChangedEventArgs e) { HoyluDevice device = (HoyluDevice)registeredDevices.SelectedItem; hoyluDevices.Remove(device); device.TimestampLastUsed = DateTime.Now; hoyluDevices.Add(device); deviceName.Text = device.Name; registerBluetooth.IsChecked = (device.BluetoothAddress != null && device.BluetoothAddress != "") ? true : false; registerNFC.IsChecked = (device.NfcValue != null && device.NfcValue != "") ? true : false; registerQRCode.IsChecked = (device.QrValue != null && device.QrValue != "") ? true : false; registerNetwork.IsChecked = (device.PublicIp != null && device.PublicIp != "") ? true : false; }
private void register_Click(object sender, RoutedEventArgs e) { //hoyluId = "f67317b7-5823-474b-b8e2-aa36e5564942"; ////NFC Hoylu Test-ID hoyluId = Guid.NewGuid().ToString(); if (registerBluetooth.IsChecked == true) { bluetoothAddress = GetBTMacAddress(); if (bluetoothAddress == null) { MessageBox.Show("Bluetooth not available or supported on this device!"); } } if (registerQRCode.IsChecked == true) { qrValue = hoyluId; QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(qrValue, QRCodeGenerator.ECCLevel.L); QRCode qrCode = new QRCode(qrCodeData); qrCodeImage = qrCode.GetGraphic(20); qrUsed = true; } if (registerNFC.IsChecked == true) { nfcValue = hoyluId; Console.WriteLine("NFC enabled"); nfcUsed = true; } if (registerNetwork.IsChecked == true) { publicIp = new WebClient().DownloadString(@"http://icanhazip.com").Trim(); defaultGateway = GetDefaultGateway(); networkUsed = true; } name = deviceName.Text; hoyluDevice = new HoyluDevice(name, hoyluId, bluetoothAddress, qrValue, nfcValue, publicIp, defaultGateway); hoyluDevice.TimestampLastUsed = DateTime.Now; hoyluDevices.Add(hoyluDevice); registeredDevices.Items.Add(hoyluDevice); ConnectToServer(); Button register = sender as Button; register.IsEnabled = false; }