mirror of
https://github.com/reactos/reactos.git
synced 2025-08-01 17:03:00 +00:00
- code refactoring
- made more and more easily extensible: * commands automatically loaded from plugins dlls * declarative and automatic command parameter parsing * common code moved to base classes - other fixes svn path=/trunk/; revision=33344
This commit is contained in:
parent
e3407fdd9c
commit
d7b2077ed8
42 changed files with 2263 additions and 1689 deletions
52
irc/TechBot/TechBot.Library/Factory/CommandBuilder.cs
Normal file
52
irc/TechBot/TechBot.Library/Factory/CommandBuilder.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace TechBot.Library
|
||||
{
|
||||
public class CommandBuilder
|
||||
{
|
||||
private Type m_CommandType;
|
||||
private string m_CommandName;
|
||||
private string m_CommandHelp;
|
||||
private string m_CommandDesc;
|
||||
|
||||
public CommandBuilder(Type commandType)
|
||||
{
|
||||
m_CommandType = commandType;
|
||||
|
||||
CommandAttribute commandAttribute = (CommandAttribute)
|
||||
Attribute.GetCustomAttribute(commandType, typeof(CommandAttribute));
|
||||
|
||||
m_CommandName = commandAttribute.Name;
|
||||
m_CommandHelp = commandAttribute.Help;
|
||||
m_CommandDesc = commandAttribute.Description;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return m_CommandName; }
|
||||
}
|
||||
|
||||
public string Help
|
||||
{
|
||||
get { return m_CommandHelp; }
|
||||
}
|
||||
|
||||
public string Description
|
||||
{
|
||||
get { return m_CommandDesc; }
|
||||
}
|
||||
|
||||
public Type Type
|
||||
{
|
||||
get { return m_CommandType; }
|
||||
}
|
||||
|
||||
public Command CreateCommand()
|
||||
{
|
||||
return (Command)Type.Assembly.CreateInstance(Type.FullName, true);
|
||||
}
|
||||
}
|
||||
}
|
54
irc/TechBot/TechBot.Library/Factory/CommandFactory.cs
Normal file
54
irc/TechBot/TechBot.Library/Factory/CommandFactory.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
|
||||
namespace TechBot.Library
|
||||
{
|
||||
public class CommandFactory
|
||||
{
|
||||
private static CommandBuilderCollection m_Commands = new CommandBuilderCollection();
|
||||
|
||||
private CommandFactory()
|
||||
{
|
||||
}
|
||||
|
||||
public static void LoadPlugins()
|
||||
{
|
||||
//get the file names of the dll files in the current directory.
|
||||
FileInfo objExeInfo = new FileInfo(@"C:\Ros\current\irc\TechBot\TechBot.Console\bin\Debug\");
|
||||
|
||||
foreach (FileInfo objInfo in objExeInfo.Directory.GetFiles("*.dll"))
|
||||
{
|
||||
LoadPluginsFromDLLFile(objInfo.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
private static void LoadPluginsFromDLLFile(string sFile)
|
||||
{
|
||||
Assembly assPlugin = Assembly.LoadFile(sFile);
|
||||
|
||||
if (assPlugin != null)
|
||||
{
|
||||
foreach (Type pluginType in assPlugin.GetTypes())
|
||||
{
|
||||
if (pluginType.IsSubclassOf(typeof(Command)))
|
||||
{
|
||||
if (pluginType.IsAbstract == false)
|
||||
{
|
||||
//Add it to the list.
|
||||
Commands.Add(new CommandBuilder(pluginType));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static CommandBuilderCollection Commands
|
||||
{
|
||||
get { return m_Commands; }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue