/// <summary> /// Initializes the MIB import. This will resolve all referenced /// symbols.This method will be called by the MIB loader. /// </summary> /// <param name="log">The MIB Loader Log</param> /// <exception cref="MibException">if an error was encountered during the /// initialization /// </exception> #pragma warning disable IDE0060 // Remove unused parameter public void Initialize(MibLoaderLog log) #pragma warning restore IDE0060 // Remove unused parameter { string message; this.mib = this.loader.GetMib(this.name); if (this.mib == null) { message = "couldn't find referenced MIB '" + this.name + "'"; throw new MibException(this.location, message); } if (this.symbols != null) { foreach (var s in this.symbols) { if (this.mib.GetSymbol(s.ToString()) == null) { message = "couldn't find imported symbol '" + s + "' in MIB '" + this.name + "'"; throw new MibException(this.location, message); } } } }
/// <summary>Initializes a new instance of the <see cref="MibTypeSymbol"/> class.</summary> /// <param name="location">The symbol location</param> /// <param name="mib">The symbol MIB file</param> /// <param name="name">The symbol name</param> /// <param name="type">The symbol type</param> public MibTypeSymbol( FileLocation location, Mib mib, string name, MibType type) : base(location, mib, name) { this.type = type; }
/// <summary> /// Initializes a new instance of the <see cref="MibValueSymbol"/> class. /// NOTE: This is an internal constructor that /// should only be called by the MIB loader. /// </summary> /// <param name="location">The symbol location</param> /// <param name="mib">The symbol MIB name</param> /// <param name="name">The symbol name</param> /// <param name="type">The symbol type</param> /// <param name="value">The symbol value</param> public MibValueSymbol( FileLocation location, Mib mib, string name, MibType type, MibValue value) : base(location, mib, name) { this.type = type; this.value = value; }
/// <summary> /// Unloads a MIB. This method will remove the loader reference to /// a previously loaded MIB if no other MIBs are depending on it. /// This method attempts to free the memory used by the MIB, as it /// clears both the loader and internal MIB references to the data /// structures (thereby allowing the garbage collector to recover /// the memory used if no other references exist). Other MIB:s /// should be unaffected by this operation. /// </summary> /// <param name="mib">The MIB to be unloaded</param> /// <exception cref="MibLoaderException"> /// If the MIB couldn't be unloaded due to dependencies from /// other loaded MIBs /// </exception> /// <see cref="Reset"/> public void Unload(Mib mib) { if (this.mibs.Contains(mib)) { var referers = mib.ImportingMibs; if (referers.Count > 0) { string message = "cannot be unloaded due to reference in " + referers[0]; throw new MibLoaderException(mib.File, message); } this.mibs.Remove(mib); mib.Clear(); } }
/// <summary>Loads a MIB file with the specified base name. The file is /// searched for in the MIB search path. The MIB is identified by /// it's MIB name (i.e. the module name). This method will also /// load all imported MIB:s if not previously loaded by this /// loader. If a MIB with the same name has already been loaded, it /// will be returned directly instead of reloading it. /// </summary> /// <param name="name">The MIB name (filename without extension)</param> /// <returns>The MIB module that was loaded</returns> /// <exception cref="IOException"> /// If the MIB file couldn't be found in the MIB search path /// </exception> /// <exception cref="MibLoaderException"> /// If the MIB file couldn't be loaded correctly /// </exception> public Mib Load(string name) { Mib mib = this.GetMib(name); if (mib == null) { if (!this.Locate(name, out MibSource src)) { throw new FileNotFoundException("couldn't locate MIB: '" + name + "'"); } mib = this.Load(src); } else { mib.Loaded = true; } return(mib); }
/// <summary> /// Initializes a new instance of the <see cref="MibMacroSymbol"/> class. /// </summary> /// <param name="location">The symbol location</param> /// <param name="mib">The symbol MIB name</param> /// <param name="name">The symbol name</param> public MibMacroSymbol(FileLocation location, Mib mib, string name) : base(location, mib, name) { }