mirror of
https://git.battle-of-pip.de/root/vpr-mitarbeiterverwaltung.git
synced 2025-06-21 00:03:18 +02:00
140 lines
5.4 KiB
C#
140 lines
5.4 KiB
C#
using System.Text.Json;
|
|
using DX86.Modules;
|
|
using Library;
|
|
|
|
namespace ChatClient;
|
|
|
|
public class Tester
|
|
{
|
|
public static async Task Main(string[] args)
|
|
{
|
|
MessageSender ms = new MessageSender("log.txt");
|
|
ItemSelector selector = new ItemSelector(ms);
|
|
InputBox inputBox = new InputBox(ms);
|
|
MessageBox messageBox = new MessageBox(ms);
|
|
|
|
Console.Write("Enter the server IP address: ");
|
|
string ip = Console.ReadLine();
|
|
Console.Write("Enter the port: ");
|
|
int port = int.Parse(Console.ReadLine());
|
|
|
|
Server server = new Server(ip, port);
|
|
|
|
|
|
bool running = true;
|
|
|
|
string[] testCommands = new[] {
|
|
"login",
|
|
"logout",
|
|
"get self employee",
|
|
"get worker byid",
|
|
"get worker bycode",
|
|
"clock in",
|
|
"clock out",
|
|
"clock break",
|
|
"help"
|
|
};
|
|
|
|
server.OnMessageReceived = (message) =>
|
|
{
|
|
ms.Log(message);
|
|
};
|
|
|
|
while (running)
|
|
{
|
|
try
|
|
{
|
|
string command = selector.SelectItemFromList(testCommands);
|
|
|
|
if (command == "help")
|
|
{
|
|
string response = await server.HelpCommand();
|
|
// split response into string[] at \n
|
|
var responseLines = response.Split('\n').ToList();
|
|
await messageBox.ShowAsync("Command Result: Help", responseLines);
|
|
}
|
|
else if (command == "login")
|
|
{
|
|
string user = inputBox.ShowAsync("Login", new List<string> { "Enter username" });
|
|
string password = inputBox.ShowAsync("Login", new List<string> { "Enter password" });
|
|
|
|
string response = await server.Login(user, password);
|
|
// split response into string[] at \n
|
|
var responseLines = response.Split('\n').ToList();
|
|
messageBox.ShowAsync("Command Result: Login", responseLines);
|
|
}
|
|
else if (command == "logout")
|
|
{
|
|
string response = await server.Logout();
|
|
// split response into string[] at \n
|
|
var responseLines = response.Split('\n').ToList();
|
|
messageBox.ShowAsync("Command Result: Logout", responseLines);
|
|
}
|
|
else if (command == "get self employee")
|
|
{
|
|
Employee employee = await server.GetLoggedInEmployee();
|
|
messageBox.ShowAsync("Command Result: Get Self Employee", new List<string>
|
|
{
|
|
$"ID: {employee.Id}",
|
|
$"Code: {employee.Code}",
|
|
$"Surname: {employee.Surname}",
|
|
$"Forename: {employee.Forename}",
|
|
});
|
|
}
|
|
else if (command == "clock in")
|
|
{
|
|
string response = await server.ClockIn();
|
|
// split response into string[] at \n
|
|
var responseLines = response.Split('\n').ToList();
|
|
await messageBox.ShowAsync("Command Result: clock in", responseLines);
|
|
}
|
|
else if (command == "clock out")
|
|
{
|
|
string response = await server.ClockOut();
|
|
// split response into string[] at \n
|
|
var responseLines = response.Split('\n').ToList();
|
|
await messageBox.ShowAsync("Command Result: clock out", responseLines);
|
|
}
|
|
else if (command == "clock break")
|
|
{
|
|
string response = await server.ClockBreak();
|
|
// split response into string[] at \n
|
|
var responseLines = response.Split('\n').ToList();
|
|
await messageBox.ShowAsync("Command Result: clock break", responseLines);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await messageBox.ShowAsync("Error", new List<string> { ex.Message });
|
|
}
|
|
|
|
/*
|
|
string input = "";
|
|
if (command.Contains("login"))
|
|
input = inputBox.ShowAsync("Login", new List<string> { "Enter username and password (space-separated)" });
|
|
else if (command.Contains("get worker"))
|
|
input = inputBox.ShowAsync("Worker", new List<string> { "Enter ID or Code" });
|
|
else
|
|
inputBox.ShowAsync("Info", new List<string> { "No additional parameters required." });
|
|
|
|
string fullCmd = $"{command} {input}".Trim();
|
|
string response = await server.ExecuteCommandAsync(fullCmd);
|
|
|
|
try
|
|
{
|
|
using var doc = JsonDocument.Parse(response);
|
|
var formatted = JsonSerializer.Serialize(doc, new JsonSerializerOptions { WriteIndented = true });
|
|
await messageBox.ShowAsync("Server Response", formatted.Split('\n').ToList());
|
|
}
|
|
catch
|
|
{
|
|
await messageBox.ShowAsync("Server Response", new List<string> { response });
|
|
}
|
|
|
|
string again = inputBox.ShowAsync("Continue?", new List<string> { "Type 'exit' to quit, anything else to continue" });
|
|
if (again.Trim().ToLower() == "exit")
|
|
running = false;
|
|
*/
|
|
}
|
|
}
|
|
} |