RegisterPlugin() публичный Метод

Register a plugin by adding it to the plugin list and telling it to start
public RegisterPlugin ( IPlugin plugin ) : void
plugin IPlugin Plugin to register
Результат void
Пример #1
0
        private static void LoadPlugin(Server server, string file)
        {
            //Verify file name
            if (!File.Exists(file) || !file.EndsWith(".dll", true, null))
            {
                return;
            }

            Assembly asm = null;

            //Load file
            try
            {
                asm = Assembly.LoadFile(file);
            }
            catch (Exception)
            {
                Log.WriteLine(LogType.Error, "Unable to load {0}", file);
            }

            Type pluginInfo = null;

            try
            {
                Type[] types      = asm.GetTypes();
                Type   pluginType = typeof(IPlugin);

                foreach (var t in types)
                {
                    if (pluginType.IsAssignableFrom((Type)t))
                    {
                        pluginInfo = t;
                        break;
                    }
                }

                //Create instance of the plugin and add it to the server
                if (pluginInfo != null)
                {
                    Object  instance = Activator.CreateInstance(pluginInfo);
                    IPlugin plugin   = (IPlugin)instance;
                    server.RegisterPlugin(plugin);
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine(ex.ToString(), ConsoleColor.Red);
            }
        }
Пример #2
0
        private static void LoadPlugin(Server server, string file)
        {
            //Verify file name
            if (!File.Exists(file) || !file.EndsWith(".dll", true, null))
                return;

            Assembly asm = null;

            //Load file
            try
            {
                asm = Assembly.LoadFile(file);
            }
            catch (Exception)
            {
                Log.WriteLine(LogType.Error, "Unable to load {0}", file);
            }

            Type pluginInfo = null;
            try
            {
                Type[] types = asm.GetTypes();
                Type pluginType = typeof(IPlugin);

                foreach (var t in types)
                {
                    if (pluginType.IsAssignableFrom((Type)t))
                    {
                        pluginInfo = t;
                        break;
                    }
                }

                //Create instance of the plugin and add it to the server
                if (pluginInfo != null)
                {
                    Object instance = Activator.CreateInstance(pluginInfo);
                    IPlugin plugin = (IPlugin)instance;
                    server.RegisterPlugin(plugin);
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine(ex.ToString(), ConsoleColor.Red);
            }
        }