示例#1
0
        public FingerTemplate Deserialize(int type, byte[] data)
        {
            TemplateHi template = null;

            if (type == TemplateTypes.HiTemplate)
            {
                template = new TemplateHi(data);
            }
            return(template);
        }
示例#2
0
        private void deviceThread()
        {
            isThreadFinalized = false;
            ///
            int enrollCount = 0;

            stateCallBack     = new BioAPI.GUI_STATE_CALLBACK(DeviceHi.GuiStateCallback);
            streamingCallBack = new BioAPI.GUI_STREAMING_CALLBACK(DeviceHi.GuiStreamingCallback);
            List <FingerTemplate> templates = new List <FingerTemplate>();
            STATE       state     = STATE.IDLE;
            COMMAND     com       = COMMAND.NONE;
            int         BirHandle = 0;
            int         intsize   = Marshal.SizeOf(typeof(IntPtr));
            uint        res;
            bioapi_data unitcontroldata;
            bioapi_bir  bir = new bioapi_bir();

            int[] enrollmentBirHandle   = new int[3];
            int   verifyEnrollBirHandle = 0;
            byte  enrollState           = BioAPI.NO_PURPOSE_AVAILABLE;

            unitcontroldata.Data = Marshal.AllocHGlobal(4 * intsize);


            try
            {
                online = true;
                while (true)
                {
                    cancelToken.Token.ThrowIfCancellationRequested();

                    if (state == STATE.IDLE)
                    {
                        com = queue.Take(cancelToken.Token);
                    }
                    else
                    {
                        // non blocking take
                        if (queue.Count > 0)
                        {
                            com = queue.Take();
                        }
                    }

                    switch (com)
                    {
                    case COMMAND.LIVECAPTURE_START:
                        state = STATE.STARTTEST;
                        break;

                    case COMMAND.ENROLLMENT_START:
                        state       = STATE.GETFINGER;
                        enrollCount = 0;
                        enrollState = BioAPI.PURPOSE_ENROLL;
                        templates.Clear();
                        break;

                    case COMMAND.SINGLECAPTURE_START:
                        state = STATE.GETSINGLE;
                        break;

                    case COMMAND.SINGLECAPTURE_STOP:
                    case COMMAND.LIVECAPTURE_STOP:
                    case COMMAND.ENROLLMENT_STOP:
                        BioAPI.Cancel(handle);
                        state = STATE.IDLE;
                        break;
                    }
                    com = COMMAND.NONE;
                    switch (state)
                    {
                    case STATE.IDLE:
                        Detach();
                        break;

                    case STATE.STARTTEST:
                        SendBaseMessage("Please, place finger on scanner");
                        state = STATE.TEST;
                        break;

                    case STATE.TEST:
                        Attach();
                        res = BioAPI.Capture(handle, BioAPI.PURPOSE_VERIFY, ref BirHandle, CaptureTimeout);
                        if (res == 0)
                        {
                            bioapi_input_bir captured_bir_data = new bioapi_input_bir();
                            int      processed_bir             = 0;
                            GCHandle tmpgch = GCHandle.Alloc(BirHandle, GCHandleType.Pinned);
                            captured_bir_data.Form = BioAPI.BIR_HANDLE_INPUT;
                            captured_bir_data.InputBIR.BIRinBSP = tmpgch.AddrOfPinnedObject();
                            BioAPI.Process(handle, ref captured_bir_data, ref processed_bir);
                            BioAPI.FreeBIRHandle(handle, BirHandle);
                            tmpgch.Free();
                            BioAPI.GetBIRFromHandle(handle, processed_bir, ref bir);
                            OnBiometricsCaptured(new FingerImageHi(bir));
                            Thread.Sleep(300);
                            BioAPI.Free(bir.BiometricData.Data);
                            BioAPI.Free(bir.SecurityBlock.Data);
                        }
                        else
                        {
                            if (((res & (uint)BioAPI.Error.TIMEOUT_EXPIRED) == (uint)BioAPI.Error.TIMEOUT_EXPIRED) ||
                                ((res & (uint)BioAPI.Error.USER_CANCELLED) == (uint)BioAPI.Error.USER_CANCELLED))
                            {
                                //                  _log.Info(res.ToString() + " test capture error");
                                OnBiometricsCaptured(null);
                            }
                            else
                            {
                                online = false;
                                state  = STATE.OFFLINE;
                                Ambassador.AddMessage(new MSignal(this, MSignal.SIGNAL.DEVICE_FAILURE));
                            }
                        }
                        break;

                    case STATE.GETSINGLE:
                        //SendBaseMessage("Please, select finger to enroll or place a finger on the FV scanner");
                        state = STATE.GETSINGLEIMAGE;
                        break;

                    case STATE.GETSINGLEIMAGE:
                        Attach();
                        res = BioAPI.Capture(handle,BioAPI.PURPOSE_VERIFY,ref BirHandle,CaptureTimeout);
                        if (res == 0)
                        {
                            bioapi_input_bir captured_bir_data = new bioapi_input_bir();
                            int      processed_bir             = 0;
                            GCHandle tmpgch = GCHandle.Alloc(BirHandle,GCHandleType.Pinned);
                            captured_bir_data.Form = BioAPI.BIR_HANDLE_INPUT;
                            captured_bir_data.InputBIR.BIRinBSP = tmpgch.AddrOfPinnedObject();
                            BioAPI.Process(handle,ref captured_bir_data,ref processed_bir);
                            BioAPI.FreeBIRHandle(handle,BirHandle);
                            tmpgch.Free();
                            BioAPI.GetBIRFromHandle(handle,processed_bir,ref bir);
                            Detach();
                            FingerImageHi catchedImage = new FingerImageHi(bir);
                            OnSingleCaptured(catchedImage);
                            Thread.Sleep(300);
                            BioAPI.Free(bir.BiometricData.Data);
                            BioAPI.Free(bir.SecurityBlock.Data);
                        }
                        else
                        {
                            if (((res & (uint)BioAPI.Error.TIMEOUT_EXPIRED) == (uint)BioAPI.Error.TIMEOUT_EXPIRED) ||
                                ((res & (uint)BioAPI.Error.USER_CANCELLED) == (uint)BioAPI.Error.USER_CANCELLED))
                            {
                                //                    _log.Info(res.ToString() + " getsingleimage capture error");
                            }
                            else
                            {
                                online = false;
                                state  = STATE.OFFLINE;
                                Ambassador.AddMessage(new MSignal(this,MSignal.SIGNAL.DEVICE_FAILURE));
                            }
                        }
                        break;

                    case STATE.GETFINGER:
                        SendBaseMessage("Please, place a finger on the FV scanner");
                        state = STATE.GETIMAGE;
                        break;

                    case STATE.GETIMAGE:
                        Attach();
                        res = BioAPI.Capture(handle,enrollState,ref BirHandle,CaptureTimeout);
                        if (res == 0)
                        {
                            bioapi_input_bir captured_bir_data = new bioapi_input_bir();
                            GCHandle         tmpgch            = GCHandle.Alloc(BirHandle,GCHandleType.Pinned);
                            captured_bir_data.Form = BioAPI.BIR_HANDLE_INPUT;
                            captured_bir_data.InputBIR.BIRinBSP = tmpgch.AddrOfPinnedObject();
                            if (enrollState == BioAPI.PURPOSE_ENROLL)
                            {
                                res = BioAPI.CreateTemplate(handle,ref captured_bir_data,ref enrollmentBirHandle[enrollCount]);
                                enrollCount++;
                                if (enrollCount == 2)
                                {
                                    enrollState = BioAPI.PURPOSE_VERIFY;
                                }
                            }
                            else if (enrollState == BioAPI.PURPOSE_VERIFY)
                            {
                                res = BioAPI.Process(handle,ref captured_bir_data,ref verifyEnrollBirHandle);
                                enrollCount++;
                            }
                            tmpgch.Free();

                            BioAPI.GetBIRFromHandle(handle,BirHandle,ref bir);
                            OnBiometricsCaptured(new FingerImageHi(bir));
                            BioAPI.Free(bir.BiometricData.Data);
                            BioAPI.Free(bir.SecurityBlock.Data);

                            OnSendProgressMessage(enrollCount * 33);
                            if (enrollCount < 3)
                            {
                                state = STATE.GETEMPTY;
                            }
                            else
                            {
                                int              FMRAchieved = 0;
                                byte             matchResult = 0;
                                GCHandle         gcverify,gcenroll;
                                bioapi_input_bir verify_input_bir = new bioapi_input_bir();
                                verify_input_bir.Form = BioAPI.BIR_HANDLE_INPUT;
                                gcverify = GCHandle.Alloc(verifyEnrollBirHandle,GCHandleType.Pinned);
                                verify_input_bir.InputBIR.BIRinBSP = gcverify.AddrOfPinnedObject();

                                bioapi_input_bir enroll_input_bir = new bioapi_input_bir();
                                enroll_input_bir.Form = BioAPI.BIR_HANDLE_INPUT;
                                gcenroll = GCHandle.Alloc(enrollmentBirHandle[0],GCHandleType.Pinned);
                                enroll_input_bir.InputBIR.BIRinBSP = gcenroll.AddrOfPinnedObject();

                                res = BioAPI.VerifyMatch(handle,2072,ref verify_input_bir,ref enroll_input_bir,ref matchResult,ref FMRAchieved);
                                gcenroll.Free();
                                if ((res == 0) && (matchResult != 0))
                                {
                                    enroll_input_bir.Form = BioAPI.BIR_HANDLE_INPUT;
                                    gcenroll = GCHandle.Alloc(enrollmentBirHandle[1],GCHandleType.Pinned);
                                    enroll_input_bir.InputBIR.BIRinBSP = gcenroll.AddrOfPinnedObject();

                                    res = BioAPI.VerifyMatch(handle,2072,ref verify_input_bir,ref enroll_input_bir,ref matchResult,ref FMRAchieved);
                                    gcenroll.Free();
                                }
                                gcverify.Free();
                                if ((res == 0) && (matchResult != 0))
                                {
                                    res = BioAPI.GetBIRFromHandle(handle,enrollmentBirHandle[1],ref bir);
                                    TemplateHi template = new TemplateHi(bir);
                                    BioAPI.Free(bir.BiometricData.Data);
                                    BioAPI.Free(bir.SecurityBlock.Data);
                                    templates.Add(template);
                                    state = STATE.FINISHENROLL;
                                }
                                else
                                {
                                    state = STATE.FINISHENROLL;
                                    BioAPI.FreeBIRHandle(handle,enrollmentBirHandle[1]);
                                }
                                BioAPI.FreeBIRHandle(handle,enrollmentBirHandle[0]);
                                BioAPI.FreeBIRHandle(handle,verifyEnrollBirHandle);
                            }
                        }
                        else if (((res & (uint)BioAPI.Error.TIMEOUT_EXPIRED) == (uint)BioAPI.Error.TIMEOUT_EXPIRED) ||
                                 ((res & (uint)BioAPI.Error.USER_CANCELLED) == (uint)BioAPI.Error.USER_CANCELLED))
                        {
//                                _log.Info(res.ToString() + " getimage capture error");
                        }
                        else
                        {
                            online = false;
                            state  = STATE.OFFLINE;
                            for (int i = 0; i < enrollCount; i++)
                            {
                                BioAPI.FreeBIRHandle(handle,enrollmentBirHandle[i]);
                            }
                            Ambassador.AddMessage(new MSignal(this,MSignal.SIGNAL.DEVICE_FAILURE));
                        }
                        break;

                    case STATE.GETEMPTY:
                        SendPopUpMessage("Please remove finger from scanner");
                        Attach();
                        res = BioAPI.Capture(handle,BioAPI.PURPOSE_ENROLL,ref BirHandle,CaptureTimeout);
                        if (res != 0)
                        {
                            state = STATE.GETFINGER;
                        }
                        else
                        {
                            BioAPI.FreeBIRHandle(handle,BirHandle);
                        }
                        break;

                    case STATE.GETEMPTYIMAGE:
                        break;

                    case STATE.FINISHENROLL:
                        state = STATE.IDLE;
                        if (templates.Count() > 0)
                        {
                            SendPopUpMessage("Successfully registered");
                            OnBiometricsEnrolled(templates.ToList());
                        }
                        else
                        {
                            SendPopUpMessage("Registration failed");
                            OnBiometricsEnrolled(null);
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                _log.Error(e.Message);
            }
            finally
            {
                Detach();
                isThreadFinalized = true;
            }
        }