diff --git a/.gitignore b/.gitignore index 64f5c67..7bf38fa 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ obj/ *.user *.log appsettings.Development.json +/packages diff --git a/SlReport/Program.cs b/SlReport/Program.cs index bf2a763..06bb881 100644 --- a/SlReport/Program.cs +++ b/SlReport/Program.cs @@ -6,27 +6,125 @@ using System.Net; class Program { static SignLanguageReportApiClient api; + static List defaultClientIds = new List { "13351", "13355", "13356" }; + static string defaultServer = "MORO"; static void Main(string[] args) { Console.Title = "SL REPORT – API TEST HARNESS"; + if (args.Length == 0) + { + Console.WriteLine("Usage:"); + Console.WriteLine(" registerUser "); + Console.WriteLine(" registerClient "); + Console.WriteLine(" mapUser "); + Console.WriteLine(" capture "); + Console.WriteLine(" reportAll "); + Console.WriteLine(" reportFiltered "); + Console.WriteLine(" listClients"); + Console.WriteLine(" all "); + return; + } + try { api = new SignLanguageReportApiClient("https://localhost:44367/"); - LogHeader("SL REPORT TEST STARTED"); - var userId = RegisterUser(); - if (userId == Guid.Empty) - return; + var command = args[0].ToLower(); - RegisterClient(); - MapUser(userId); - CaptureSessions(); - ReportAllHistory(); - ReportFilteredHistory(); - ListAllClients(); + switch (command) + { + case "registerdefaultclients": + + RegisterDefaultClients(); + break; + + case "capturedefaultclients": + + CaptureDefaultClients(); + break; + + case "registeruser": + if (args.Length < 3) + { + Console.WriteLine("registerUser requires "); + return; + } + RegisterUser(args[1], args[2]); + break; + + case "registerclient": + string cid = args.Length > 1 ? args[1] : null; + string srv = args.Length > 2 ? args[2] : defaultServer; + if (string.IsNullOrEmpty(cid)) + { + Console.WriteLine("registerClient requires []"); + return; + } + RegisterClient(cid, srv); + break; + + case "mapuser": + if (args.Length < 4) + { + Console.WriteLine("mapUser requires "); + return; + } + MapUser(Guid.Parse(args[1]), args[2], args[3]); + break; + + case "capture": + if (args.Length < 3) + { + Console.WriteLine("capture requires "); + return; + } + Capture(args[1], args[2]); + break; + + case "reportall": + if (args.Length < 3) + { + Console.WriteLine("reportAll requires "); + return; + } + ReportAllHistory(args[1], args[2]); + break; + + case "reportfiltered": + if (args.Length < 3) + { + Console.WriteLine("reportFiltered requires "); + return; + } + ReportFilteredHistory(args[1], args[2]); + break; + + case "listclients": + ListAllClients(); + break; + + case "all": + if (args.Length < 3) + { + Console.WriteLine("all requires "); + return; + } + var userId = RegisterUser(args[1], args[2]); + RegisterDefaultClients(); + MapUserForAllClients(userId); + CaptureAllClients(); + ReportAllHistoryForAllClients(); + ReportFilteredHistoryForAllClients(); + ListAllClients(); + break; + + default: + Console.WriteLine($"Unknown command: {command}"); + break; + } LogHeader("SL REPORT TEST COMPLETED"); } @@ -38,61 +136,109 @@ class Program Console.WriteLine("\nPress ENTER to exit..."); Console.ReadLine(); } - static Guid RegisterUser() + + #region Actions + + static Guid RegisterUser(string username, string password) { return SafeCall( - () => api.RegisterUser("test_user3", "123456"), - "RegisterUser" + () => api.RegisterUser(username, password), + $"RegisterUser {username}" ); } - static void RegisterClient() + + static void RegisterClient(string cid, string srv) { SafeCall( - () => api.RegisterClient("13351", "MORO"), - "RegisterClient" + () => api.RegisterClient(cid, srv), + $"RegisterClient {cid}" ); } - static void MapUser(Guid userId) + + static void RegisterDefaultClients() + { + foreach (var cid in defaultClientIds) + { + RegisterClient(cid, defaultServer); + } + } + + static void MapUser(Guid userId, string cid, string srv) { SafeCall( - () => api.MapUser(userId, "13351", "MORO"), - "MapUser" + () => api.MapUser(userId, cid, srv), + $"MapUser {cid}" ); } - static void CaptureSessions() + + static void MapUserForAllClients(Guid userId) { - SafeCall(() => api.Capture("13351", "MORO"), "Capture #1"); - SafeCall(() => api.Capture("13351", "MORO"), "Capture #2"); + foreach (var cid in defaultClientIds) + { + MapUser(userId, cid, defaultServer); + } } - static void ReportAllHistory() + + static void Capture(string cid, string srv) + { + SafeCall(() => api.Capture(cid, srv), $"Capture {cid} #1"); + } + + static void CaptureAllClients() + { + foreach (var cid in defaultClientIds) + { + Capture(cid, defaultServer); + } + } + + static void ReportAllHistory(string cid, string srv) { var history = SafeCall( - () => api.ReportAllClientHistory("13351", "MORO"), - "ReportAllClientHistory" + () => api.ReportAllClientHistory(cid, srv), + $"ReportAllClientHistory {cid}" ); if (history == null) return; - LogInfo($"History records: {history.Count}"); + LogInfo($"History records for {cid}: {history.Count}"); foreach (var h in history) LogInfo($"{h.captDate:yyyy-MM-dd HH:mm:ss} , Sessions: {h.NoOfSessions}"); } - static void ReportFilteredHistory() + + static void ReportFilteredHistory(string cid, string srv) { var from = DateTime.Today.AddDays(-7); var to = DateTime.Today; var history = SafeCall( - () => api.ReportClientHistory("13351", "MORO", from, to), - "ReportClientHistory" + () => api.ReportClientHistory(cid, srv, from, to), + $"ReportClientHistory {cid}" ); - if (history != null) - LogInfo($"Filtered records: {history.Count}"); + if (history == null) return; + + LogInfo($"Filtered records for {cid}: {history.Count}"); foreach (var h in history) LogInfo($"{h.captDate:yyyy-MM-dd HH:mm:ss} , Sessions: {h.NoOfSessions}"); - } + + static void ReportAllHistoryForAllClients() + { + foreach (var cid in defaultClientIds) + { + ReportAllHistory(cid, defaultServer); + } + } + + static void ReportFilteredHistoryForAllClients() + { + foreach (var cid in defaultClientIds) + { + ReportFilteredHistory(cid, defaultServer); + } + } + static void ListAllClients() { var clients = SafeCall( @@ -100,12 +246,24 @@ class Program "ListAllClients" ); - if (clients != null) - LogInfo($"Total clients: {clients.Count}"); + if (clients == null) return; + + LogInfo($"Total clients: {clients.Count}"); foreach (var c in clients) LogInfo($"cid: {c.cid}, srv: {c.srv}, addingDate: {c.addingDate}, lastCaptDate: {c.lastCaptDate}, NoOfCapt: {c.NoOfCapt}"); - } + static void CaptureDefaultClients() + { + foreach (var cid in defaultClientIds) + { + SafeCall(() => api.Capture(cid, defaultServer), $"Capture {cid} #1"); + } + } + + #endregion + + #region Helpers + static T SafeCall(Func action, string stepName) { var sw = Stopwatch.StartNew(); @@ -189,4 +347,6 @@ class Program Console.ResetColor(); } + + #endregion }