mirror of
https://git.battle-of-pip.de/root/vpr-mitarbeiterverwaltung.git
synced 2025-06-21 00:03:18 +02:00
TEST-SOFTWARE
This commit is contained in:
parent
d5bb061987
commit
c0462e01b1
119
TestClient/Program.cs
Normal file
119
TestClient/Program.cs
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
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}",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
TestClient/TestClient.csproj
Normal file
15
TestClient/TestClient.csproj
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\DX86\DX86.csproj" />
|
||||||
|
<ProjectReference Include="..\Library\Library.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
x
Reference in New Issue
Block a user