コード例 #1
0
        private bool CheckDuplicate(FingerImageRecord fRecord)
        {
            try
            {
                if (FingerprintRecords.Count == 0)
                {
                    FingerprintRecords.Add(fRecord);
                    return(true);
                }

                //NBuffer .GetTemplateBuffer()

                using (var biometricClient = new NBiometricClient())
                {
                    // Set matching threshold
                    biometricClient.MatchingThreshold = (int)Settings.Default.MatchingScore;

                    // Set matching speed
                    biometricClient.FingersMatchingSpeed = NMatchingSpeed.Low;

                    var matcherFound = false;
                    FingerprintRecords.ForEach(item =>
                    {
                        if (item.FingerTemplate != null)
                        {
                            var status = biometricClient.Verify(fRecord.FingerSubject, item.FingerSubject);
                            if (status == NBiometricStatus.Ok)
                            {
                                matcherFound = true;
                                item         = fRecord;
                            }
                        }
                    });

                    if (matcherFound)
                    {
                        return(false);
                    }
                    FingerprintRecords.Add(fRecord);
                    return(true);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, @"Process Fingerprint");
                return(false);
            }
        }
コード例 #2
0
        public int run(int from, int to, int count)
        {
            string dbFingerTable = System.Configuration.ConfigurationManager.AppSettings["dbFingerTable"];
            string dbFingerColumn = System.Configuration.ConfigurationManager.AppSettings["dbFingerColumn"];
            string dbIdColumn = System.Configuration.ConfigurationManager.AppSettings["dbIdColumn"];

            SqlConnection conn = null;
            SqlCommand cmd = null;
            SqlDataReader reader = null;

            int AppId = 0;
            //int rowNumber = 0;

            _biometricClient = new NBiometricClient { UseDeviceManager = true, BiometricTypes = NBiometricType.Finger };
            _biometricClient.Initialize();

            Stopwatch sw = new Stopwatch();

            NSubject subject2 = null;
            int score = 0;
            int numberOfMatches = 0;
            NBiometricStatus status;
            int retcode = 0;

            var fingerArray = new string[2] { "ri", "rm" };

            byte[][] buffer = new byte[2][];

            try
            {
                var connStr = getConnectionString();
                conn = new SqlConnection(connStr);
                conn.Open();
                cmd = new SqlCommand();
                cmd.Connection = conn;

                cmd.CommandText = String.Format("SELECT AppID, {2}, {3} FROM Egy_T_FingerPrint WITH (NOLOCK) WHERE datalength(AppWsq) IS NOT NULL ORDER BY AppID ASC OFFSET {0} ROWS FETCH NEXT {1} ROWS ONLY ", from, count, fingerArray[0], fingerArray[1]);

                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    if (terminateProcess)
                        break;

                    //rowNumber++;
                    //Console.WriteLine("{0}", rowNumber + from);

                    numberOfMatches = 0;

                    if (!reader.IsDBNull(0))
                    {
                        AppId = reader.GetInt32(0);
                        //Console.WriteLine("{0}", AppId);

                        if (!reader.IsDBNull(1) && ((byte[])reader[fingerArray[0]]).Length > 1)
                        {
                            buffer[0] = (byte[])reader[fingerArray[0]];

                            subject2 = NSubject.FromMemory(buffer[0]);

                            //_biometricClient.MatchingWithDetails = true;

                            //sw.Start();

                            status = _biometricClient.Verify(subject, subject2);

                            //sw.Stop();
                            //Console.WriteLine(" ------------------------- Time elapsed: {0}", sw.Elapsed);

                            if (status == NBiometricStatus.Ok)
                            {
                                score = subject.MatchingResults[0].Score;
                                numberOfMatches++;
                            }

                            subject2.Clear();
                        }

                        if (!reader.IsDBNull(2) && ((byte[])reader[fingerArray[1]]).Length > 1)
                        {
                            buffer[1] = (byte[])reader[fingerArray[1]];

                            subject2 = NSubject.FromMemory(buffer[1]);

                            _biometricClient.MatchingWithDetails = true;
                            status = _biometricClient.Verify(subject, subject2);

                            if (status == NBiometricStatus.Ok)
                            {
                                score = subject.MatchingResults[0].Score;
                                numberOfMatches++;
                            }

                            subject2.Clear();
                        }
                    }

                    if (numberOfMatches == 2)
                    {
                        Console.WriteLine(" ----- AppID: {0}", AppId);
                        retcode = AppId;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                try
                {
                    if (reader != null)
                        reader.Close();

                    if (conn != null && conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                        conn = null;
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }

            return retcode;
        }