コード例 #1
0
        private void LoadDefaultApplicationsAndGroups()
        {
            var applicationsAndGroupsDoc = XDocument.Load("junos-defaults.xml", LoadOptions.SetLineInfo);

            if (applicationsAndGroupsDoc.Root == null)
            {
                throw new ApplicationException("Cannot find Juniper default applications file 'junos-defaults.xml'.");
            }

            // The "applications" element is an inner element and NOT a direct child...
            // Just grab the first and only item from the results list.
            var applicationsNode = applicationsAndGroupsDoc.Root.Descendants("applications").ToList()[0];

            if (applicationsNode == null)
            {
                throw new InvalidDataException("Invalid XML structure: default 'applications' element is missing.");
            }

            var applications = applicationsNode.Elements("application");

            foreach (var application in applications)
            {
                ParseApplication(application);
            }

            var groups = applicationsNode.Elements("application-set");

            foreach (var group in groups)
            {
                JuniperObject juniperApplicationGroup = new Juniper_ApplicationGroup();
                juniperApplicationGroup.Parse(group, null);
                _juniperObjects.Add(juniperApplicationGroup);
            }
        }
コード例 #2
0
        private void ParseApplicationsAndGroups(XElement configNode)
        {
            var applications = configNode.XPathSelectElements("./applications/application");

            foreach (var application in applications)
            {
                ParseApplication(application);
            }

            var applicationGroups = configNode.XPathSelectElements("./applications/application-set");

            foreach (var group in applicationGroups)
            {
                JuniperObject juniperApplicationGroup = new Juniper_ApplicationGroup();
                juniperApplicationGroup.Parse(group, null);
                _juniperObjects.Add(juniperApplicationGroup);
            }
        }
コード例 #3
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);
            }
        }