コード例 #1
0
        private void ParseInterfaces(XElement configNode)
        {
            var physicalInterfaces = configNode.XPathSelectElements("./interfaces/interface");

            foreach (var physicalInterface in physicalInterfaces)
            {
                // For a valid interface there should be at least one IP address node...
                if (physicalInterface.XPathSelectElement("./unit/family/inet/address/name") == null)
                {
                    continue;
                }

                // Use a temporary object to parse a name from the parent physical interface node.
                var tempObject = new JuniperObject();
                tempObject.Parse(physicalInterface, null);

                var logicalInterfaces = physicalInterface.Elements("unit");
                foreach (var logicalInterface in logicalInterfaces)
                {
                    JuniperObject juniperInterface = new Juniper_Interface();
                    juniperInterface.Parse(logicalInterface, null);
                    juniperInterface.Name = string.Format("{0}.{1}", tempObject.Name, juniperInterface.Name);
                    _juniperObjects.Add(juniperInterface);
                }
            }
        }
コード例 #2
0
        private void ParseApplication(XElement application)
        {
            JuniperObject juniperObject;

            var terms = application.Elements("term").ToList();

            if (terms.Count > 0)
            {
                // Use a temporary object to parse name and description from the parent application node.
                var termApplicationObject = new JuniperObject();
                termApplicationObject.Parse(application, null);

                if (terms.Count > 1)
                {
                    // Create a group only for multiple terms!!!
                    var members = new List <string>();

                    foreach (var term in terms)
                    {
                        juniperObject = new Juniper_Application {
                            LineNumber = ((IXmlLineInfo)term).LineNumber
                        };
                        ((Juniper_Application)juniperObject).IsJunosDefault = termApplicationObject.Name.StartsWith("junos-");   // must come before parsing!!!
                        ((Juniper_Application)juniperObject).ParseFromTerm(term, true);
                        _juniperObjects.Add(juniperObject);

                        members.Add(juniperObject.Name);
                    }

                    juniperObject = new Juniper_ApplicationGroup
                    {
                        Name        = termApplicationObject.Name,
                        Description = termApplicationObject.Description,
                        LineNumber  = termApplicationObject.LineNumber,
                    };

                    ((Juniper_ApplicationGroup)juniperObject).IsJunosDefault = termApplicationObject.Name.StartsWith("junos-");
                    ((Juniper_ApplicationGroup)juniperObject).Members.AddRange(members);   // add the members manually
                    _juniperObjects.Add(juniperObject);
                }
                else
                {
                    juniperObject = new Juniper_Application
                    {
                        Name        = termApplicationObject.Name,
                        Description = termApplicationObject.Description,
                        LineNumber  = termApplicationObject.LineNumber
                    };

                    ((Juniper_Application)juniperObject).IsJunosDefault = termApplicationObject.Name.StartsWith("junos-");   // must come before parsing!!!
                    ((Juniper_Application)juniperObject).ParseFromTerm(terms[0], false);
                    _juniperObjects.Add(juniperObject);
                }
            }
            else
            {
                juniperObject = new Juniper_Application();
                juniperObject.Parse(application, null);
                _juniperObjects.Add(juniperObject);
            }
        }