// ******************************************************************************** /// <summary> /// Handle request for a single term /// </summary> /// <param name="request"></param> /// <returns></returns> /// <created>UPh,30.10.2015</created> /// <changed>UPh,30.10.2015</changed> // ******************************************************************************** private void HandleTermInfoRequest(TermBaseRequest request) { TermBase tb = _TermBases.FindTermBase(request.TermBaseID); if (tb == null) { return; } TermInfo info; if (!tb.GetTermInfo(request.TermID, out info, this)) { return; } info.TermID = request.TermID; _TermbaseQuery.FireTermInfoResult(request.ID, request.TermBaseID, info); }
// ******************************************************************************** /// <summary> /// Create the correct term base instance, depending on the file extension /// </summary> /// <param name="file"></param> /// <returns></returns> /// <created>UPh,25.10.2015</created> /// <changed>UPh,25.10.2015</changed> // ******************************************************************************** static public TermBase CreateTermBase(TermBaseFile file) { try { file.OpenError = ""; TermBase termBase = null; string ext = Path.GetExtension(file.StoragePath); if (string.Compare(ext, ".csv", true) == 0) { termBase = new TermBaseCSV(); } else if (string.Compare(ext, ".tbx", true) == 0) { termBase = new TermBaseTBX(); } else if (string.Compare(ext, ".sdltb", true) == 0) { termBase = new TermBaseDB(); } if (termBase != null) { termBase.File = file; termBase.OnOpenFile(); } else { file.OpenError = string.Format("Unknown term base type: {0}", ext); } return(termBase); } catch (Exception ex) { file.OpenError = ex.Message; return(null); } }
// ******************************************************************************** /// <summary> /// /// </summary> /// <param name="term"></param> /// <param name="infos"></param> /// <returns></returns> /// <created>UPh,17.11.2015</created> /// <changed>UPh,17.11.2015</changed> // ******************************************************************************** internal void HandleTermInfosRequest(string term, List <TermInfoResultArgs> result = null) { bool bSync = (result != null); // Build index if necessary if (_Index.LCID != _TermbaseQuery.LCID1) { TermListItems items = RetrieveTermList(true, false); if (!bSync && _shouldStop) { return; } // Index from items _Index.BuildIndex(_TermbaseQuery.LCID1, items); } foreach (IndexItem match in _Index.Matches(term)) { // Get TermInfo TermBase termbase = _TermBases.FindTermBase(match.TermBaseID); if (termbase == null) { continue; } TermInfo terminfo = null; if (!termbase.GetTermInfo(match.TermID, out terminfo, this)) { return; } TermInfoResultArgs item = new TermInfoResultArgs(); item.RequestID = 0; item.TermBaseID = match.TermBaseID; item.Info = terminfo; result.Add(item); } }
// ******************************************************************************** /// <summary> /// /// </summary> /// <param name="requestid"></param> /// <param name="match"></param> /// <param name="from"></param> /// <param name="len"></param> /// <param name="result"></param> /// <created>UPh,20.03.2016</created> /// <changed>UPh,20.03.2016</changed> // ******************************************************************************** private void HandleProhibitedTerminologyMatch(bool bTargetLanguage, long requestid, IndexItem match, int from, int len, List <TerminologyResultArgs> result = null) { // Get TermInfo TermBase termbase = _TermBases.FindTermBase(match.TermBaseID); if (termbase == null) { return; } TermInfo terminfo = null; if (!termbase.GetTermInfo(match.TermID, out terminfo, this)) { return; } int langset = -1; if (bTargetLanguage) { if (terminfo.LanguageSets.Count < 2) { return; } langset = 1; } else { if (terminfo.LanguageSets.Count < 1) { return; } langset = 0; } foreach (TermInfo.Term term in terminfo.LanguageSets[langset].Terms) { if (term.Props == null || term.Props.Status != TermStatus.prohibited) { continue; } ulong hash = TermIndex.MakeGlossaryHashCode(term.Text); if (match.Hash != hash) { continue; } TerminologyResultArgs args = new TerminologyResultArgs(); args.Status = term.Props.Status; args.RequestID = requestid; args.TermBaseID = match.TermBaseID; args.TermID = match.TermID; args.FindFrom = from; args.FindLen = len; args.Term1 = term.Text; args.Term2 = term.Text; args.Origin = termbase.File.DisplayName; args.Description = ""; if (result != null) { result.Add(args); } else { _TermbaseQuery.FireTerminologyResult(args); } } }
// ******************************************************************************** /// <summary> /// /// </summary> /// <param name="match"></param> /// <returns></returns> /// <created>UPh,14.11.2015</created> /// <changed>UPh,14.11.2015</changed> // ******************************************************************************** private void HandleTerminologyMatch(long requestid, IndexItem match, int from, int len, List <TerminologyResultArgs> result = null) { // Get TermInfo TermBase termbase = _TermBases.FindTermBase(match.TermBaseID); if (termbase == null) { return; } TermInfo terminfo = null; if (!termbase.GetTermInfo(match.TermID, out terminfo, this)) { return; } if (terminfo.LanguageSets.Count != 2) { return; } TermInfo.Term srcterm = null; foreach (TermInfo.Term term in terminfo.LanguageSets[0].Terms) { ulong hash = TermIndex.MakeGlossaryHashCode(term.Text); if (match.Hash != hash) { continue; } srcterm = term; break; } if (srcterm == null) { return; } string definition = terminfo.Definition; foreach (TermInfo.Term term in terminfo.LanguageSets[1].Terms) { TerminologyResultArgs args = new TerminologyResultArgs(); if (term.Props != null) { args.Status = term.Props.Status; } else { args.Status = TermStatus.none; } args.RequestID = requestid; args.TermBaseID = match.TermBaseID; args.TermID = match.TermID; args.FindFrom = from; args.FindLen = len; args.Term1 = srcterm.Text; args.Term2 = term.Text; args.Origin = termbase.File.DisplayName; args.Description = definition; if (result != null) { result.Add(args); } else { _TermbaseQuery.FireTerminologyResult(args); } } }