示例#1
0
 public static void createProtocol(TreeView tree)
 {
     TreeNodeCollection treeCol = tree.Nodes;
     Protocol prot = new Protocol(treeCol[0].Text, treeCol[0].ImageKey, treeCol[0].SelectedImageKey);
     Block data = null;
     foreach (TreeNode t in treeCol[0].Nodes)
     {
         if (t.Name.Equals("block"))
         {
             data = prot.createBlock(t.Text, t.ImageKey, t.SelectedImageKey);
             createProtocol(t.Nodes, data);
         }
         else
         {
             if(t.Name.Equals("multi"))
             {
             Field f = prot.createField(t.Text, t.Name,  "", t.SelectedImageKey);
             string[] values = t.ImageKey.Split(';');
             foreach(string s in values)
                 {
                     string[] pair = s.Split(':');
                     ((MultiField)f).addKey(pair[0], pair[1]);
                 }
            } else prot.createField(t.Text, t.Name, t.ImageKey, t.SelectedImageKey);
         }
     }
     createXML(prot);
 }
示例#2
0
        public Protocol parse(String path)
        {
            // parse protocol attributes
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(path);

            Protocol protocol = null;
            XmlNodeList protocolNode = xmlDoc.DocumentElement.SelectNodes("/protocol");

            // parsing protocol attributes
            if (protocolNode != null)
            {
                string protoName = null, protoSource = null, protoDescription = null;
                foreach (XmlNode node in protocolNode)
                {

                    if (node.Attributes["name"] != null)
                    {
                        protoName = node.Attributes["name"].Value;
                    }
                    if (node.Attributes["source"] != null)
                    {
                        protoSource = node.Attributes["source"].Value;
                    }
                    if (node.Attributes["description"] != null)
                    {
                        protoDescription = node.Attributes["description"].Value;
                    }

                }

                //creating new protocol instance
                 protocol = new Protocol(protoName, protoSource, protoDescription);

                //getting all the blo
                XmlNodeList nodes = xmlDoc.DocumentElement.SelectNodes("/protocol/block|/protocol/field");

                //going over all the nodes and creating their instances
                foreach (XmlNode node in nodes)
                {
                    if (node.Name == "block")
                    {
                        String[] attr = getBlockAttr(node);
                        String name = attr[0];
                        String type = attr[1];
                        String info = attr[2];

                        Block block = protocol.createBlock(name, type, info);
                        innerBlocks(block, node.ChildNodes);
                    }
                    else if (node.Name == "field")
                    {
                        String[] attr = getFieldAttr(node);
                        String name = attr[0];
                        String type = attr[1];
                        String info = attr[2];
                        String description = attr[3];

                        Field field = protocol.createField(name, type, info, description);
                        if (node.ChildNodes != null)
                        {
                            innerFields(field, node.ChildNodes);
                        }
                    }
                }

            }
            return protocol;
        }