Default Register and Capture
This commit is contained in:
parent
02805630d0
commit
57296e5d81
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ obj/
|
||||
*.user
|
||||
*.log
|
||||
appsettings.Development.json
|
||||
/packages
|
||||
|
||||
@ -6,27 +6,125 @@ using System.Net;
|
||||
class Program
|
||||
{
|
||||
static SignLanguageReportApiClient api;
|
||||
static List<string> defaultClientIds = new List<string> { "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 <username> <password>");
|
||||
Console.WriteLine(" registerClient <cid> <srv>");
|
||||
Console.WriteLine(" mapUser <userId> <cid> <srv>");
|
||||
Console.WriteLine(" capture <cid> <srv>");
|
||||
Console.WriteLine(" reportAll <cid> <srv>");
|
||||
Console.WriteLine(" reportFiltered <cid> <srv>");
|
||||
Console.WriteLine(" listClients");
|
||||
Console.WriteLine(" all <username> <password>");
|
||||
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();
|
||||
switch (command)
|
||||
{
|
||||
case "registerdefaultclients":
|
||||
|
||||
RegisterDefaultClients();
|
||||
break;
|
||||
|
||||
case "capturedefaultclients":
|
||||
|
||||
CaptureDefaultClients();
|
||||
break;
|
||||
|
||||
case "registeruser":
|
||||
if (args.Length < 3)
|
||||
{
|
||||
Console.WriteLine("registerUser requires <username> <password>");
|
||||
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 <cid> [<srv>]");
|
||||
return;
|
||||
}
|
||||
RegisterClient(cid, srv);
|
||||
break;
|
||||
|
||||
case "mapuser":
|
||||
if (args.Length < 4)
|
||||
{
|
||||
Console.WriteLine("mapUser requires <userId> <cid> <srv>");
|
||||
return;
|
||||
}
|
||||
MapUser(Guid.Parse(args[1]), args[2], args[3]);
|
||||
break;
|
||||
|
||||
case "capture":
|
||||
if (args.Length < 3)
|
||||
{
|
||||
Console.WriteLine("capture requires <cid> <srv>");
|
||||
return;
|
||||
}
|
||||
Capture(args[1], args[2]);
|
||||
break;
|
||||
|
||||
case "reportall":
|
||||
if (args.Length < 3)
|
||||
{
|
||||
Console.WriteLine("reportAll requires <cid> <srv>");
|
||||
return;
|
||||
}
|
||||
ReportAllHistory(args[1], args[2]);
|
||||
break;
|
||||
|
||||
case "reportfiltered":
|
||||
if (args.Length < 3)
|
||||
{
|
||||
Console.WriteLine("reportFiltered requires <cid> <srv>");
|
||||
return;
|
||||
}
|
||||
ReportFilteredHistory(args[1], args[2]);
|
||||
break;
|
||||
|
||||
case "listclients":
|
||||
ListAllClients();
|
||||
break;
|
||||
|
||||
case "all":
|
||||
if (args.Length < 3)
|
||||
{
|
||||
Console.WriteLine("all requires <username> <password>");
|
||||
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)
|
||||
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<T>(Func<T> action, string stepName)
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
@ -189,4 +347,6 @@ class Program
|
||||
|
||||
Console.ResetColor();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user