예제 #1
0
        /// <summary> Initializes a new instance of the <see cref="Range{T}" /> class. </summary>
        /// <param name="firstBoundary"> The first boundary. </param>
        /// <param name="secondBoundary"> The second boundary. </param>
        /// <param name="type"> The type or boundaries. </param>
        public Range(T firstBoundary, T secondBoundary, RangeBoundaries type = RangeBoundaries.InIn)
        {
            if (firstBoundary.CompareTo(other: secondBoundary) <= 0)
            {
                Min = firstBoundary;
                Max = secondBoundary;
            }
            else
            {
                Min = secondBoundary;
                Max = firstBoundary;
            }

            BoundariesType = type;
        }
예제 #2
0
        /// <summary>
        /// This function adds a sensor with the data from the fields to the collection of sensors
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            SensorData data = new SensorData
            {
                Name            = txtName.Text,
                Description     = txtDesc.Text,
                Location        = new Location((double)numLat.Value, (double)numLong.Value),
                Type            = sensorTypeChooser.Text,
                PollingInterval = (int)numPoll.Value
            };

            RangeBoundaries <string> boundaries = new RangeBoundaries <string>(numMinVal.Text, numMaxVal.Text);

            if (logic.AddSensor(data, boundaries))
            {
                logic.SaveState();
            }
        }
예제 #3
0
        /// <summary>
        /// Adds sensor with the given "data" to the Sensors List
        /// </summary>
        /// <param name="data"></param>
        /// <param name="rangeBoundaries"></param>
        /// <returns>True if the sensor is added successfully, False otherwise</returns>
        public bool AddSensor(SensorData data, RangeBoundaries <string> rangeBoundaries)
        {
            bool   success = true;
            Sensor sensor  = null;

            try
            {
                switch (data.Type)
                {
                case "DoorSensor":
                    sensor = new DoorSensor(data);
                    break;

                case "ElPowerSensor":
                    sensor = new ElPowerSensor(data, new RangeBoundaries <int>(int.Parse(rangeBoundaries.Min), int.Parse(rangeBoundaries.Max)));
                    break;

                case "NoiseSensor":
                    sensor = new NoiseSensor(data, new RangeBoundaries <int>(int.Parse(rangeBoundaries.Min), int.Parse(rangeBoundaries.Max)));
                    break;

                case "HumiditySensor":
                    sensor = new HumiditySensor(data, new RangeBoundaries <float>(float.Parse(rangeBoundaries.Min), float.Parse(rangeBoundaries.Max)));
                    break;

                case "TemperatureSensor":
                    sensor = new TemperatureSensor(data, new RangeBoundaries <double>(double.Parse(rangeBoundaries.Min), double.Parse(rangeBoundaries.Max)));
                    break;

                default:
                    break;
                }
                Sensors.Add(sensor);
                SaveState();
            }
            catch (Exception)
            {
                MessageBox.Show("Failed to add the sensor!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                success = false;
            }

            return(success);
        }
예제 #4
0
        /// <summary>
        /// Modifies a sensor's data with the given data
        /// </summary>
        /// <param name="sensor">The sensor to be modified</param>
        /// <param name="data">The new data</param>
        /// <param name="minVal">The new minimal bounary value</param>
        /// <param name="maxVal">The new maximal bounary value</param>
        public void ModifySensor(Sensor sensor, SensorData data, RangeBoundaries <string> rangeBoundaries)
        {
            sensor.Description     = data.Description;
            sensor.Location        = data.Location;
            sensor.PollingInterval = data.PollingInterval;

            rangeBoundaries.Min = rangeBoundaries.Min.Trim();
            rangeBoundaries.Max = rangeBoundaries.Max.Trim();
            if (rangeBoundaries.Min[0] == '-' && rangeBoundaries.Min[1] == ' ')
            {
                rangeBoundaries.Min = rangeBoundaries.Min.Remove(1, 1);
            }
            if (rangeBoundaries.Max[0] == '-' && rangeBoundaries.Max[1] == ' ')
            {
                rangeBoundaries.Max = rangeBoundaries.Max.Remove(1, 1);
            }

            if (sensor is BoundedSensor <int> s)
            {
                s.Boundaries = new RangeBoundaries <int>
                               (
                    int.Parse(rangeBoundaries.Min),
                    int.Parse(rangeBoundaries.Max)
                               );
            }
            else if (sensor is BoundedSensor <float> s2)
            {
                s2.Boundaries = new RangeBoundaries <float>
                                (
                    float.Parse(rangeBoundaries.Min),
                    float.Parse(rangeBoundaries.Max)
                                );
            }
            else if (sensor is BoundedSensor <double> s3)
            {
                s3.Boundaries = new RangeBoundaries <double>
                                (
                    double.Parse(rangeBoundaries.Min),
                    double.Parse(rangeBoundaries.Max)
                                );
            }
        }
예제 #5
0
 /// <summary> Initializes a new instance of the <see cref="MathInterval" /> class. </summary>
 /// <param name="min"> The minimum. </param>
 /// <param name="max"> The maximum. </param>
 /// <param name="type"> The type of boundaries. </param>
 public MathInterval(double min, double max, RangeBoundaries type = RangeBoundaries.InIn) : base(min, max, type)
 {
 }