Esempio n. 1
0
        public void SetSensorTest()
        {
            var ls = new ListedSensor(_sensor1, _ds);

            ls.Sensor = _sensor2;
            Assert.AreEqual(ls.Sensor.Name, "DO");

            ls.Sensor = _sensor1;
            Assert.AreEqual(ls.Sensor.Name, "Temperature");
        }
Esempio n. 2
0
 public void NullSensorTest()
 {
     var ls = new ListedSensor(_sensor1, _ds);
     ls.Sensor = null;
 }
Esempio n. 3
0
        public void SetDatasetTest()
        {
            var ls = new ListedSensor(_sensor1, _ds);

            ls.Dataset = _ds2;
            Assert.AreEqual(ls.Dataset, _ds2);

            ls.Dataset = _ds;
            Assert.AreEqual(ls.Dataset, _ds);
        }
Esempio n. 4
0
 public void NullConstructSensorTest()
 {
     var ls = new ListedSensor(null, _ds);
 }
Esempio n. 5
0
 public void NullDatasetTest()
 {
     var ls = new ListedSensor(_sensor1, _ds);
     ls.Dataset = null;
 }
Esempio n. 6
0
 public void NullConstructDatasetTest()
 {
     var ls = new ListedSensor(_sensor1, null);
 }
Esempio n. 7
0
        public void GetDatasetTest()
        {
            var ls = new ListedSensor(_sensor1, _ds);
            Assert.AreEqual(ls.Dataset, _ds);

            var nls = new ListedSensor(_sensor1, _ds2);
            Assert.AreEqual(nls.Dataset, _ds2);
        }
Esempio n. 8
0
        public void StartSensorDrag(SelectionChangedEventArgs e)
        {
            if (isDragging)
                return;

            // This handles the fact that, when you click and drag, this event *only* fires
            // when a *new* item is selected. We want the one from before - hence the
            // use of RemovedItems.

            _sensorAtStartOfDrag = (e.RemovedItems.Count == 1) ? (ListedSensor)e.RemovedItems[0] : (ListedSensor)e.AddedItems[0];

            isDragging = true;
        }
Esempio n. 9
0
        public void EndSensorDrag(MouseEventArgs e)
        {
            if (movedMouseWhileDragging)
            {
                isDragging = false;
                var sensorAtEndOfDrag = SelectedItem;

                if(sensorAtEndOfDrag != null && _sensorAtStartOfDrag != null && !sensorAtEndOfDrag.Sensor.Equals(_sensorAtStartOfDrag.Sensor))
                {
                    // Move it into place
                    _ds.MoveSensorTo(_sensorAtStartOfDrag.Sensor, sensorAtEndOfDrag.Sensor);
                    SelectedItem = _sensorAtStartOfDrag;

                    // TODO: must be more efficient way of doing this? Just NotifyPropertyChanged() didn't work
                    var tmpList = AllSensors;
                    AllSensors = new List<ListedSensor>();
                    AllSensors = tmpList;
                }
            }

            _sensorAtStartOfDrag = null;
            movedMouseWhileDragging = false;
            isDragging = false;
            ViewCursor = Cursors.Arrow;
        }
Esempio n. 10
0
        public void btnSave()
        {
            if(SelectedItem == null)
            {
                // New sensor
                try
                {
                    // TODO: more user-friendly conversion messages!
                    var s = new Sensor(Name, Description, float.Parse(UpperLimit), float.Parse(LowerLimit), Unit, float.Parse(MaximumRateOfChange), new Stack<SensorState>(), new Stack<SensorState>(), new List<Calibration>(), int.Parse(ErrorThreshold), _ds, (SummaryType)SummaryType) { Elevation = float.Parse(Depth)};

                    if(Dataset.Sensors == null)
                        Dataset.Sensors = new List<Sensor>();

                    Dataset.Sensors.Add(s);
                    SelectedItem = new ListedSensor(s, _ds);

                    EventLogger.LogInfo(_ds, GetType().ToString(), "Created new sensor. Sensor name: " + s.Name);
                    Common.ShowMessageBox("New sensor created", "The new sensor '" + Name + "' was added successfully.",
                                          false, false);
                    endEditing();
                }
                catch (Exception e)
                {
                    Common.ShowMessageBox("Format Error", e.Message, false, true);
                    EventLogger.LogWarning(_ds, GetType().ToString(), "Attempted to create new sensor, but failed. Details: " + e.Message);
                }
            }
            else
            {
                // Existing sensor
                try
                {
                    SelectedItem.Sensor.Name = Name;
                    SelectedItem.Sensor.Description = Description;
                    SelectedItem.Sensor.Elevation = float.Parse(Depth);
                    SelectedItem.Sensor.UpperLimit = float.Parse(UpperLimit);
                    SelectedItem.Sensor.LowerLimit = float.Parse(LowerLimit);
                    SelectedItem.Sensor.Unit = Unit;
                    SelectedItem.Sensor.MaxRateOfChange = float.Parse(MaximumRateOfChange);
                    SelectedItem.Sensor.ErrorThreshold = int.Parse(ErrorThreshold);
                    SelectedItem.Sensor.SummaryType = (SummaryType)SummaryType;
                    EventLogger.LogInfo(_ds, GetType().ToString(), "Saved existing sensor. Sensor name: " + Name);
                    endEditing();
                }
                catch (Exception e)
                {
                    Common.ShowMessageBox("An Error Occured", e.Message, false, true);
                    EventLogger.LogWarning(_ds, GetType().ToString(), "Attempted to save existing sensor, but failed. Details: " + e.Message);
                }
            }
        }