Example #1
0
        public static MatchResult Identify(MatchRequest request)
        {
            found = false;
            //var subset = Cache.Fingerprints[0].Count;
            var sw = new Stopwatch();

            sw.Start();

            var compareTasks = new Task <CompareResult> [ThreadDistribution.Count];

            for (int i = 0; i < ThreadDistribution.Count; i++)
            {
                if (!found)
                {
                    var scanSet = ThreadDistribution[i];
                    compareTasks[i] = Task <CompareResult> .Factory.StartNew(() => StartMatcherAsync(request, scanSet));
                }
            }

            Task.WaitAll(compareTasks);
            sw.Stop();

            var status = new StringBuilder();

            if (BenchmarkMode)
            {
                status.Append(ProcessorCores + " Tasks");
            }
            int totalScanned   = 0;
            var totalElapsed   = new TimeSpan();
            var identifyResult = new MatchResult();

            identifyResult.RequestDate  = request.RequestDate;
            identifyResult.ExtraRefCode = request.ExtraRefCode;

            foreach (var task in compareTasks)
            {
                if (task == null || task.Result == null)
                {
                    continue;
                }

                var result = task.Result;
                if (BenchmarkMode)
                {
                    status.Append(string.Format("\r\nFingerPrints: {0}, Duration: {1}", result.Scanned, result.Elapsed));
                }
                totalElapsed += result.Elapsed;
                totalScanned += result.Scanned;

                if (result.Result.Found)
                {
                    identifyResult.Found    = true;
                    identifyResult.Score    = result.Result.Score;
                    identifyResult.MemberId = result.Result.MemberId;
                    //identifyResult.ExtraRefCode = result.Result.ExtraRefCode;
                }
            }
            if (BenchmarkMode)
            {
                status.Append("\r\n= " + Convert.ToInt32(totalScanned / (totalElapsed.TotalSeconds / ProcessorCores)) +
                              "/sec, Run time: " + sw.Elapsed + ", found: " + found);
            }
            identifyResult.Extra = status.ToString();
            return(identifyResult);
        }
Example #2
0
 public CompareResult()
 {
     Result = new MatchResult();
 }
Example #3
0
        private static CompareResult StartMatcherAsync(MatchRequest toMatch, List <int> chaptersToScan)
        {
            if (BreakOnMatch && found)
            {
                return new CompareResult {
                           Elapsed = new TimeSpan(), Scanned = 0
                }
            }
            ;

            var matcher = CreateMatcher <IFingerprintSdk>();

            matcher.Initialize();
            var sw            = new Stopwatch();
            int scanned       = 0;
            int contextId     = 0;
            var compareResult = new CompareResult();

            sw.Start();
            matcher.PreMatch(out contextId);
            matcher.IdentifyPrepare(toMatch.Fingerprint, contextId);
            foreach (var chapter in chaptersToScan)
            {
                var chapterFp = Cache.Fingerprints[chapter];

                foreach (var fp in chapterFp)
                {
                    if (BreakOnMatch && found)
                    {
                        break;
                    }

                    MatchResult result = null;
                    try
                    {
                        result = matcher.Identify(fp.Fingerprint, contextId);
                    }
                    catch (Exception ex) { throw ex; }

                    scanned++;
                    if (result.Found)
                    {
                        found                = true;
                        result.MemberId      = fp.MemberId;
                        compareResult.Result = result;

                        if (BreakOnMatch)
                        {
                            break;
                        }
                    }
                }
            }

            matcher.PostMatch(contextId);
            sw.Stop();

            compareResult.Elapsed = sw.Elapsed;
            compareResult.Scanned = scanned;
            return(compareResult);
        }