private void SaveButton_Click(object sender, EventArgs e) { TreeNode node = SitesTreeView.SelectedNode; Action act = null; if (node.Tag is EventGenerator) { DetectionSystem eventWatcher = (DetectionSystem)node.Parent.Tag; EventGenerator eg = (EventGenerator)node.Tag; if (eg.Name != NameTextBox.Text && siteMan.ContainsName(NameTextBox.Text)) { MessageBox.Show("All items in the Site Manager and Event Manager require a unique name!"); return; } if (!ParamListPanel.ValidateInput()) { return; } EventGeneratorHookup hookup = EventGenerator.GetHookup(eg.GetEventGeneratorType()); int index = 0; List <EventGenerator> egs = (eg.Parent as DetectionSystem).GetEventGenerators(); for (int i = 0; i < egs.Count; i++) { if (eg.ID == egs[i].ID) { index = i; break; } } eg.Delete(); eg = hookup.FromParameters(eventWatcher, NameTextBox.Text, ParamListPanel.Parameters, eg.ID); eg.SetIndex(index); foreach (Action action in eg.GetActions()) { if (action.Name == ActionsComboBox.Text) { SaveAction(eg, action); act = action; break; } } siteMan.Save(); UpdateSitesTree(); siteManChanged = true; SitesTreeView.SelectedNode = SitesTreeView.Nodes.Find(eg.Name, true)[0]; if (act != null) { ActionsComboBox.Text = act.Name; } } }
private void AddButton_Click(object sender, EventArgs e) { EventTypeDialog dialog = new EventTypeDialog(); DialogResult result = dialog.ShowDialog(); if (result == DialogResult.Cancel) { return; } TreeNode node = SitesTreeView.SelectedNode; DetectionSystem eventWatcher; int insertIndex = -1; if (node.Tag is DetectionSystem) { eventWatcher = (DetectionSystem)node.Tag; } else { eventWatcher = (DetectionSystem)node.Parent.Tag; insertIndex = eventWatcher.GetEventGenerators().IndexOf((EventGenerator)node.Tag) + 1; } EventGeneratorHookup hookup = EventGenerator.GetHookup(dialog.eventType); string name = ""; bool uniqueName = false; int iteration = 0; while (!uniqueName) { iteration++; name = "New-" + hookup.Type + "-" + iteration.ToString(); uniqueName = !siteMan.ContainsName(name); } List <string> validSystemChannels = new List <string>(); foreach (Instrument inst in ((DetectionSystem)eventWatcher).GetInstruments()) { foreach (Channel chan in inst.GetChannels()) { validSystemChannels.Add(chan.Name); } } List <string> validEGs = new List <string>(); foreach (EventGenerator otherEG in eventWatcher.GetEventGenerators()) { validEGs.Add(otherEG.Name); } List <Parameter> parameters = new List <Parameter>(); foreach (ParameterTemplate paramTemp in hookup.TemplateParameters) { switch (paramTemp.Type) { case ParameterType.Double: parameters.Add(new DoubleParameter(paramTemp.Name) { Value = "0" }); break; case ParameterType.Enum: parameters.Add(new EnumParameter(paramTemp.Name) { Value = paramTemp.ValidValues[0], ValidValues = paramTemp.ValidValues }); break; case ParameterType.SystemChannel: if (validSystemChannels.Count == 0) { MessageBox.Show("No channels to watch in this system!"); return; } parameters.Add(new SystemChannelParameter(paramTemp.Name, (DetectionSystem)eventWatcher) { Value = validSystemChannels[0], ValidValues = validSystemChannels }); break; case ParameterType.SystemEventGenerator: if (validEGs.Count == 0) { MessageBox.Show("No event generators to watch in this system!"); return; } parameters.Add(new SystemEventGeneratorParameter(paramTemp.Name, (DetectionSystem)eventWatcher) { Value = validEGs[0], ValidValues = validEGs }); break; case ParameterType.TimeSpan: parameters.Add(new TimeSpanParameter(paramTemp.Name) { Value = "0" }); break; } } EventGenerator eg = hookup.FromParameters(eventWatcher, name, parameters, 0); siteMan.Save(); UpdateSitesTree(); siteManChanged = true; SitesTreeView.SelectedNode = SitesTreeView.Nodes.Find(eg.Name, true)[0]; }