Esempio 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 != 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);
        }
Esempio n. 2
0
        private async Task <DictionaryResult> Search(string word, LanguagePair languagePair, CultureInfo culture)
        {
            word = word.ToLower(culture);

            DictionaryEntity entity = SearchOffline(word, languagePair);

            if (entity != null)
            {
                return(entity.Definition.FromJson <DictionaryResult>());
            }

            DictionaryResult result = await SearchOnline(word, languagePair, culture).ConfigureAwait(false);

            if (result != null)
            {
                return(result);
            }

            string correction = await YandexService.Correct(word, languagePair.InputLanguage).ConfigureAwait(false);

            if (!String.IsNullOrWhiteSpace(correction) && String.Compare(word, correction, true, culture) != 0)
            {
                return(await Search(correction, languagePair, culture).ConfigureAwait(false));
            }

            return(null);
        }