[DDK]
[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 foreach (string fileName in Directory.GetFiles(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "*.dll"))
22 {
23 LoadPluginsFromDLLFile(fileName);
24 }
25 }
26
27 private static void LoadPluginsFromDLLFile(string sFile)
28 {
29 Assembly assPlugin = Assembly.LoadFile(sFile);
30
31 Console.WriteLine("Loading plugins from : {0}", assPlugin.Location);
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 CommandBuilder cmdBuilder = new CommandBuilder(pluginType);
42
43 Console.WriteLine("{0}:{1}",
44 cmdBuilder.Name,
45 cmdBuilder.Description);
46
47 //Add it to the list.
48 Commands.Add(new CommandBuilder(pluginType));
49 }
50 }
51 }
52 }
53 }
54
55 public static CommandBuilderCollection Commands
56 {
57 get { return m_Commands; }
58 }
59 }
60 }