/// <summary> /// Loads a plugin with raw assembly binaries. /// </summary> /// <param name="coffBlob">The COFF image format byte array that contains the plugin</param> /// <param name="pluginKey">The key string reference to this loaded plugin</param> /// <returns><c>true</c> if load successful, otherwise <c>false</c></returns> public bool Load(byte[] coffBlob, out string pluginKey) { if (coffBlob == null) { throw new ArgumentNullException(nameof(coffBlob)); } using (HashAlgorithm hasher = SHA512.Create()) { string key = BitConverter.ToString(hasher.ComputeHash(coffBlob)); if (loadedPlugins.ContainsKey(key)) { pluginKey = string.Empty; return(false); } LoadedPlugin plugin = new LoadedPlugin(key, Assembly.Load(coffBlob)); loadedPlugins.Add(plugin.pluginKey, plugin); pluginKey = key; return(true); } }
/// <summary> /// Loads a plugin with an assembly name. /// </summary> /// <param name="assemblyName">Assembly name that contains the plugin</param> /// <param name="pluginKey">The key string reference to this loaded plugin</param> /// <returns><c>true</c> if load successful, otherwise <c>false</c></returns> public bool Load(AssemblyName assemblyName, out string pluginKey) { if (assemblyName == null) { throw new ArgumentNullException(nameof(assemblyName)); } string key = assemblyName.FullName; if (loadedPlugins.ContainsKey(key)) { pluginKey = string.Empty; return(false); } LoadedPlugin plugin = new LoadedPlugin(key, Assembly.Load(assemblyName)); loadedPlugins.Add(plugin.pluginKey, plugin); pluginKey = key; return(true); }
/// <summary> /// Loads a plugin with a file path. /// </summary> /// <param name="path">File path to the assembly</param> /// <param name="pluginKey">The key string reference to this loaded plugin</param> /// <returns><c>true</c> if load successful, otherwise <c>false</c></returns> public bool Load(string path, out string pluginKey) { if (path == null) { throw new ArgumentNullException(nameof(path)); } path = Path.GetFullPath(path); if (!File.Exists(path)) { throw new FileNotFoundException("Requested plugin assembly not found.", path); } if (loadedPlugins.ContainsKey(path)) { pluginKey = string.Empty; return(false); } LoadedPlugin plugin = new LoadedPlugin(path, Assembly.LoadFile(path)); loadedPlugins.Add(plugin.pluginKey, plugin); pluginKey = path; return(true); }