Esempio n. 1
0
        public XmlNode exportXMLnode()
        {
            XmlDocument   xmlDoc        = new XmlDocument();
            StringWriter  stringWriter  = new StringWriter();
            XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
            XmlNode       rootNode      = null;

            if (isNodeComment)
            {
                rootNode = xmlDoc.CreateComment(comment);
                xmlDoc.AppendChild(rootNode);

                return(rootNode);
            }

            rootNode = xmlDoc.CreateElement(mType.ToString());
            xmlDoc.AppendChild(rootNode);

            foreach (string attr in arrAttributes)
            {
                XmlAttribute attrName = xmlDoc.CreateAttribute(attr);
                attrName.Value = (string)this.GetType().GetProperty(attr).GetValue(this);
                rootNode.Attributes.Append(attrName);
            }

            foreach (IED iedn in iedList)
            {
                XmlNode importNode = rootNode.OwnerDocument.ImportNode(iedn.exportXMLnode(), true);
                rootNode.AppendChild(importNode);
            }
            return(rootNode);
        }
        private void btnImportIED_Click(object sender, EventArgs e)
        {
            string strRoutineName = "btnImportIED_Click";

            try
            {
                if (ofdXMLFile.ShowDialog() == DialogResult.OK)
                {
                    Utils.WriteLine(VerboseLevel.DEBUG, "*** Opening file: {0}", ofdXMLFile.FileName);
                    if (!Utils.IsXMLWellFormed(ofdXMLFile.FileName))
                    {
                        MessageBox.Show("Selected file is not a valid XML!!!.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(ofdXMLFile.FileName);
                    XmlNodeList nodeList = xmlDoc.SelectNodes("IEDexport");
                    Utils.WriteLine(VerboseLevel.BOMBARD, "nodeList count: {0}", nodeList.Count);
                    if (nodeList.Count <= 0)
                    {
                        MessageBox.Show("Selected file is not an IED exported node.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    XmlNode rootNode = nodeList.Item(0);
                    Utils.WriteLine(VerboseLevel.DEBUG, "*** Exported IED Node name: {0}", rootNode.Name);
                    if (rootNode.Attributes != null)
                    {
                        foreach (XmlAttribute item in rootNode.Attributes)
                        {
                            Utils.Write(VerboseLevel.DEBUG, "{0} {1} ", item.Name, item.Value);
                            if (item.Name == "MasterType")
                            {
                                if (item.Value != mType.ToString())
                                {
                                    MessageBox.Show("Invalid Master Type (" + item.Value + ") to import!!!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    return;
                                }
                            }
                        }
                    }
                    foreach (XmlNode node in rootNode)
                    {
                        Utils.WriteLine(VerboseLevel.BOMBARD, "node value: '{0}' child count {1}", node.Name, node.ChildNodes.Count);
                        if (node.Name == "IED")
                        {
                            if (node.NodeType == XmlNodeType.Comment)
                            {
                                continue;                                      //IMP: Ignore comments in file...
                            }
                            TreeNode tmp = IEC101TreeNode.Nodes.Add("IED_" + Utils.GenerateShortUniqueKey(), "IED", "IED", "IED");
                            iedList.Add(new IED(node, tmp, MasterTypes.IEC101, Int32.Parse(MasterNum), true));
                            Utils.CreateDI4IED(MasterTypes.IEC101, Int32.Parse(MasterNum), Int32.Parse(iedList[iedList.Count - 1].UnitID), iedList[iedList.Count - 1].Device);
                            tmp.Expand();
                        }
                    }
                    refreshList();
                    MessageBox.Show("IED imported successfully!!!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(strRoutineName + ": " + "Error: " + ex.Message.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }