using System; using System.Diagnostics; using System.Runtime.InteropServices; namespace FreshProcessTest; /// /// Standalone COM enumeration tool for TEST5 (Fresh Process boundary). /// Spawned as a child process from the test harness. /// /// Output format (machine-readable): /// CONNECT=TRUE|FALSE duration_ms=N /// READGENERAL=TRUE|FALSE duration_ms=N GetLastError=N /// SSR_COUNT=N duration_ms=N GetLastError=N /// LOGCOUNT=N /// THREAD_ID=N APARTMENT=STA|MTA /// PASS|FAIL /// public static class Program { public static int Main(string[] args) { var ip = args.Length > 0 ? args[0] : "172.20.30.220"; int port = args.Length > 1 && int.TryParse(args[1], out var p) ? p : 4370; int commKey = args.Length > 2 && int.TryParse(args[2], out var k) ? k : 0; int machine = 1; Console.WriteLine($"FRESH_PROCESS: ip={ip} port={port} commKey={commKey}"); Console.WriteLine($"THREAD: id={Environment.CurrentManagedThreadId} apartment={Thread.CurrentThread.GetApartmentState()}"); Console.WriteLine($"PROCESS: pid={Process.GetCurrentProcess().Id}"); zkemkeeper.CZKEMClass? zkem = null; try { zkem = new zkemkeeper.CZKEMClass(); if (commKey > 0) zkem.SetCommPassword(commKey); // Connect var sw = Stopwatch.StartNew(); bool connected = zkem.Connect_Net(ip, port); sw.Stop(); Console.WriteLine($"CONNECT={(connected ? "TRUE" : "FALSE")} duration_ms={sw.ElapsedMilliseconds}"); if (!connected) { Console.WriteLine("FAIL"); return 1; } // GetLogCount int lc = 0; zkem.GetDeviceStatus(machine, 6, ref lc); Console.WriteLine($"LOGCOUNT={lc}"); // ReadGeneralLogData sw.Restart(); bool readOk = zkem.ReadGeneralLogData(machine); sw.Stop(); int errRead = -999; zkem.GetLastError(ref errRead); Console.WriteLine($"READGENERAL={(readOk ? "TRUE" : "FALSE")} duration_ms={sw.ElapsedMilliseconds} GetLastError={errRead}"); // SSR_GetGeneralLogData enumeration sw.Restart(); int count = 0; if (readOk) { string enroll = ""; int vm = 0, io = 0, y = 0, m = 0, d = 0, h = 0, mi = 0, s = 0, wc = 0; while (zkem.SSR_GetGeneralLogData(machine, out enroll, out vm, out io, out y, out m, out d, out h, out mi, out s, ref wc)) count++; } sw.Stop(); int errSsr = -999; zkem.GetLastError(ref errSsr); Console.WriteLine($"SSR_COUNT={count} duration_ms={sw.ElapsedMilliseconds} GetLastError={errSsr}"); bool pass = connected && readOk && count > 0; Console.WriteLine(pass ? "PASS" : "FAIL"); return pass ? 0 : 1; } catch (Exception ex) { Console.WriteLine($"EXCEPTION={ex.Message}"); Console.WriteLine("FAIL"); return 2; } finally { if (zkem != null) { try { Marshal.ReleaseComObject(zkem); } catch { } } } } }