private static void ProcessMibTreeNode(MibTreeNode mibTreeNode, SnmpTreeNode assignedSnmpNode)
        {
            foreach (MibTreeNode mtn in mibTreeNode.ChildNodes)
            {
                // in theory container nodes may also be scalars or tables at the same time (for now only process real containers)
                if (mtn.NodeType == MibTreeNodeType.Container)
                {
                    SnmpTreeNode snmpTreeNode = GenerateSnmpTreeNode(mtn, assignedSnmpNode);
                    assignedSnmpNode.ChildNodes.Add(snmpTreeNode);

                    ProcessMibTreeNode(mtn, snmpTreeNode);
                }
                else if ((mtn.NodeType & MibTreeNodeType.Scalar) != 0)
                {
                    SnmpScalarNode snmpScalarNode = GenerateSnmpScalarNode(mtn, assignedSnmpNode);
                    if (snmpScalarNode != null)
                    {
                        assignedSnmpNode.ChildNodes.Add(snmpScalarNode);
                    }
                }
                else if ((mtn.NodeType & MibTreeNodeType.Table) != 0)
                {
                    SnmpTableNode snmpTableNode = GenerateSnmpTableNode(mtn, assignedSnmpNode);
                    if (snmpTableNode != null)
                    {
                        assignedSnmpNode.ChildNodes.Add(snmpTableNode);
                    }
                }
            }
        }
        private static SnmpTreeNode GenerateSnmpTreeNode(MibTreeNode mibTreeNode, SnmpTreeNode parentNode)
        {
            SnmpTreeNode result = new SnmpTreeNode(parentNode);

            result.Name    = _alphaNumericRegex.Replace(mibTreeNode.Entity.Name, "");
            result.Oid     = mibTreeNode.Entity.Value;
            result.FullOid = MibTypesResolver.ResolveOid(mibTreeNode.Entity).GetOidString();

            return(result);
        }
        private static SnmpTableNode GenerateSnmpTableNode(MibTreeNode mibTreeNode, SnmpTreeNode parentNode)
        {
            SnmpTableNode result = new SnmpTableNode(parentNode);

            result.Name = mibTreeNode.Entity.Name;
            result.Oid  = mibTreeNode.Entity.Value;

            // expect exactly one row entry
            if ((mibTreeNode.ChildNodes.Count != 1) || ((mibTreeNode.ChildNodes[0].NodeType & MibTreeNodeType.TableRow) == 0) || (mibTreeNode.ChildNodes[0].Entity.Value != 1))
            {
                Console.WriteLine("Found table with unsupported properties! Table needs exactly one (fixed) TableRow with OID=1 ! (" + mibTreeNode.Entity.Name + ")");
                return(null);
            }

            MibTreeNode rowNode = mibTreeNode.ChildNodes[0];

            ObjectType rot = rowNode.Entity as ObjectType;

            if (rot != null)
            {
                if (!String.IsNullOrWhiteSpace(rot.Augments))
                {
                    result.AugmentedTableRow = rot.Augments;

                    // the indices from another table shall be used because this table is only an extension of it
                    rot = MibTypesResolver.ResolveDeclaration(rot.Module, rot.Augments) as ObjectType;
                }

                if (rot.Indices != null)
                {
                    foreach (string index in rot.Indices)
                    {
                        ObjectType indexEntity = MibTypesResolver.ResolveDeclaration(rot.Module, index) as ObjectType;
                        if (indexEntity == null)
                        {
                            Console.WriteLine(String.Format("Could not resolve index '{0}' for table '{1}'! Table omitted!", index, result.Name));
                            return(null);
                        }

                        result.IndexNodes.Add(GenerateSnmpScalarNode(indexEntity, parentNode, ignoreAccessibleFlag: true));
                    }
                }
            }

            if (result.IndexNodes.Count == 0)
            {
                // a table cannot be used without index
                Console.WriteLine("Found table without any index column ! (" + mibTreeNode.Entity.Name + ")");
                return(null);
            }

            // add child nodes
            foreach (MibTreeNode cellNode in rowNode.ChildNodes)
            {
                SnmpScalarNode ssn = GenerateSnmpScalarNode(cellNode, parentNode);
                if (ssn != null)
                {
                    result.CellNodes.Add(ssn);
                }
            }

            return(result);
        }
        private static SnmpScalarNode GenerateSnmpScalarNode(ObjectType ote, SnmpTreeNode parentNode, bool ignoreAccessibleFlag = false)
        {
            SnmpScalarNode result;

            ITypeAssignment mibType = ote.BaseType;
            IntegerType     it      = (mibType as IntegerType);

            if (it != null)
            {
                if (ote.ReferredType.Name == Symbol.TruthValue.ToString())
                {
                    result = new SnmpScalarNodeTruthValue(parentNode);
                }
                else if ((it.Type == IntegerType.Types.Integer) || (it.Type == IntegerType.Types.Integer32))
                {
                    result = new SnmpScalarNodeInt(parentNode);
                }
                else
                {
                    Console.WriteLine(String.Format("Unsupported IntegerType '{0}'!", it.Type));
                    return(null);
                }
                if (it.IsEnumeration)
                {
                    result.Restrictions.AddRange(CreateRestrictions(it.Enumeration));
                }
                else
                {
                    result.Restrictions.AddRange(CreateRestrictions(it.Ranges));
                }
            }
            else
            {
                UnsignedType ut = (mibType as UnsignedType);
                if (ut != null)
                {
                    if ((ut.Type == UnsignedType.Types.Unsigned32) ||
                        (ut.Type == UnsignedType.Types.Gauge32))
                    {
                        result = new SnmpScalarNodeUint(SnmpDataType.Gauge, parentNode);
                    }
                    else if (ut.Type == UnsignedType.Types.Counter32)
                    {
                        result = new SnmpScalarNodeUint(SnmpDataType.Counter, parentNode);
                    }
                    else if (ut.Type == UnsignedType.Types.TimeTicks)
                    {
                        result = new SnmpScalarNodeUint(SnmpDataType.TimeTicks, parentNode);
                    }
                    else if (ut.Type == UnsignedType.Types.Counter64)
                    {
                        result = new SnmpScalarNodeCounter64(parentNode);
                        if ((ut.Ranges != null) && (ut.Ranges.Count > 0))
                        {
                            Console.WriteLine(String.Format("Generation of ranges is not supported for Counter64 type!"));
                            return(null);
                        }
                    }
                    else
                    {
                        Console.WriteLine(String.Format("Unsupported UnsignedType '{0}'!", ut.Type));
                        return(null);
                    }
                    result.Restrictions.AddRange(CreateRestrictions(ut.Ranges));
                }
                else if (mibType is IpAddressType)
                {
                    result = new SnmpScalarNodeOctetString(SnmpDataType.IpAddress, parentNode);
                    result.Restrictions.AddRange(CreateRestrictions((mibType as OctetStringType).Size));
                }
                else if (mibType is OpaqueType)
                {
                    result = new SnmpScalarNodeOctetString(SnmpDataType.Opaque, parentNode);
                    result.Restrictions.AddRange(CreateRestrictions((mibType as OctetStringType).Size));
                }
                else if (mibType is OctetStringType)
                {
                    result = new SnmpScalarNodeOctetString(SnmpDataType.OctetString, parentNode);
                    result.Restrictions.AddRange(CreateRestrictions((mibType as OctetStringType).Size));
                }
                else if (mibType is ObjectIdentifierType)
                {
                    result = new SnmpScalarNodeObjectIdentifier(parentNode);
                }
                else if (mibType is BitsType)
                {
                    result = new SnmpScalarNodeBits(parentNode, (uint)((mibType as BitsType).Map.GetHighestValue() + 1));
                    result.Restrictions.AddRange(CreateRestrictions(mibType as BitsType));
                }
                else
                {
                    TypeAssignment ta = mibType as TypeAssignment;
                    if (ta != null)
                    {
                        Console.WriteLine(String.Format("Unsupported BaseType: Module='{0}', Name='{1}', Type='{2}'!", ta.Module.Name, ta.Name, ta.Type));
                    }
                    else
                    {
                        Console.WriteLine(String.Format("Unsupported BaseType: Module='{0}', Name='{1}'!", mibType.Module, mibType.Name));
                    }

                    return(null);
                }
            }

            result.Name = _alphaNumericRegex.Replace(ote.Name, "");
            result.Oid  = ote.Value;

            if (ote.Access == MaxAccess.readWrite)
            {
                result.AccessMode = SnmpAccessMode.ReadWrite;
            }
            else if (ote.Access == MaxAccess.readOnly)
            {
                result.AccessMode = SnmpAccessMode.ReadOnly;
            }
            else if (ote.Access == MaxAccess.readCreate)
            {
                result.AccessMode = SnmpAccessMode.ReadOnly;
            }
            else if (ignoreAccessibleFlag && (ote.Access == MaxAccess.notAccessible))
            {
                result.AccessMode = SnmpAccessMode.NotAccessible;
            }
            else
            {
                // not accessible or unsupported access type
                return(null);
            }

            return(result);
        }
        private static SnmpScalarNode GenerateSnmpScalarNode(MibTreeNode mibTreeNode, SnmpTreeNode parentNode, bool ignoreAccessibleFlag = false)
        {
            ObjectType ote = mibTreeNode.Entity as ObjectType;

            if (ote != null)
            {
                return(GenerateSnmpScalarNode(ote, parentNode, ignoreAccessibleFlag));
            }

            return(null);
        }