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); } } } } }