using AttendanceHub.Sync.Com; using AttendanceHub.Sync.Workers; using Microsoft.Extensions.Logging; namespace AttendanceHub.Sync.Oversight; /// /// Production V2 dual-session runtime for one device: /// DeviceRuntime { LiveSession, ReadSession } — each an independent ComSession, /// hence independent DeviceSessionWorker => independent owner thread (STA + permanent pump), /// independent CZKEMClass RCW, independent generation, independent recreate lifecycle. /// Pure factory/holder: session lifecycle (dispose) is owned by , /// which receives both sessions. /// public sealed class DeviceRuntime { public ComSession LiveSession { get; } public ComSession ReadSession { get; } private DeviceRuntime(ComSession liveSession, ComSession readSession) { LiveSession = liveSession; ReadSession = readSession; } public static DeviceRuntime Create(Phase1DeviceConfig config, ILoggerFactory loggerFactory) { var commTimeout = config.Sdk.CommTimeoutSeconds; // LIVE session: reads forbidden at the session level (Connect / sinks / RegEvent / events only). var live = new ComSession( config.Device.DeviceId + ":live", config.Device.Ip, config.Device.Port, config.Device.MachineNumber, commTimeout, loggerFactory.CreateLogger("ComSession:live"), performsReadOperations: false); // READ session: full read surface (Auto => ReadGeneralLogData + SSR_GetGeneralLogData). var read = new ComSession( config.Device.DeviceId + ":read", config.Device.Ip, config.Device.Port, config.Device.MachineNumber, commTimeout, loggerFactory.CreateLogger("ComSession:read"), performsReadOperations: true); return new DeviceRuntime(live, read); } }