/// <summary> /// Clears and prepares this value for garbage collection. This /// method will recursively clear any associated types or values, /// making sure that no data structures references this object. /// </summary> /// <remarks> /// This is an internal method that should /// only be called by the MIB loader. /// </remarks> public override void Clear() { // Recursively clear all children in same MIB if (this.children != null) { foreach (var c in this.children) { c.Clear(); } } // Remove parent reference if all children were cleared if (this.ChildCount <= 0) { if (this.parent != null) { this.Parent.children.Remove(this); this.parent = null; } this.children = null; } // Clear other value data this.symbol = null; base.Clear(); }
/// <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> /// Validates a MIB type. This will check any sequences and make /// sure their elements are present in the MIB file. If they are /// not, new symbols 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="type">The MIB type to check</param> /// <exception cref="MibException"> /// If an error was encountered during the validation /// </exception> private static void CheckType( MibValueSymbol symbol, MibLoaderLog log, MibType type) { if (type is SequenceOfType sequence) { SnmpObjectType.CheckType(symbol, log, sequence.ElementType); } else if (type is SequenceType tp) { IList <ElementType> elems = tp.AllElements.ToList(); for (int i = 0; i < elems.Count(); i++) { SnmpObjectType.CheckElement(symbol, log, elems[i], i + 1); } } }
/// <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"); } }