コード例 #1
0
 /// <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();
 }
コード例 #2
0
        protected void OnAppDomainUnloading(PluginAppDomain appDomain)
        {
            AppDomainEventHandler appDomainUnloading = AppDomainUnloading;

            if (appDomainUnloading == null)
            {
                return;                                          // no listeners
            }
            appDomainUnloading(appDomain);
        }
コード例 #3
0
        protected void OnAppDomainLoaded(PluginAppDomain appDomain)
        {
            AppDomainEventHandler appDomainLoaded = AppDomainLoaded;

            if (appDomainLoaded == null)
            {
                return;                                       // no listeners
            }
            appDomainLoaded(appDomain);
        }
コード例 #4
0
 /// <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]);
         }
     }
 }
コード例 #5
0
        /// <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)));
        }
コード例 #6
0
        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();
        }
コード例 #7
0
 /// <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);
     }
 }
コード例 #8
0
        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();
        }
コード例 #9
0
 protected void OnAppDomainUnloading(PluginAppDomain appDomain)
 {
     AppDomainEventHandler appDomainUnloading = AppDomainUnloading;
     if( appDomainUnloading == null ) return; // no listeners
     appDomainUnloading(appDomain);
 }
コード例 #10
0
 protected void OnAppDomainLoaded(PluginAppDomain appDomain)
 {
     AppDomainEventHandler appDomainLoaded = AppDomainLoaded;
     if( appDomainLoaded == null ) return; // no listeners
     appDomainLoaded(appDomain);
 }
コード例 #11
0
 /// <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]);
     }
 }
コード例 #12
0
 /// <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();
 }
コード例 #13
0
 /// <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;
     }
 }
コード例 #14
0
 /// <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);
 }
コード例 #15
0
 /// <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));
 }