34e3471f6f811b8e6f4d4141516208889121cc27
[reactos.git] / irc / TechBot / TechBot.Library / Factory / CommandFactory.cs
1 using System;
2 using System.IO;
3 using System.Collections;
4 using System.Collections.Generic;
5 using System.ComponentModel;
6 using System.Reflection;
7
8 namespace TechBot.Library
9 {
10 public class CommandFactory
11 {
12 private static CommandBuilderCollection m_Commands = new CommandBuilderCollection();
13
14 private CommandFactory()
15 {
16 }
17
18 public static void LoadPlugins()
19 {
20 //get the file names of the dll files in the current directory.
21 FileInfo objExeInfo = new FileInfo(@"C:\Ros\current\irc\TechBot\TechBot.Console\bin\Debug\");
22
23 foreach (FileInfo objInfo in objExeInfo.Directory.GetFiles("*.dll"))
24 {
25 LoadPluginsFromDLLFile(objInfo.FullName);
26 }
27 }
28
29 private static void LoadPluginsFromDLLFile(string sFile)
30 {
31 Assembly assPlugin = Assembly.LoadFile(sFile);
32
33 if (assPlugin != null)
34 {
35 foreach (Type pluginType in assPlugin.GetTypes())
36 {
37 if (pluginType.IsSubclassOf(typeof(Command)))
38 {
39 if (pluginType.IsAbstract == false)
40 {
41 //Add it to the list.
42 Commands.Add(new CommandBuilder(pluginType));
43 }
44 }
45 }
46 }
47 }
48
49 public static CommandBuilderCollection Commands
50 {
51 get { return m_Commands; }
52 }
53 }
54 }