3 using System.Collections;
4 using System.Collections.Generic;
5 using System.ComponentModel;
6 using System.Reflection;
8 namespace TechBot.Library
10 public class CommandFactory
12 private static CommandBuilderCollection m_Commands = new CommandBuilderCollection();
14 private CommandFactory()
18 public static void LoadPlugins()
20 //get the file names of the dll files in the current directory.
21 foreach (string fileName in Directory.GetFiles(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "*.dll"))
23 LoadPluginsFromDLLFile(fileName);
27 private static void LoadPluginsFromDLLFile(string sFile)
29 Assembly assPlugin = Assembly.LoadFile(sFile);
31 Console.WriteLine("Loading plugins from : {0}", assPlugin.Location);
33 if (assPlugin != null)
35 foreach (Type pluginType in assPlugin.GetTypes())
37 if (pluginType.IsSubclassOf(typeof(Command)))
39 if (pluginType.IsAbstract == false)
41 CommandBuilder cmdBuilder = new CommandBuilder(pluginType);
43 Console.WriteLine("{0}:{1}",
45 cmdBuilder.Description);
48 Commands.Add(new CommandBuilder(pluginType));
55 public static CommandBuilderCollection Commands
57 get { return m_Commands; }