public void ExportsTwoPresetsCorrectly() { var templates = new List <SensorTemplate> { new SensorTemplate(UNIT, UPPER_LIMIT, LOWER_LIMIT, MAX_CHANGE, SensorTemplate.MatchStyle.Contains, "Temp"), new SensorTemplate("Q", 1000, 700, 7, SensorTemplate.MatchStyle.StartsWith, "Humid") }; SensorTemplate.ExportAll(templates); Assert.AreEqual(SensorTemplateDualXML, File.ReadAllText(SensorTemplate.ExportPath)); }
public void ExportsOnePresetCorrectly() { var templates = new List <SensorTemplate> { new SensorTemplate(UNIT, UPPER_LIMIT, LOWER_LIMIT, MAX_CHANGE, SensorTemplate.MatchStyle.Contains, "Temp") }; SensorTemplate.ExportAll(templates); Assert.AreEqual(SensorTemplateSingleXML, File.ReadAllText(SensorTemplate.ExportPath)); }
public void btnDelete() { if (SelectedTemplate != null && Common.Confirm("Delete Preset", "Are you sure you want to permanently delete this preset?")) { var list = AllTemplates; list.Remove(SelectedTemplate); SensorTemplate.ExportAll(list); AllTemplates = new List <SensorTemplate>(); AllTemplates = list; Common.ShowMessageBox("Delete Preset", "Preset successfully deleted.", false, false); } }
public void btnSave() { try { var msg = ""; var template = new SensorTemplate(Unit, UpperLimit, LowerLimit, MaximumRateOfChange, (SensorTemplate.MatchStyle)Enum.Parse(typeof(SensorTemplate.MatchStyle), (MatchMode).ToString()), TextToMatch, _sType); // Construct object to prevent inconsistent state if updating (when setting properties and some are invalid) var list = AllTemplates; // To trigger update if (SelectedTemplate == null) { // New list.Add(template); AllTemplates = list; foreach (var sensor in _sensors) { foreach (var sensorTemplate in list) { if (sensorTemplate.Matches(sensor.Sensor)) { sensorTemplate.ProvideDefaultValues(sensor.Sensor); } } } msg = "Sensor preset successfully created."; } else { // Update list[list.IndexOf(SelectedTemplate)] = template; SelectedTemplate = template; AllTemplates = list; foreach (var sensor in _sensors) { foreach (var sensorTemplate in list) { if (sensorTemplate.Matches(sensor.Sensor)) { sensorTemplate.ProvideDefaultValues(sensor.Sensor); } } } msg = "Sensor preset successfully updated."; } SensorTemplate.ExportAll(AllTemplates); Common.ShowMessageBox("Presets", msg, false, false); Editing = false; SelectedTemplate = null; AllTemplates = new List <SensorTemplate>(); // To force update! AllTemplates = list; } catch (Exception e) { Common.ShowMessageBox("Error", e.Message, false, true); } }