Exemplo n.º 1
0
        public MibTree(MibModule module)
        {
            IList <IEntity> entities = module.Entities;

            if (entities.Count > 0)
            {
                // try to find module identity as root
                foreach (IEntity element in entities)
                {
                    ModuleIdentity mi = element as ModuleIdentity;

                    if (mi != null)
                    {
                        _root.Add(new MibTreeNode(null, mi));
                    }
                }

                // gather all items below ModuleIdentity
                foreach (MibTreeNode mibTreeNode in _root)
                {
                    entities.Remove(mibTreeNode.Entity);
                    BuildTree(mibTreeNode, entities);
                    UpdateTreeNodeTypes(mibTreeNode);
                }

                // find OID assignments as root, if there are any that are not below ModuleIdentity
                // FIXME: There may be multiple OID assignments that create a tree (find the root ones!)
                foreach (IEntity element in entities)
                {
                    OidValueAssignment oa = element as OidValueAssignment;

                    if (oa != null)
                    {
                        _root.Add(new MibTreeNode(null, oa));
                    }
                }

                if (_root.Count == 0)
                {
                    //no module identity, assume first entity is root
                    _root.Add(new MibTreeNode(null, entities[0]));
                }

                foreach (MibTreeNode mibTreeNode in _root)
                {
                    if (entities.Contains(mibTreeNode.Entity))
                    {
                        entities.Remove(mibTreeNode.Entity);
                    }
                    BuildTree(mibTreeNode, entities);
                    UpdateTreeNodeTypes(mibTreeNode);
                }
            }
        }
Exemplo n.º 2
0
        private Definition CreateExtraNodes(string module, string longParent)
        {
            string[]   content = longParent.Split('.');
            Definition node    = Find(ExtractName(content[0]));

            uint[] rootId = node.GetNumericalForm();
            uint[] all    = new uint[content.Length + rootId.Length - 1];
            for (int j = rootId.Length - 1; j >= 0; j--)
            {
                all[j] = rootId[j];
            }

            // change all to numerical
            for (int i = 1; i < content.Length; i++)
            {
                uint value;
                bool numberFound   = UInt32.TryParse(content[i], out value);
                int  currentCursor = rootId.Length + i - 1;
                if (numberFound)
                {
                    all[currentCursor] = value;
                    node = Find(ExtractParent(all, currentCursor + 1));
                    if (node != null)
                    {
                        continue;
                    }

                    IDefinition subroot = Find(ExtractParent(all, currentCursor));

                    // if not, create Prefix node.
                    IEntity prefix = new OidValueAssignment(module, subroot.Name + "_" + value.ToString(CultureInfo.InvariantCulture), subroot.Name, value);
                    node = CreateSelf(prefix);
                    AddToTable(node);
                }
                else
                {
                    string  self   = content[i];
                    string  parent = content[i - 1];
                    IEntity extra  = new OidValueAssignment(module, ExtractName(self), ExtractName(parent), ExtractValue(self));
                    node = CreateSelf(extra);
                    if (node != null)
                    {
                        AddToTable(node);
                        all[currentCursor] = node.Value;
                    }
                    else
                    {
                        //Logger.InfoFormat(CultureInfo.InvariantCulture, "ignored {0} in module {1}", longParent, module);
                    }
                }
            }

            return(node);
        }
Exemplo n.º 3
0
        public MibTree(MibModule module)
        {
            IList <IEntity> entities = module.Entities;

            if (entities.Count > 0)
            {
                // try to find module identity as root
                foreach (IEntity element in entities)
                {
                    ModuleIdentity mi = element as ModuleIdentity;

                    if (mi != null)
                    {
                        _root.Add(new MibTreeNode(null, mi));
                    }
                }

                // find OID assignments as root, if there are any that are not below ModuleIdentity
                foreach (IEntity element in entities)
                {
                    OidValueAssignment oa = element as OidValueAssignment;

                    if (oa != null)
                    {
                        _root.Add(new MibTreeNode(null, oa));
                    }
                }

                FilterRealRoots(entities);

                foreach (MibTreeNode mibTreeNode in _root)
                {
                    entities.Remove(mibTreeNode.Entity);
                }

                if (_root.Count == 0)
                {
                    //no module identity, assume first entity is root
                    _root.Add(new MibTreeNode(null, entities[0]));
                }

                foreach (MibTreeNode mibTreeNode in _root)
                {
                    if (entities.Contains(mibTreeNode.Entity))
                    {
                        entities.Remove(mibTreeNode.Entity);
                    }
                    BuildTree(mibTreeNode, entities);
                    UpdateTreeNodeTypes(mibTreeNode);
                }
            }
        }
Exemplo n.º 4
0
        private Definition CreateExtraNodes(string module, string longParent)
        {
            string[] content = longParent.Split('.');
            Definition node = Find(ExtractName(content[0]));
            uint[] rootId = node.GetNumericalForm();
            uint[] all = new uint[content.Length + rootId.Length - 1];
            for (int j = rootId.Length - 1; j >= 0; j--)
            {
                all[j] = rootId[j];
            }
            
            // change all to numerical
            for (int i = 1; i < content.Length; i++)
            {
                uint value;
                bool numberFound = UInt32.TryParse(content[i], out value);
                int currentCursor = rootId.Length + i - 1;
                if (numberFound)
                {
                    all[currentCursor] = value;
                    node = Find(ExtractParent(all, currentCursor + 1));
                    if (node != null)
                    {
                        continue;
                    }

                    IDefinition subroot = Find(ExtractParent(all, currentCursor));
                    
                    // if not, create Prefix node.
                    IEntity prefix = new OidValueAssignment(module, subroot.Name + "_" + value.ToString(CultureInfo.InvariantCulture), subroot.Name, value);
                    node = CreateSelf(prefix);
                    AddToTable(node);
                }
                else
                {
                    string self = content[i];
                    string parent = content[i - 1];
                    IEntity extra = new OidValueAssignment(module, ExtractName(self), ExtractName(parent), ExtractValue(self));
                    node = CreateSelf(extra);
                    if (node != null)
                    {
                        AddToTable(node);
                        all[currentCursor] = node.Value;
                    }
                    else
                    {
                        Logger.InfoFormat(CultureInfo.InvariantCulture, "ignored {0} in module {1}", longParent, module);
                    }
                }
            }

            return node;
        }