/// <summary> /// </summary> /// <returns></returns> public Message Version() { string errorMessage; if (!UserAccountManager.HasAccess(UserAccountManager.CurrentAccessGroup, out errorMessage, true)) { return(ServiceHelper.SendErrorMessage(ResultErrorCode.AuthorizationError, errorMessage)); } UserAccountManager.GlobalNumberOfRequestsInc(); Version version = Assembly.GetExecutingAssembly().GetName().Version; XElement xResult = ServiceHelper.CreateRoot(ResultErrorCode.OK); xResult.Add(new XElement("Version", String.Format("{0:0}.{1:00}.{2:0000}", version.Major, version.Minor, version.Build))); xResult.Add(new XElement("ClientIP", ServiceHelper.CurrentClientIP)); xResult.Add(new XElement("AuthenticatedUsername", UserAccountManager.CurrentBasicAuthenticatedUsername)); xResult.Add(new XElement("ServerName", Environment.MachineName)); return(Message.CreateMessage(MessageVersion.None, "", new XElementBodyWriter(xResult))); }
public Message FingerprintRecognize(Stream stream) { string errorMessage; if (!UserAccountManager.HasAccess(UserAccountManager.CurrentAccessGroup, out errorMessage, true)) { return(ServiceHelper.SendErrorMessage(ResultErrorCode.AuthorizationError, errorMessage)); } UserAccountManager.GlobalNumberOfRequestsInc(); XElement xResult = null; try { QueryString qs = new QueryString(stream); string fingerprint = qs["Fingerprint"]; string reliabilty = qs["Reliabilities"]; using (FingerprintSignature fsQuery = new FingerprintSignature("UNKNOWN", 0, System.Convert.FromBase64String(fingerprint), 0, true)) { fsQuery.Reliabilities = System.Convert.FromBase64String(reliabilty); LuceneIndex subFingerIndex = LuceneIndexes.IndexSubFingerprint; try { // We moeten hier al locken aangezien de audiofingerprint library geen weet heeft van onze // LuceneIndex object subFingerIndex.Lock(); using (SubFingerprintQuery query = new SubFingerprintQuery(subFingerIndex.Index)) { Resultset answer = query.MatchAudioFingerprint(fsQuery, 2300); if (answer != null) { xResult = ServiceHelper.CreateRoot(ResultErrorCode.OK); xResult.Add(new XElement("RecognizeResult", new XAttribute("RecognizeCode", 0), "OK")); XElement xTimeStatistics = new XElement("TimeStatistics"); xTimeStatistics.Add(new XElement("TotalQueryTime", new XAttribute("Unit", "ms"), (int)answer.QueryTime.TotalMilliseconds)); xTimeStatistics.Add(new XElement("SubFingerQueryTime", new XAttribute("Unit", "ms"), (int)answer.FingerQueryTime.TotalMilliseconds)); xTimeStatistics.Add(new XElement("FingerLoadTime", new XAttribute("Unit", "ms"), (int)answer.FingerLoadTime.TotalMilliseconds)); xTimeStatistics.Add(new XElement("MatchTime", new XAttribute("Unit", "ms"), (int)answer.MatchTime.TotalMilliseconds)); xResult.Add(xTimeStatistics); XElement xFingerTracks = new XElement("FingerTracks", new XAttribute("Count", 0)); xResult.Add(xFingerTracks); if (answer.ResultEntries.Count > 0) { // Gets a NumberFormatInfo associated with the en-US culture. System.Globalization.NumberFormatInfo nfi = new System.Globalization.CultureInfo("en-US", false).NumberFormat; nfi.CurrencySymbol = "€"; nfi.CurrencyDecimalDigits = 2; nfi.CurrencyDecimalSeparator = "."; nfi.NumberGroupSeparator = ""; nfi.NumberDecimalSeparator = "."; Dictionary <string, ResultEntry> dict = new Dictionary <string, ResultEntry>(); int count = 0; foreach (ResultEntry item in answer.ResultEntries) { XElement xFingerTrack = new XElement("FingerTrack"); xFingerTracks.Add(xFingerTrack); xFingerTrack.Add(new XAttribute("BER", item.Similarity.ToString())); xFingerTrack.Add(new XElement("DetectPosition", new XAttribute("Unit", "ms"), new XAttribute("InSec", string.Format(nfi, "{0:#0.000}", (item.Time.TotalMilliseconds / 1000))), (int)item.Time.TotalMilliseconds)); XElement xSearchStrategy = new XElement("SearchStrategy"); xFingerTrack.Add(xSearchStrategy); xSearchStrategy.Add(new XElement("IndexNumberInMatchList", item.IndexNumberInMatchList)); xSearchStrategy.Add(new XElement("SubFingerCountHitInFingerprint", item.SubFingerCountHitInFingerprint)); xSearchStrategy.Add(new XElement("SearchName", item.SearchStrategy.ToString())); xSearchStrategy.Add(new XElement("SearchIteration", item.SearchIteration)); xFingerTrack.Add(new XElement("Reference", item.Reference.ToString())); xFingerTrack.Add(new XElement("FingerTrackID", item.FingerTrackID.ToString())); count++; } //foreach xFingerTracks.Attribute("Count").Value = count.ToString(); } } else { // Query geeft null waarde terug. Betekent dat er iets goed fout is gegaan xResult = ServiceHelper.CreateRoot(ResultErrorCode.FAILED); } if (xResult != null) { return(Message.CreateMessage(MessageVersion.None, "", new XElementBodyWriter(xResult))); } // Als we hier komen dan hebben we geen resultaat return(ServiceHelper.SendErrorMessage(ResultErrorCode.NoResultset, "No resultset")); } //using } finally { subFingerIndex.UnLock(); } } //using } catch (Exception e) { CDRLogger.Logger.LogError(e); return(ServiceHelper.SendErrorMessage(ResultErrorCode.Exception, e.Message)); } finally { GC.Collect(); } }