Beispiel #1
0
 public override bool SetIndex(int index)
 {
     eventWatcher.GetEventGenerators().Remove(this);
     eventWatcher.GetEventGenerators().Insert(index, this);
     eventWatcher.Children.Remove(this);
     eventWatcher.Children.Insert(index + eventWatcher.GetInstruments().Count, this);
     return(true);
 }
Beispiel #2
0
        public EventGenerator(DetectionSystem parent, string name, uint id) : base(parent, name, id)
        {
            parent.GetEventGenerators().Add(this);

            eventWatcher = parent;
            events       = new List <Event>();
            actions      = new List <Action>();
        }
Beispiel #3
0
 public SystemEventGeneratorParameter(string name, DetectionSystem system) : base(name, ParameterType.SystemEventGenerator)
 {
     System      = system;
     ValidValues = new List <string>();
     foreach (EventGenerator eg in System.GetEventGenerators())
     {
         ValidValues.Add(eg.Name);
     }
 }
Beispiel #4
0
        private void DownButton_Click(object sender, EventArgs e)
        {
            TreeNode node = SitesTreeView.SelectedNode;

            if (node.Tag is EventGenerator)
            {
                EventGenerator  eg           = (EventGenerator)node.Tag;
                DetectionSystem eventWatcher = (DetectionSystem)node.Parent.Tag;
                int             index        = eventWatcher.GetEventGenerators().IndexOf(eg);
                if (index < eventWatcher.GetEventGenerators().Count - 1)
                {
                    eg.SetIndex(index + 1);

                    siteMan.Save();
                    UpdateSitesTree();
                    siteManChanged             = true;
                    SitesTreeView.SelectedNode = SitesTreeView.Nodes.Find(eg.Name, true)[0];
                }
            }
        }
Beispiel #5
0
        private void RemoveButton_Click(object sender, EventArgs e)
        {
            TreeNode     node         = SitesTreeView.SelectedNode;
            DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete " + node.Text + "?", "Delete Item", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.No)
            {
                return;
            }

            if (node.Tag is Site)
            {
                Site site = (Site)node.Tag;
                site.Delete();
                // G - Turn off other buttons if there are no longer any sites
                if (siteMan.GetSites().Count == 0)
                {
                    DisableButtons();
                }
            }
            else if (node.Tag is Facility)
            {
                Facility fac = (Facility)node.Tag;
                fac.Delete();
            }
            else if (node.Tag is DetectionSystem)
            {
                DetectionSystem sys = (DetectionSystem)node.Tag;
                sys.Delete();
            }
            else if (node.Tag is Instrument)
            {
                Instrument inst = (Instrument)node.Tag;
                inst.Delete();
            }
            else if (node.Tag is EventGenerator)
            {
                EventGenerator  eg  = (EventGenerator)node.Tag;
                DetectionSystem sys = (DetectionSystem)node.Parent.Tag;
                sys.GetEventGenerators().Remove(eg);
            }

            siteMan.Save();
            UpdateSitesTree();
            siteManChanged = true;

            // G - Select new node after deleting
            SitesTreeView.SelectedNode = SitesTreeView.TopNode;
        }
Beispiel #6
0
 public ReturnCode LoadFromXML(string fileName)
 {
     if (!File.Exists(fileName))
     {
         return(ReturnCode.FILE_DOESNT_EXIST);
     }
     try
     {
         XmlDocument doc = new XmlDocument();
         doc.Load(fileName);
         presets.Clear();
         foreach (XmlNode presetNode in doc.DocumentElement.ChildNodes)
         {
             Preset newPreset = new Preset(presetNode.Attributes["name"]?.InnerText);
             foreach (XmlNode siteNode in presetNode.ChildNodes)
             {
                 Site site = siteMan.GetSites().Single(s => s.Name == siteNode.Attributes["name"]?.InnerText);
                 foreach (XmlNode facilityNode in siteNode.ChildNodes)
                 {
                     Facility fac = site.GetFacilities().Single(s => s.Name == facilityNode.Attributes["name"]?.InnerText);
                     foreach (XmlNode systemNode in facilityNode.ChildNodes)
                     {
                         DetectionSystem sys = fac.GetSystems().Single(s => s.Name == systemNode.Attributes["name"]?.InnerText);
                         foreach (XmlNode instrumentNode in systemNode.ChildNodes)
                         {
                             if (instrumentNode.Name == "Instrument")
                             {
                                 Instrument inst = sys.GetInstruments().Single(i => i.Name == instrumentNode.Attributes["name"]?.InnerText);
                                 if (instrumentNode.Attributes["checked"] != null)
                                 {
                                     if (instrumentNode.Attributes["checked"].InnerText == "true")
                                     {
                                         newPreset.GetActiveInstruments().Add(inst);
                                         foreach (XmlNode chanNode in instrumentNode.ChildNodes)
                                         {
                                             Channel chan = inst.GetChannels().Single(c => c.Name == chanNode.Attributes["name"]?.InnerText);
                                             foreach (XmlNode checkNode in chanNode.ChildNodes)
                                             {
                                                 if (checkNode.Attributes["checked"] != null)
                                                 {
                                                     if (checkNode.Attributes["checked"].InnerText == "true")
                                                     {
                                                         newPreset.AddChannel(chan, int.Parse(checkNode.Attributes["chart"].InnerText));
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                             else if (instrumentNode.Name == "EventGenerator")
                             {
                                 XmlNode        eventGenNode   = instrumentNode;
                                 EventGenerator eventGenerator = sys.GetEventGenerators().Single(e => e.Name == eventGenNode.Attributes["name"]?.InnerText);
                                 if (eventGenNode.Attributes["checked"].InnerText == "true")
                                 {
                                     newPreset.GetActiveEventGenerators().Add(eventGenerator);
                                 }
                             }
                             else
                             {
                                 return(ReturnCode.CORRUPTED_FILE);
                             }
                         }
                     }
                 }
             }
             presets.Add(newPreset);
         }
     }
     catch
     {
         return(ReturnCode.FAIL);
     }
     return(ReturnCode.SUCCESS);
 }