/// <summary> /// Loads a MIB. This method will also load all imported MIB:s if /// not previously loaded by this loader. Note that if the source /// contains several MIB modules, this method will only return the /// first one (although all are loaded). /// </summary> /// <param name="src">The MIB source</param> /// <returns>The first MIB Module loaded</returns> /// <exception cref="IOException">If the MIB couldn't be found</exception> /// <exception cref="MibLoaderException"> /// If the MIB file couldn't be loaded correctly /// </exception> private Mib Load(MibSource src) { this.sourceQueue.Clear(); this.sourceQueue.Add(src); int position = mibs.Count; MibLoaderLog log = this.LoadQueue(); if (log.ErrorCount > 0) { throw new MibLoaderException(log); } return(this.mibs[position]); }
/// <summary> /// Checks if this object is equal to another. This method /// will only return true for another mib source object with /// the same input source. /// </summary> /// <param name="obj">The object to compare with</param> /// <returns>True if the objects are equal, false if not</returns> public override bool Equals(object obj) { MibSource src = obj as MibSource; if (src == null) { return(false); } if (this.url != null) { return(this.url.Equals(src.url)); } else if (this.file != null) { return(this.file.Equals(src.file)); } return(false); }
/// <summary> /// Searches for a MIB in the search path. The name specified /// should be the MIB name. If a matching file name isn't found in /// the directory search path, the contents in the base resource /// path are also tested. Finally, if no MIB file has been found, /// the files in the search path will be opened regardless of file /// name to perform a small heuristic test for the MIB in question. /// </summary> /// <param name="name">The MIB name</param> /// <returns>The MIB found, or null if none was found</returns> private bool Locate(string name, out MibSource src) { foreach (var dir in this.dirCaches) { string file = dir.FindByName(name); if (file != null) { src = new MibSource(file); return(true); } file = dir.FindByContent(name); if (file != null) { src = new MibSource(file); return(true); } } src = new MibSource(); return(false); }
/// <summary> /// Loads all MIB files in the loader queue. New entries may be /// added to the queue while loading a MIB, as a result of /// importing other MIB files. This method will either load all /// MIB files in the queue or none (if errors were encountered). /// </summary> /// <returns>The loader log for the whole queue</returns> /// <exception cref="MibLoaderException"> /// If the MIB file in the queue couldn't be /// found /// </exception> private MibLoaderLog LoadQueue() { MibLoaderLog log = new MibLoaderLog(); IList <Mib> processed = new List <Mib>(); IList <Mib> list; foreach (var msrc in this.sourceQueue) { if (this.GetMib(msrc.File) == null) { list = msrc.ParseMib(this, log); foreach (var mib in list) { mib.Loaded = true; } this.mibs = this.mibs.Concat(list).ToList(); processed = processed.Concat(list).ToList(); } } this.sourceQueue.Clear(); for (int i = 0; i < nameQueue.Count; i++) { string name = nameQueue[i]; MibSource src = this.Locate(name); if (src == null) { continue; } if (this.GetMib(src.File) == null) { list = src.ParseMib(this, log); foreach (var mib in list) { mib.Loaded = false; } this.mibs = this.mibs.Concat(list).ToList(); processed = processed.Concat(list).ToList(); } } this.nameQueue.Clear(); // Initialize all parsed MIB files in reverse order foreach (var mib in processed.Reverse()) { try { mib.Initialize(); } catch (MibLoaderException) { // Do nothing, errors are already in the log } } // Validate all parsed MIB files in reverse order foreach (var mib in processed.Reverse()) { try { mib.Validate(); } catch (MibLoaderException) { // Do nothing, errors are already in the log } } // Handle errors if (log.ErrorCount > 0) { foreach (var mib in processed) { this.mibs.Remove(mib); } } return(log); }