Skip to content
Marcus Aurelius edited this page Jul 3, 2017 · 3 revisions

Logo

The Command Management System


What is the Command Management System?

The Command Management System helps you to implement an event system with a simple syntax that is highly adaptable. Whenever something should happen due to a command or trigger.

Get Started

Get The Command Management System

Get the command management system via the NuGet package manager

PM> Install-Package CommandManagementSystem

Start with the default manager

Add a variable from type default manager

DefaultCommandManager defaultCommandManager;

And initialize it by specifying in the constructor the namespaces where your commands are located.

defaultCommandManager = new DefaultCommandManager("ConsoleApp.Commands", "ConsoleApp");

The default manager is now ready for use. You can now execute commands by calling the dispatch method and passing a commando tag as well as your arguments.

defaultCommandManager.Dispatch("/hello", null);

Define Commands as methods

If you want to write your command code in a simple method, you can use the CommandAttribute on a method. They are executed after each call and are then finished.

[Command("/hello")]
static dynamic Hello(object[] arg)
{
  Console.WriteLine("Hello");
  return null;
}

Use the Command attribute and give it a tag. In order for your command to work, the return type, the parameter type, and the type of the tag must be identical to that of the manager.

For the Default command manager, this is: tag = string, parameter = object [], return = dynamic

The code of this method is now executed when the dispatch method receives a string with the content "/hello"

Define complex commands

If you want to use complex commands, you can write a class for a command and assign it the command attribute.In addition, the class should inherit from the Command class

[Command("/time")]
public class TimeCommand : Command<object[]>
{
  public override dynamic Main(object[] arg)
  {
    Console.WriteLine(DateTime.Now);
    return base.Main(arg);
  }
}

The manager now gets a string with the content "/time", an object of this class is created and the main method is executed.

You want it even more complex? No problem define methods with the DispatchOder attribute in your class

[Command("/test")]
public class TimeCommand : Command<object[]>
{
 [DispatchOrder(0)]
 public override dynamic Test0(object[] arg)
 {
  //Do something on first dispatch
 }

 [DispatchOrder(1)]
 public override dynamic Test1(object[] arg)
 {
  //Do something on second dispatch
 }
}

At each Dispatch the next method is lined up and executed. If another method exists, the object waits for the next dispatch. Only when no other methods are left will object discarded and a new generated.


That was not complex enough for you? Then read the pages on the topic of customizing the CommandManager or write A completely own custom CommandManager.