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"); }
public void NullSensorTest() { var ls = new ListedSensor(_sensor1, _ds); ls.Sensor = null; }
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); }
public void NullConstructSensorTest() { var ls = new ListedSensor(null, _ds); }
public void NullDatasetTest() { var ls = new ListedSensor(_sensor1, _ds); ls.Dataset = null; }
public void NullConstructDatasetTest() { var ls = new ListedSensor(_sensor1, null); }
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); }
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; }
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; }
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); } } }