using System; using System.Net.Http; using System.Text; using System.Text.Json; using System.Threading.Tasks; namespace Deploymentcenter.TestClient; class Program { private static readonly string BaseUrl = "https://dc.mhdf.de"; private static readonly HttpClient Client = new HttpClient(new HttpClientHandler { ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true }); static async Task Main(string[] args) { Console.OutputEncoding = Encoding.UTF8; Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("================================================="); Console.WriteLine(" 🚀 Deploymentcenter Unified Client Test Suite "); Console.WriteLine("================================================="); Console.ResetColor(); Console.WriteLine($" Server Base URL: {BaseUrl}\n"); await TestLicenseModuleAsync(); await TestWatchdogModuleAsync(); await TestUpdateServiceModuleAsync(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\n[✔] Alle Systemprüfungen erfolgreich abgeschlossen!"); Console.ResetColor(); } private static async Task TestLicenseModuleAsync() { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("1. Teste Module: Lizenzen (License Validation)..."); Console.ResetColor(); try { var payload = new { product = "myapp", license_key = "LLAB1-98A72-B3C4D-5E6F7-89012", hardware_id = "HWID-TEST-CLI-CSHARP-01", nonce = Guid.NewGuid().ToString("N"), hostname = Environment.MachineName, app_version = "1.0.0" }; string json = JsonSerializer.Serialize(payload); var content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = await Client.PostAsync($"{BaseUrl}/api/license/v1/validate", content); string responseBody = await response.Content.ReadAsStringAsync(); Console.WriteLine($" HTTP Status: {(int)response.StatusCode} {response.StatusCode}"); Console.WriteLine($" Response Payload:\n {responseBody.Replace("\n", "\n ")}"); if (response.IsSuccessStatusCode && responseBody.Contains("\"status\": \"valid\"")) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(" ✔ Lizenzen Modul Test: GÜLTIG!"); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(" ✖ Lizenzen Modul Test: Fehler oder Ungültig!"); } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($" ✖ Fehler beim Lizenzen-Test: {ex.Message}"); } Console.ResetColor(); Console.WriteLine(); } private static async Task TestWatchdogModuleAsync() { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("2. Teste Module: Watchdog (Heartbeat Ping)..."); Console.ResetColor(); try { var payload = new { source = "srv-db-01", instance = "default", type = "heartbeat", status = "ok", message = "C# Client Test Suite running smoothly", interval = 60, group = "TestRunner", os = Environment.OSVersion.ToString() }; string json = JsonSerializer.Serialize(payload); var content = new StringContent(json, Encoding.UTF8, "application/json"); var request = new HttpRequestMessage(HttpMethod.Post, $"{BaseUrl}/api/watchdog/v1/ping") { Content = content }; request.Headers.Add("X-Agent-Token", "wd_live_token_infra_01_secure"); HttpResponseMessage response = await Client.SendAsync(request); string responseBody = await response.Content.ReadAsStringAsync(); Console.WriteLine($" HTTP Status: {(int)response.StatusCode} {response.StatusCode}"); Console.WriteLine($" Response Payload:\n {responseBody.Replace("\n", "\n ")}"); if (response.IsSuccessStatusCode) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(" ✔ Watchdog Modul Test: ERFOLGREICH!"); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(" ✖ Watchdog Modul Test: FEHLER!"); } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($" ✖ Fehler beim Watchdog-Test: {ex.Message}"); } Console.ResetColor(); Console.WriteLine(); } private static async Task TestUpdateServiceModuleAsync() { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("3. Teste Module: UpdateService (Release Check)..."); Console.ResetColor(); try { HttpResponseMessage response = await Client.GetAsync($"{BaseUrl}/api/updateservice/v1/check?product=myapp&version=1.0.0"); string responseBody = await response.Content.ReadAsStringAsync(); Console.WriteLine($" HTTP Status: {(int)response.StatusCode} {response.StatusCode}"); Console.WriteLine($" Response Payload:\n {responseBody.Replace("\n", "\n ")}"); if (response.IsSuccessStatusCode) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(" ✔ UpdateService Modul Test: ERFOLGREICH!"); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(" ✖ UpdateService Modul Test: FEHLER!"); } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($" ✖ Fehler beim UpdateService-Test: {ex.Message}"); } Console.ResetColor(); Console.WriteLine(); } }