/// <summary> /// Unloads a <see cref="PluginAppDomain"/>. /// </summary> public void Unload(PluginAppDomain appdomain) { if (!Contains(appdomain)) { return; } OnAppDomainUnloading(appdomain); appdomains.Remove(appdomain.AssemblyName.FullName); appdomain.Unload(); }
protected void OnAppDomainUnloading(PluginAppDomain appDomain) { AppDomainEventHandler appDomainUnloading = AppDomainUnloading; if (appDomainUnloading == null) { return; // no listeners } appDomainUnloading(appDomain); }
protected void OnAppDomainLoaded(PluginAppDomain appDomain) { AppDomainEventHandler appDomainLoaded = AppDomainLoaded; if (appDomainLoaded == null) { return; // no listeners } appDomainLoaded(appDomain); }
/// <summary> /// Unloads all plugin assemblies. /// </summary> public void UnloadAll() { lock ( appdomains ) { PluginAppDomain[] appdomainsArray = new PluginAppDomain[appdomains.Count]; appdomains.Values.CopyTo(appdomainsArray, 0); for (int i = 0; i < appdomainsArray.Length; i++) { Unload(appdomainsArray[i]); } } }
/// <summary> /// Loads all plugin assemblies found in a given directory. /// </summary> /// <param name="assemblyDirectory"> /// The file system directory to scan for plugins. /// </param> /// <returns> /// A list of all <see cref="PluginAppDomain"/> objects /// created to host the plugin assemblies. /// </returns> public PluginAppDomain[] LoadAll(string assemblyDirectory) { ArrayList domainsLoaded = new ArrayList(); foreach (string filename in Directory.GetFiles(assemblyDirectory, "*.dll")) { PluginAppDomain appdomain = Load(filename); if (appdomain != null) { domainsLoaded.Add(appdomain); } } return((PluginAppDomain[])domainsLoaded.ToArray(typeof(PluginAppDomain))); }
private void pluginAppDomains_AppDomainLoaded(PluginAppDomain appDomain) { foreach (IPlugin plugin in appDomain.Handlers) { Console.WriteLine("Starting {0} handler plugin.", plugin.Name); plugin.Startup(Server); Plugins.Add(plugin); } foreach (IPlugin plugin in appDomain.Filters) { Console.WriteLine("Starting {0} filter plugin.", plugin.Name); plugin.Startup(Server); Plugins.Add(plugin); } OnChanged(); }
/// <summary> /// Loads the plugins in a given assembly into the server. /// </summary> /// <param name="assemblyName"> /// The <see cref="AssemblyName"/> of the plugin assembly to load. /// </param> /// <returns> /// The <see cref="PluginAppDomain"/> created to host the /// loaded assembly. /// </returns> public PluginAppDomain Load(AssemblyName assemblyName) { try { if (appdomains.Contains(assemblyName.FullName)) { throw new InvalidOperationException("Assembly already loaded."); } PluginAppDomain appdomain = new PluginAppDomain(assemblyName); // Keep track of the appdomain so we can unload it if the plugin changes or is removed. appdomains.Add(assemblyName.FullName, appdomain); OnAppDomainLoaded(appdomain); return(appdomain); } catch (Exception ex) { Console.Error.WriteLine("Error loading assembly: {0}" + Environment.NewLine + "{1}", assemblyName.FullName, ex.ToString()); return(null); } }
private void pluginAppDomains_AppDomainUnloading(PluginAppDomain appDomain) { foreach (IPlugin plugin in appDomain.Filters) { Plugins.Remove(plugin); Console.WriteLine("Stopping {0} filter plugin.", plugin.Name); plugin.Shutdown(); } foreach (IPlugin plugin in appDomain.Handlers) { Plugins.Remove(plugin); try { Console.WriteLine("Stopping {0} handler plugin.", plugin.Name); plugin.Shutdown(); } catch (System.Runtime.Remoting.RemotingException ex) { Console.Error.WriteLine("Plugin disconnected prematurely.\n{0}", ex.ToString()); } } OnChanged(); }
protected void OnAppDomainUnloading(PluginAppDomain appDomain) { AppDomainEventHandler appDomainUnloading = AppDomainUnloading; if( appDomainUnloading == null ) return; // no listeners appDomainUnloading(appDomain); }
protected void OnAppDomainLoaded(PluginAppDomain appDomain) { AppDomainEventHandler appDomainLoaded = AppDomainLoaded; if( appDomainLoaded == null ) return; // no listeners appDomainLoaded(appDomain); }
/// <summary> /// Unloads all plugin assemblies. /// </summary> public void UnloadAll() { lock( appdomains ) { PluginAppDomain[] appdomainsArray = new PluginAppDomain[appdomains.Count]; appdomains.Values.CopyTo(appdomainsArray, 0); for( int i = 0; i < appdomainsArray.Length; i++ ) Unload(appdomainsArray[i]); } }
/// <summary> /// Unloads a <see cref="PluginAppDomain"/>. /// </summary> public void Unload(PluginAppDomain appdomain) { if( !Contains( appdomain ) ) return; OnAppDomainUnloading(appdomain); appdomains.Remove( appdomain.AssemblyName.FullName ); appdomain.Unload(); }
/// <summary> /// Loads the plugins in a given assembly into the server. /// </summary> /// <param name="assemblyName"> /// The <see cref="AssemblyName"/> of the plugin assembly to load. /// </param> /// <returns> /// The <see cref="PluginAppDomain"/> created to host the /// loaded assembly. /// </returns> public PluginAppDomain Load(AssemblyName assemblyName) { try { if( appdomains.Contains(assemblyName.FullName) ) throw new InvalidOperationException("Assembly already loaded."); PluginAppDomain appdomain = new PluginAppDomain(assemblyName); // Keep track of the appdomain so we can unload it if the plugin changes or is removed. appdomains.Add( assemblyName.FullName, appdomain ); OnAppDomainLoaded(appdomain); return appdomain; } catch( Exception ex ) { Console.Error.WriteLine("Error loading assembly: {0}" + Environment.NewLine + "{1}", assemblyName.FullName, ex.ToString()); return null; } }
/// <summary> /// Checks whether a given <see cref="PluginAppDomain"/> is already /// a member of this collection. /// </summary> public bool Contains(PluginAppDomain appdomain) { return Contains(appdomain.AssemblyName); }
/// <summary> /// Checks whether a given <see cref="PluginAppDomain"/> is already /// a member of this collection. /// </summary> public bool Contains(PluginAppDomain appdomain) { return(Contains(appdomain.AssemblyName)); }