Exemplo n.º 1
0
        private async Task <DictionaryResult> SearchOnline(string word, LanguagePair languagePair, CultureInfo culture)
        {
            DictionaryResult result = await YandexService.Lookup(word, languagePair).ConfigureAwait(false);

            if (result?.Definitions?.Length > 0)
            {
                string          returnedWord = result.Definitions[0].Word.ToLower(culture);
                DictionaryEntry entry        = SearchOffline(returnedWord, languagePair);
                if (entry != null)
                {
                    entry.Variations += word + "|";
                    Dictionary.Update(entry);
                }
                else
                {
                    entry          = new DictionaryEntry();
                    entry.Word     = returnedWord;
                    entry.Result   = result;
                    entry.Language = languagePair.ToString();

                    if (String.Compare(word, returnedWord, true, culture) != 0)
                    {
                        entry.Variations += word + "|";
                    }

                    Dictionary.Insert(entry);
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        private async Task <DictionaryResult> SearchOnline(string word, LanguagePair languagePair, CultureInfo culture)
        {
            DictionaryResult result = await YandexService.Lookup(word, languagePair).ConfigureAwait(false);

            if (result != null && result.Definitions != null && result.Definitions.Length > 0)
            {
                string           returnedWord = result.Definitions[0].Word.ToLower(culture);
                DictionaryEntity entity       = SearchOffline(returnedWord, languagePair);
                if (entity != null)
                {
                    entity.Variations += word + "|";
                    entity.Save();
                }
                else
                {
                    entity            = new DictionaryEntity(UnitOfWork);
                    entity.Word       = returnedWord;
                    entity.Definition = result.ToJson();
                    entity.Language   = languagePair.ToString();

                    if (String.Compare(word, returnedWord, true, culture) != 0)
                    {
                        entity.Variations += word + "|";
                    }

                    entity.Save();
                }

                UnitOfWork.CommitChanges();
            }

            return(result);
        }