using System; using System.Linq; namespace HanvonF710XAttendanceService { class AttendanceMachine { private string machineId; private string machineIp; private int portNumber; private string machineName; private int siteId; private string status; private DateTime lastSyncDate; public AttendanceMachine() { } public AttendanceMachine(string machineId, string machineIp, int portNumber, string machineName, int siteId, string status, DateTime lastSyncDate) { this.MachineId = machineId; this.MachineIp = machineIp; this.PortNumber = portNumber; this.MachineName = machineName; this.SiteId = siteId; this.Status = status; this.LastSyncDate = lastSyncDate; } public string MachineId { get => machineId; set => machineId = value; } public string MachineIp { get => machineIp; set { // Normalize DB/config IP values that sometimes contain whitespace (e.g. "192.168. 0.50"). string ip = value ?? ""; if (ip.Length > 0) { ip = new string(ip.Trim().Where(c => !char.IsWhiteSpace(c)).ToArray()); } machineIp = ip; } } public int PortNumber { get => portNumber; set => portNumber = value; } public string MachineName { get => machineName; set => machineName = value; } public int SiteId { get => siteId; set => siteId = value; } public string Status { get => status; set => status = value; } public DateTime LastSyncDate { get => lastSyncDate; set => lastSyncDate = value; } public string GetDeviceInfo() { // HDCP SDK DeviceInfo uses password for device auth (same credentials as device web UI). string password = MachineScope.GetDevicePassword() ?? ""; return "DeviceInfo( dev_id = \"1\" dev_type = \"" + MachineScope.GetDeviceType() + "\" comm_type = \"ip\" ip_address = \"" + this.machineIp + "\", password = \"" + EscapeDeviceInfoValue(password) + "\", port_number = \"" + this.portNumber + "\")"; } /// Safe for InternalLogs — password redacted. public string GetDeviceInfoForLog() { return "DeviceInfo( dev_id = \"1\" dev_type = \"" + MachineScope.GetDeviceType() + "\" comm_type = \"ip\" ip_address = \"" + this.machineIp + "\", password = \"***\", port_number = \"" + this.portNumber + "\")"; } private static string EscapeDeviceInfoValue(string value) { if (string.IsNullOrEmpty(value)) return ""; return value.Replace("\\", "\\\\").Replace("\"", "\\\""); } } }