public List <QuizWord> GetWords(WordList wordList) { List <TranslationInfo> wordsToLearn = wordList.GetAllTranslations().Where(w => w.IsStudied && !w.IsLearned).OrderBy(tr => tr.Translation).ToList(); DateTime cutOffDate = DateTime.UtcNow - WordInfo.TimeToMarkVerified; List <TranslationInfo> wordsToVerify = wordList.GetAllTranslations().Where(w => w.IsLearned && !w.IsVerified && w.LastStateChange <= cutOffDate).OrderBy(tr => tr.Translation).ToList(); List <TranslationInfo> words = wordsToLearn.Concat(wordsToVerify).ToList(); return(words.Select(w => new QuizWord(w)).ToList()); }
public List<QuizWord> GetWords(WordList wordList) { List<TranslationInfo> wordsToLearn = wordList.GetAllTranslations().Where(w => w.IsStudied && !w.IsLearned).OrderBy(tr => tr.Translation).ToList(); DateTime cutOffDate = DateTime.UtcNow - WordInfo.TimeToMarkVerified; List<TranslationInfo> wordsToVerify = wordList.GetAllTranslations().Where(w => w.IsLearned && !w.IsVerified && w.LastStateChange <= cutOffDate).OrderBy(tr => tr.Translation).ToList(); List<TranslationInfo> words = wordsToLearn.Concat(wordsToVerify).ToList(); return words.Select(w => new QuizWord(w)).ToList(); }
public void Test() { WordList wordList = new WordList(); wordList.Add("apple", "a round fruit", null); wordList.Add("oRRange", "a round citrus fruit", "fruit"); Assert.That(wordList.GetAllWords().Select(w => w.Word.Name), Is.EquivalentTo(new[] { "apple", "oRRange" })); Assert.That(wordList.GetAllTags(), Is.EquivalentTo(new[] { "fruit" })); Assert.That(wordList.GetWordsWithTag("fruit").Select(w => w.Word.Name), Is.EquivalentTo(new[] { "oRRange" })); wordList.Update("apple", "apple", "a round fruit", "fruit"); wordList.Update("oRRange", "orange", "a round citrus fruit", "fruit"); Assert.That(wordList.GetAllWords().Select(w => w.Word.Name), Is.EquivalentTo(new[] { "apple", "orange" })); Assert.That(wordList.GetAllTags(), Is.EquivalentTo(new[] { "fruit" })); Assert.That(wordList.GetWordsWithTag("fruit").Select(w => w.Word.Name), Is.EquivalentTo(new[] { "apple", "orange" })); wordList.MarkTranslation("a round fruit", WordEventType.Remembered); WordEvent translationRemenberedEvent = wordList.GetAllTranslations().Single(t => t.Translation == "a round fruit").Events.First().WordEvent; Assert.That(translationRemenberedEvent.EventType, Is.EqualTo(WordEventType.Remembered)); Assert.That(translationRemenberedEvent.Translation, Is.EqualTo("a round fruit")); MemoryStream mem = new MemoryStream(); WordListFileParser fileParser = new WordListFileParser(); fileParser.GenerateZip(wordList, mem); WordList wordList2 = fileParser.ParseZip(mem); Assert.That(wordList2.GetAllWords().Select(w => w.Word.Name), Is.EquivalentTo(new[] { "apple", "orange" })); Assert.That(wordList2.GetAllTags(), Is.EquivalentTo(new[] { "fruit" })); Assert.That(wordList2.GetWordsWithTag("fruit").Select(w => w.Word.Name), Is.EquivalentTo(new[] { "apple", "orange" })); translationRemenberedEvent = wordList2.GetAllTranslations().Single(t => t.Translation == "a round fruit").Events.First().WordEvent; Assert.That(translationRemenberedEvent.EventType, Is.EqualTo(WordEventType.Remembered)); Assert.That(translationRemenberedEvent.Translation, Is.EqualTo("a round fruit")); }
private void Search(bool matchFilter) { string searchText = (SearchText ?? "").Trim(); IEnumerable <TranslationInfo> translations = WordList.GetAllTranslations(); List <TranslationInfo> filteredTranslations = translations.Where(tr => tr.Translation.StartsWith(searchText, true, CultureInfo.InvariantCulture)).OrderBy(w => w.Translation).ToList(); MatchingTranslations = new ObservableCollection <TranslationInfo>(filteredTranslations); if (matchFilter) { TranslationInfo matchingTranslation = null; foreach (TranslationInfo translationInfo in filteredTranslations) { if (translationInfo.Translation.Equals(searchText, StringComparison.InvariantCultureIgnoreCase)) { matchingTranslation = translationInfo; break; } } CurrentTranslation = matchingTranslation; } }