Beispiel #1
0
        private async void AddSensor()
        {
            timer.Stop();
            if (Devices_List.SelectedItem != null)
            {
                var data       = Devices_List.SelectedItem.ToString().Split(' ');
                var sensorId   = data.LastOrDefault();
                var sensorName = data[1];
                if (sensorId != null)
                {
                    foreach (var sensor in App.Current.ApplicationConfiguration.ConnectedSensors)
                    {
                        if (sensor.BluetoothId == sensorId)
                        {
                            UpdateErrorMessage("This sensor is already being tracked.");

                            timer.Start();
                            return;
                        }
                    }
                    var newSensor = new SensorProfile()
                    {
                        SensorId      = Guid.NewGuid(),
                        BluetoothId   = sensorId,
                        BluetoothName = sensorName
                    };
                    App.Current.ApplicationConfiguration.ConnectedSensors.Add(newSensor);
                    var request = (HttpWebRequest)WebRequest.Create("http://" + App.Current.ApplicationConfiguration.AzureVMIp + "/insert_sensor?sensor_id=" + newSensor.SensorId + "&sensor_name=NewlyAddedSensor");
                    await request.GetResponseAsync();

                    var writeSuccess = await App.Current.SaveApplicationConfiguration();

                    if (!writeSuccess)
                    {
                        UpdateErrorMessage("Configuration write failed.");
                    }
                    else
                    {
                        UpdateDevicesList();
                    }
                }
            }
            UpdateErrorMessage("Select a sensor from the list.");
            timer.Start();
        }
Beispiel #2
0
        private async void AddSensor()
        {
            timer.Stop();
            if (Devices_List.SelectedItem != null)
            {
                var data = Devices_List.SelectedItem.ToString().Split(' ');
                var sensorId = data.LastOrDefault();
                var sensorName = data[1];
                if (sensorId != null)
                {
                    foreach (var sensor in App.Current.ApplicationConfiguration.ConnectedSensors)
                    {
                        if (sensor.BluetoothId == sensorId)
                        {

                            UpdateErrorMessage("This sensor is already being tracked.");

                            timer.Start();
                            return;
                        }
                    }
                    var newSensor = new SensorProfile()
                    {
                        SensorId = Guid.NewGuid(),
                        BluetoothId = sensorId,
                        BluetoothName = sensorName
                    };
                    App.Current.ApplicationConfiguration.ConnectedSensors.Add(newSensor);
                    var request = (HttpWebRequest)WebRequest.Create("http://" + App.Current.ApplicationConfiguration.AzureVMIp + "/insert_sensor?sensor_id=" + newSensor.SensorId + "&sensor_name=NewlyAddedSensor");
                    await request.GetResponseAsync();
                    var writeSuccess = await App.Current.SaveApplicationConfiguration();

                    if (!writeSuccess)
                        UpdateErrorMessage("Configuration write failed.");
                    else
                        UpdateDevicesList();
                }

            }
            UpdateErrorMessage("Select a sensor from the list.");
            timer.Start();

        }