Example #1
0
        public bool InsertUser(ref UInt32 deviceID, BS2UserBlob userBlob)
        {
            _log.InfoFormat("准备插入用户到设备 {0}", parseIdToIp(deviceID));
            BS2ErrorCode result = (BS2ErrorCode)API.BS2_EnrolUser(sdkContext, deviceID, new BS2UserBlob[] { userBlob }, 1, 1);

            if (userBlob.cardObjs != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(userBlob.cardObjs);
            }

            if (userBlob.fingerObjs != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(userBlob.fingerObjs);
            }

            if (userBlob.faceObjs != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(userBlob.faceObjs);
            }

            if (result == BS2ErrorCode.BS_SDK_ERROR_DUPLICATE_CARD)
            {
                string userId = Encoding.UTF8.GetString(Empty(userBlob.user.userID));
                _log.ErrorFormat("卡片己存在, 先从 设备IP : {0} 删除用户 {1}", parseIdToIp(deviceID), userId);
                RemoveUser(ref deviceID, userId);
                return(false);
            }
            else if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                _log.ErrorFormat("插入用户失败, 状态码 : {0} 设备IP : {1}", result, parseIdToIp(deviceID));
                return(false);
            }

            _log.ErrorFormat("插入用户成功, 状态码 : {0} 设备IP : {1} ,结果 : {2}", result, parseIdToIp(deviceID), result == BS2ErrorCode.BS_SDK_SUCCESS);
            return(result == BS2ErrorCode.BS_SDK_SUCCESS);
        }