private bool HasParent(ObjectIdentifierValue oiv) { ObjectIdentifierValue parent = oiv.Parent; return(oiv.Symbol != null && oiv.Symbol.Mib != null && parent != null && parent.Symbol != null && parent.Symbol.Mib != null && parent.Symbol.Mib.Equals(oiv.Symbol.Mib)); }
/// <summary> /// /// </summary> /// <param name="sym"></param> private void AddSymbol(MibSymbol sym) { MibValueSymbol valSym = sym as MibValueSymbol; if (valSym == null) { return; } ObjectIdentifierValue oiv = valSym.Value as ObjectIdentifierValue; if (oiv == null) { return; } this.AddToTree(oiv); }
/// <summary> /// Returns a specific child symbol in the OID tree. This is a /// convenience method for value symbols that have object /// identifier values. /// </summary> /// <param name="index">The child position</param> /// <returns> /// The child symbol in the OID tree, or /// null if not found or not applicable /// </returns> /// <see cref="ObjectIdentifierValue"/> public MibValueSymbol GetChild(int index) { ObjectIdentifierValue child; ObjectIdentifierValue oiv = this.value as ObjectIdentifierValue; if (oiv == null) { return(null); } child = oiv.GetChild(index); if (child != null) { return(child.Symbol); } return(null); }
/// <summary> /// Initializes this context by creating all default symbols. /// </summary> private void Initialize() { MibSymbol symbol; ObjectIdentifierValue oid; // Add the ccitt symbol oid = new ObjectIdentifierValue(CCITT, 0); symbol = new MibValueSymbol( new FileLocation(null, -1, -1), null, CCITT, new ObjectIdentifierType(), oid); oid.Symbol = (MibValueSymbol)symbol; this.symbols.Add(CCITT, symbol); // Add the iso symbol oid = new ObjectIdentifierValue(ISO, 1); symbol = new MibValueSymbol( new FileLocation(null, -1, -1), null, ISO, new ObjectIdentifierType(), oid); oid.Symbol = (MibValueSymbol)symbol; this.symbols.Add(ISO, symbol); // Add the joint-iso-ccitt symbol oid = new ObjectIdentifierValue(JOINTISOCCITT, 2); symbol = new MibValueSymbol( new FileLocation(null, -1, -1), null, JOINTISOCCITT, new ObjectIdentifierType(), oid); oid.Symbol = (MibValueSymbol)symbol; this.symbols.Add(JOINTISOCCITT, symbol); }
/// <summary> /// Validates an element type. This will check that the element /// is present in the MIB file. If it is not, a new symbol will be /// added to the MIB. /// </summary> /// <param name="symbol">The MIB symbol containing this type</param> /// <param name="log">The MIB Loader log</param> /// <param name="element">The MIB element type to check</param> /// <param name="pos">The MIB element position</param> /// <exception cref="MibException"> /// If an error was encountered during the validation /// </exception> private static void CheckElement( MibValueSymbol symbol, MibLoaderLog log, ElementType element, int pos) { Mib mib = symbol.Mib; MibSymbol elementSymbol; string name; MibType type; ObjectIdentifierValue value; elementSymbol = mib.GetSymbol(element.Name); if (elementSymbol == null) { if (element.Name != null) { name = pos + " '" + element.Name + "'"; } else { name = pos.ToString(); } string msg = "sequence element " + name + " is undefined " + "in MIB, a default symbol will be created"; log.AddWarning(symbol.Location, msg); name = element.Name; if (name == null) { name = symbol.Name + "." + pos; } type = new SnmpObjectType( element.Type, null, SnmpAccess.ReadOnly, SnmpStatus.CURRENT, "AUTOMATICALLY CREATED SYMBOL", null, new List <SnmpIndex>(), null); value = (ObjectIdentifierValue)symbol.Value; value = new ObjectIdentifierValue( symbol.Location, value, element.Name, pos); elementSymbol = new MibValueSymbol( symbol.Location, mib, name, type, value); elementSymbol.Initialize(log); } else if (elementSymbol is MibTypeSymbol) { if (element.Name != null) { name = pos + " '" + element.Name + "'"; } else { name = pos.ToString(); } throw new MibException( symbol.Location, "sequence element " + name + " does not refer to a value, but to a type"); } }
/// <summary> /// Initializes a new instance of the <see cref="MibNode"/> class. /// </summary> /// <param name="name">The node's name</param> /// <param name="value">The node's value</param> public MibNode(string name, ObjectIdentifierValue value) : base(name) { this.Value = value; }