/// <summary> /// Uploads a user's data to the device /// </summary> /// <param name="machineNumber">The number of the machine. Normally 1,2 or 3</param> /// <param name="ipAddress">the IP address of the machine "172.16.0.110"</param> /// <param name="user">User data to upload</param> /// <param name="staffClockId"></param> /// <param name="staffClockCardNumber"></param> /// <returns>Boolean - true | false</returns> public bool UploadTemplates(string machineNumber, string ipAddress, FaceUser user, string staffClockId, string staffClockCardNumber) { int vEnrollNumber = Convert.ToInt32(staffClockId); const int vBackupNumber = 11; const int vPrivilege = 0; var cardNumber = staffClockCardNumber; Trace.WriteLine("Uploading Template For Badge: " + user.FaceName + " --->"); IntPtr zero = IntPtr.Zero; uint pRecvLen = 0; string pDevInfoBuf = String.Format("DeviceInfo( dev_id = \"{0}\" dev_type = \"HW_HDCP\" comm_type = \"ip\" ip_address = \"{1}\")", machineNumber, ipAddress); //------------------------------ string pSendBuf = String.Format("SetEmployee(id=\"{0}\" name=\"{1}\" authority=\"{2}\" card_num=\"{3}\" calid=\"{4}\" opendoor_type=\"{5}\" check_type=\"{6}\" ", /*0*/ user.FaceID, /*1*/ user.FaceName, /*2*/ user.FaceAuthority, /*2*/ user.FaceCardNumber, /*4*/ user.FaceCalID, /*5*/ user.FaceDoorType, /*6*/ user.FaceCheckType); // Add Face Data foreach (var data in user.FaceData) { pSendBuf += String.Format("\r\nface_data=\"{0}\"", data.Data); } pSendBuf = pSendBuf + ")"; if (HwDev_Execute(pDevInfoBuf, pDevInfoBuf.Length, pSendBuf, pSendBuf.Length, ref zero, ref pRecvLen, null) == 0) { Trace.WriteLine("Template data uploaded."); return(true); } else if (FK_PutEnrollDataWithString(1, vEnrollNumber, vBackupNumber, vPrivilege, cardNumber) == 1) { } else { Trace.WriteLine(String.Format("Communication failure to device {0}!", ipAddress)); return(false);//throw new Exception(String.Format("Communication failure to device {0}!", ipAddress)); } return(false); }
/// <summary> /// Downloads the data for a specified clock entry /// </summary> /// <param name="machineNumber">The number of the machine. Normally 1,2 or 3</param> /// <param name="ipAddress">the IP address of the machine "172.16.0.110"</param> /// <param name="clockId">the specific clock ID</param> /// <returns>FaceUser</returns> public FaceUser DownloadTemplates(string machineNumber, string ipAddress, string clockId) { Trace.Write("Downloading Template For Badge: " + clockId + " --->"); FaceUser Record = new FaceUser(); IntPtr zero = IntPtr.Zero; uint pRecvLen = 0; string pDevInfoBuf = String.Format("DeviceInfo( dev_id = \"{0}\" dev_type = \"HW_HDCP\" comm_type = \"ip\" ip_address = \"{1}\")", machineNumber, ipAddress); string pSendBuf = String.Format("GetEmployee(id=\"{0}\")", clockId); if (HwDev_Execute(pDevInfoBuf, pDevInfoBuf.Length, pSendBuf, pSendBuf.Length, ref zero, ref pRecvLen, null) == 0) { Trace.WriteLine("processing template data..."); string templateData = Marshal.PtrToStringAnsi(zero); templateData = templateData.Substring(7, templateData.Length - 8); templateData = templateData .Replace("\r\n", "") .Replace(" ", "|") .Replace("face_data=", "|face_data=") .Replace("||", "|"); // Split on "|" var dataArray = templateData.Split('|'); if (dataArray[0].Contains("success")) { string TmpStr = ""; int QuoteIdx = 0; int StrCount = 0; for (int i = 1; i < dataArray.Count(); i++) { TmpStr = dataArray[i]; QuoteIdx = TmpStr.IndexOf('\"') + 1; StrCount = TmpStr.LastIndexOf("\"") - QuoteIdx; var Data = TmpStr.Substring(0, TmpStr.IndexOf('=')); var Value = TmpStr.Substring(QuoteIdx, StrCount); switch (Data) { case "id": Record.FaceID = int.Parse(Value); break; case "name": Record.FaceName = Value; break; case "authority": Record.FaceAuthority = Value; break; case "card_num": Record.FaceCardNumber = Value; break; case "calid": Record.FaceCalID = Value; break; case "opendoor_type": Record.FaceDoorType = Value; break; case "check_type": Record.FaceCheckType = Value; break; case "face_data": { Record.FaceData.Add(new FaceData { Data = Value }); break; } default: break; } } } else { Trace.WriteLine(String.Format("Error retrieving template for {0}", clockId)); throw new Exception(String.Format("Error retrieving template for {0}", clockId)); } } else { Trace.WriteLine(String.Format("Communication failure to device {0}!", ipAddress)); throw new Exception(String.Format("Communication failure to device {0}!", ipAddress)); } return(Record); }