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);
}
}