Exemplo n.º 1
0
 void print(UInt32 idx, BS2UserBlob userblob)
 {
     Console.WriteLine(">>>> User idx[{4, 10}] id[{0}] numCards[{1}] numFingers[{2}] numFaces[{3}] name[{5}], startTime[{6}], endTime[{7}]",
                       Encoding.UTF8.GetString(userblob.user.userID).TrimEnd('\0'),
                       userblob.user.numCards,
                       userblob.user.numFingers,
                       userblob.user.numFaces,
                       idx,
                       Encoding.UTF8.GetString(userblob.name).TrimEnd('\0'),
                       userblob.setting.startTime,
                       userblob.setting.endTime
                       );
 }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public bool InsertUser(ref UInt32 deviceID, string userID, int type, string userName, List <string> cardIds, List <byte[]> fingerList)
        {
            _log.InfoFormat("准备添加用户 : 用户ID={0} 用户姓名={1} 卡内码={2} 卡类型={3} 指纹数量={4}", userID, userName, string.Join(",", cardIds), type, fingerList.Count);

            BS2UserBlob userBlob = Util.AllocateStructure <BS2UserBlob>();

            userBlob.user.version        = 0;
            userBlob.user.formatVersion  = 0;
            userBlob.user.faceChecksum   = 0;
            userBlob.user.fingerChecksum = 0;
            userBlob.user.numCards       = (byte)cardIds.Count;
            userBlob.user.numFingers     = (byte)fingerList.Count;;
            userBlob.user.numFaces       = 0;
            userBlob.user.flag           = 0;
            userBlob.cardObjs            = IntPtr.Zero;
            userBlob.fingerObjs          = IntPtr.Zero;
            userBlob.faceObjs            = IntPtr.Zero;

            userBlob.setting.startTime      = 0;
            userBlob.setting.endTime        = DatabaseHelper.ParseDateTimeTo1970Sec(DateTime.Now.AddYears(10));
            userBlob.setting.cardAuthMode   = (byte)BS2CardAuthModeEnum.NONE;
            userBlob.setting.fingerAuthMode = (byte)BS2FingerAuthModeEnum.NONE;
            userBlob.setting.idAuthMode     = (byte)BS2IDAuthModeEnum.NONE;
            userBlob.accessGroupId[0]       = 0;

            byte[] userIDArray = Encoding.UTF8.GetBytes(userID);
            Array.Clear(userBlob.user.userID, 0, BS2Envirionment.BS2_USER_ID_SIZE);
            Array.Copy(userIDArray, userBlob.user.userID, userIDArray.Length);

            if (cardIds.Count > 0)
            {
                userBlob.cardObjs = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(BS2CSNCard)) * userBlob.user.numCards);
                IntPtr curCardObjs = userBlob.cardObjs;

                foreach (var cardId in cardIds)
                {
                    byte   cardType = Convert.ToByte(type);
                    byte   cardSize = Convert.ToByte(32);
                    byte[] cardData = Hex2bytes(cardId, 32);

                    Marshal.WriteByte(curCardObjs, cardType);
                    curCardObjs += 1;
                    Marshal.WriteByte(curCardObjs, cardSize);
                    curCardObjs += 1;
                    Marshal.Copy(cardData, 0, curCardObjs, BS2Envirionment.BS2_CARD_DATA_SIZE);
                    curCardObjs += BS2Envirionment.BS2_CARD_DATA_SIZE;
                }
            }

            if (fingerList.Count > 0)
            {
                userBlob.fingerObjs = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(BS2Fingerprint)) * userBlob.user.numFingers);
                IntPtr curFingerObjs = userBlob.fingerObjs;

                for (int i = 0; i < fingerList.Count; i++)
                {
                    byte   fingerIndex  = Convert.ToByte(i);
                    byte   fingerFlag   = Convert.ToByte(0);
                    byte[] templateData = fingerList[i];

                    Marshal.WriteByte(curFingerObjs, fingerIndex);
                    curFingerObjs += 1;
                    Marshal.WriteByte(curFingerObjs, fingerFlag);
                    curFingerObjs += 3;
                    Marshal.Copy(templateData, 0, curFingerObjs, BS2Envirionment.BS2_TEMPLATE_PER_FINGER * BS2Envirionment.BS2_FINGER_TEMPLATE_SIZE);
                    curFingerObjs += BS2Envirionment.BS2_TEMPLATE_PER_FINGER * BS2Envirionment.BS2_FINGER_TEMPLATE_SIZE;
                }
            }

            return(InsertUser(ref deviceID, userBlob));
        }
Exemplo n.º 4
0
        public void listUserDatas(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            IntPtr outUidObjs = IntPtr.Zero;
            UInt32 numUserIds = 0;

            API.IsAcceptableUserID cbIsAcceptableUserID = new API.IsAcceptableUserID(cbAcceptableUserID); // we don't need to user id filtering

            Console.WriteLine("Enter the path of exported usb directory which you want to get.");
            Console.Write(">>>> ");
            string strDir = Console.ReadLine();

            if (!Directory.Exists(strDir))
            {
                Console.WriteLine("Invalid path");
                return;
            }

            Console.WriteLine("Trying to get user list.");
            BS2ErrorCode result = (BS2ErrorCode)API.BS2_GetUserListFromDir(sdkContext, strDir, out outUidObjs, out numUserIds, cbIsAcceptableUserID);

            if (result == BS2ErrorCode.BS_SDK_SUCCESS)
            {
                if (numUserIds > 0)
                {
                    IntPtr        curUidObjs = outUidObjs;
                    BS2UserBlob[] userBlobs  = new BS2UserBlob[USER_PAGE_SIZE];
                    byte[]        bufUserID  = new byte[BS2Environment.BS2_USER_ID_SIZE];

                    Console.WriteLine("Number of users : ({0}).", numUserIds);
                    for (UInt32 idx = 0; idx < numUserIds;)
                    {
                        UInt32 available = numUserIds - idx;
                        if (available > USER_PAGE_SIZE)
                        {
                            available = USER_PAGE_SIZE;
                        }

                        result = (BS2ErrorCode)API.BS2_GetUserDatasFromDir(sdkContext, strDir, curUidObjs, available, userBlobs, (UInt32)BS2UserMaskEnum.DATA | (UInt32)BS2UserMaskEnum.NAME);
                        if (result == BS2ErrorCode.BS_SDK_SUCCESS)
                        {
                            for (UInt32 loop = 0; loop < available; ++loop)
                            {
                                print(idx + loop, userBlobs[loop]);
                                if (userBlobs[loop].cardObjs != IntPtr.Zero)
                                {
                                    API.BS2_ReleaseObject(userBlobs[loop].cardObjs);
                                }
                                if (userBlobs[loop].fingerObjs != IntPtr.Zero)
                                {
                                    API.BS2_ReleaseObject(userBlobs[loop].fingerObjs);
                                }
                                if (userBlobs[loop].faceObjs != IntPtr.Zero)
                                {
                                    API.BS2_ReleaseObject(userBlobs[loop].faceObjs);
                                }
                            }

                            idx        += available;
                            curUidObjs += (int)available * BS2Environment.BS2_USER_ID_SIZE;
                        }
                        else
                        {
                            Console.WriteLine("Got error({0}).", result);
                            break;
                        }
                    }

                    API.BS2_ReleaseObject(outUidObjs);
                }
            }
            else
            {
                Console.WriteLine("Got error({0}).", result);
                return;
            }
        }
Exemplo n.º 5
0
 extern public static int BS2_IdentifyUser(IntPtr context, UInt32 deviceId, UInt16 seq, int handleResult, ref BS2UserBlob userBlob);