Exemplo n.º 1
0
        static private void readStaticSection(XmlReader r, AlarmDefinitionList alarms)
        {
            if (!r.ReadToDescendant("Member"))
            {
                return;
            }

            string name = r.GetAttribute("Name");

            if (name != "Props")
            {
                throw new XmlException("No Props member found");
            }
            string type  = r.GetAttribute("Datatype");
            Match  match = Regex.Match(type, "^Array\\[\\d+..(\\d+)\\] of");

            if (match.Success)
            {
                int last = int.Parse(match.Groups[1].Value);
                Console.WriteLine("Last index {0}", last);
                AlarmDefinition[] array = new AlarmDefinition[last];
                for (int i = 0; i < last; i++)
                {
                    array[i]    = new AlarmDefinition(null, null);
                    array[i].ID = i + 1;
                }
                if (!r.ReadToDescendant("Member"))
                {
                    throw new XmlException("Member not found");
                }
                do
                {
                    string member_name = r.GetAttribute("Name");
                    string member_type = r.GetAttribute("Datatype");
                    if (member_name == "Silent" && member_type == "Bool")
                    {
                        readSilentMember(r.ReadSubtree(), array);
                    }
                    else if (member_name == "AutoAck" && member_type == "Bool")
                    {
                        readAutoAckMember(r.ReadSubtree(), array);
                    }
                    else if (member_name == "Text" && member_type.StartsWith("String["))
                    {
                        readTextMember(r.ReadSubtree(), array);
                    }
                } while (r.ReadToNextSibling("Member"));
                alarms.Clear();
                alarms.AddRange(array);
            }
        }
Exemplo n.º 2
0
        private void extractAlarmDefsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tiaPortal != null)
            {
                if (data_block_dialog == null)
                {
                    data_block_dialog         = new BrowseDialog(tiaPortal);
                    data_block_dialog.Descend = TIATree.ControllerOnly;
                    data_block_dialog.Leaf    = TIATree.SharedDBOnly;
                    data_block_dialog.AutoExpandMaxChildren = 1;
                    data_block_dialog.AcceptText            = "Extract";
                    data_block_dialog.Text = "Select alarm data block";
                }
                if (data_block_dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    if (data_block_dialog.SelectedObject is DataBlock)
                    {
                        DataBlock block = (DataBlock)data_block_dialog.SelectedObject;
                        try
                        {
                            // Extract from data base
                            string filename = TempFile.Name("AlarmDB", "xml");

                            block.Export(filename, ExportOptions.WithDefaults | ExportOptions.WithReadOnly);
                            alarmList.DataSource = null;
                            AlarmDB.parseFile(defs, filename);
                            System.IO.File.Delete(filename);

                            // Extract from constant tags
                            // Move up the tree until we find a ControllerTarget
                            IEngineeringObject obj = (block as IEngineeringObject).Parent;
                            while (!(obj is ControllerTarget))
                            {
                                obj = obj.Parent;
                                // Shouldn't happen, but just in case
                                if (obj == null)
                                {
                                    MessageBox.Show(this, "No controller found as parent");
                                    return;
                                }
                            }
                            ControllerTarget           controller = (ControllerTarget)obj;
                            List <ConstTable.Constant> consts     = new List <ConstTable.Constant>();

                            ControllerTagTable table = controller.ControllerTagFolder.TagTables.Find("Alarms");
                            if (table == null)
                            {
                                MessageBox.Show(this, "No tag table named Alarms was found");
                            }
                            else
                            {
                                filename = TempFile.Name("ConstantTags", "xml");
                                Console.WriteLine("Wrote to " + filename);
                                table.Export(filename, ExportOptions.WithDefaults | ExportOptions.WithReadOnly);
                                List <ConstTable.Constant> constants = ConstTable.getConstants(filename);
                                foreach (ConstTable.Constant c in constants)
                                {
                                    if (c.Name.StartsWith("Alarm") && c.Value is int)
                                    {
                                        AlarmDefinition a = defs.FindByID((int)c.Value);
                                        if (a != null)
                                        {
                                            a.Name = c.Name.Substring(5);
                                        }
                                    }
                                }
                            }
                            defs.ValidateID();

                            alarmList.AutoGenerateColumns = false;
                            alarmList.DataSource          = defs;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Failed to extract alarm definitions: " + ex.Message);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private static void readStaticSection(XmlReader r, AlarmDefinitionList alarms)
        {
            if (!r.ReadToDescendant("Member")) return;

            string name = r.GetAttribute("Name");
            if (name != "Props") throw new XmlException("No Props member found");
            string type = r.GetAttribute("Datatype");
            Match match = Regex.Match(type,"^Array\\[\\d+..(\\d+)\\] of");
            if (match.Success)
            {
                int last = int.Parse(match.Groups[1].Value);
                Console.WriteLine("Last index {0}", last);
                AlarmDefinition[] array = new AlarmDefinition[last];
                for (int i = 0; i < last; i++)
                {
                    array[i] = new AlarmDefinition(null, null);
                    array[i].ID = i + 1;
                }
                    if (!r.ReadToDescendant("Member")) throw new XmlException("Member not found");
                do
                {
                    string member_name = r.GetAttribute("Name");
                    string member_type = r.GetAttribute("Datatype");
                    if (member_name == "Silent" && member_type == "Bool")
                    {
                        readSilentMember(r.ReadSubtree(), array);
                    }
                    else if (member_name == "AutoAck" && member_type == "Bool")
                    {
                        readAutoAckMember(r.ReadSubtree(), array);
                    }
                    else if (member_name == "Text" && member_type.StartsWith("String["))
                    {
                        readTextMember(r.ReadSubtree(), array);
                    }
                } while (r.ReadToNextSibling("Member"));
                alarms.Clear();
                alarms.AddRange(array);
            }
        }
Exemplo n.º 4
0
 static void readTextMember(XmlReader r, AlarmDefinition[] array)
 {
     if (!r.ReadToDescendant("StartValue")) return;
     while (r.IsStartElement())
     {
         int index = int.Parse(r.GetAttribute("Path"));
         if (index >= 1 && index <= array.Length)
         {
             string text = r.ReadElementContentAsString("StartValue", InterfaceNS);
             array[index - 1].Text = text.Substring(1, text.Length - 2); // Remove quotes
         }
         else
         {
             r.ReadToNextSibling("StartValue");
         }
     }
 }
Exemplo n.º 5
0
        static void readSilentMember(XmlReader r, AlarmDefinition[] array)
        {
            if (!r.ReadToDescendant("StartValue")) return;
            while (r.IsStartElement())
            {
                int index = int.Parse(r.GetAttribute("Path"));
                if (index >= 1 && index <= array.Length)
                {
                    string value = r.ReadElementContentAsString("StartValue", InterfaceNS);

                    array[index - 1].Options |= (value.Contains("TRUE") || value.Contains("true")) ? AlarmDefinition.Option.Silent : 0;
                }
                else
                {
                    r.ReadToNextSibling("StartValue");
                }
            }
        }