mirror of
https://git.battle-of-pip.de/root/vpr-mitarbeiterverwaltung.git
synced 2025-06-21 00:03:18 +02:00

Implementierung CommandManager.cs in BackendServer.cs Worker.cs umbennannt zu Employee.cs WorkerState.cs umbenannt zu EmployeeState.cs .help command eingefügt (HelpCommand.cs) Management-Server auf port 3767 eingefügt (Program.cs) Server-Connector (Server.cs) erste methoden eingefügt GetEmployee Login Logout clockin,clockout,clockbreak
46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
using System.Net.Sockets;
|
|
using System.Reflection;
|
|
using DX86;
|
|
using Server.Commands;
|
|
|
|
namespace Server;
|
|
|
|
public class CommandManager
|
|
{
|
|
private readonly Dictionary<string, ICommand> _commands = new();
|
|
|
|
public CommandManager()
|
|
{
|
|
LoadCommands();
|
|
}
|
|
|
|
private void LoadCommands()
|
|
{
|
|
// Get all types implementing ICommand
|
|
var commandTypes = Assembly.GetExecutingAssembly()
|
|
.GetTypes()
|
|
.Where(t => typeof(ICommand).IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract);
|
|
|
|
foreach (var type in commandTypes)
|
|
{
|
|
// Create an instance of the command
|
|
if (Activator.CreateInstance(type) is ICommand command)
|
|
{
|
|
// Use the Executor property as the key
|
|
_commands[command.Executor] = command;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ExecuteCommand(string executor, TcpClient? client = null, TcpServer? clientSocket = null, params string[] args)
|
|
{
|
|
if (_commands.TryGetValue(executor, out var command))
|
|
{
|
|
command.Exec(args:args, client:client, clientSocket:clientSocket);
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine($"Command '{executor}' not found.");
|
|
}
|
|
}
|
|
} |