public void TestReversedEventOrder()
        {
            WordList wordList = new WordList();
            Word word = wordList.Add("test", "test", "");
            wordList.ResetHistory();

            DateTime utcNow = DateTime.UtcNow;
            word.Events.Add(new WordEvent(utcNow.AddDays(-1), WordEventType.Remembered));
            word.Events.Add(new WordEvent(utcNow.AddDays(-2), WordEventType.Forgotten));
            word.Events.Add(new WordEvent(utcNow.AddDays(-2), WordEventType.Added));

            var wordListXml = WordListXmlConverter.ConvertToXml(wordList);
            WordList wordList2 = WordListXmlConverter.ConvertToObject(wordListXml);

            List<WordInfo> words2 = wordList2.GetAllWords().ToList();
            Assert.That(words2.Count, Is.EqualTo(1));

            Word word2 = words2[0].Word;

            Assert.That(word2.Events.Count, Is.EqualTo(3));
            Assert.That(word2.Events[0].EventType, Is.EqualTo(WordEventType.Added));
            Assert.That(word2.Events[1].EventType, Is.EqualTo(WordEventType.Forgotten));
            Assert.That(word2.Events[2].EventType, Is.EqualTo(WordEventType.Remembered));
            Assert.That(word2.Events[0].EventDate, Is.EqualTo(utcNow.AddDays(-2)));
            Assert.That(word2.Events[1].EventDate, Is.EqualTo(utcNow.AddDays(-2)));
            Assert.That(word2.Events[2].EventDate, Is.EqualTo(utcNow.AddDays(-1)));
        }
예제 #2
0
        public void Test()
        {
            DateTime dateAdded = DateTime.UtcNow.AddDays(-100);
            DateTime dateRepeated1 = dateAdded + new TimeSpan(1, 0, 0, 0);
            DateTime dateForgotten = dateAdded + new TimeSpan(2, 0, 0, 0);
            DateTime dateRepeated2 = dateAdded + new TimeSpan(2, 0, 1, 0);
            DateTime dateRepeated3 = dateAdded + new TimeSpan(3, 0, 0, 0);
            DateTime dateLearned = dateAdded + new TimeSpan(4, 0, 0, 0);
            DateTime dateVerified = dateAdded + new TimeSpan(10, 0, 0, 0);

            Word word = new Word();
            word.Name = "name";
            word.Description = "descr";
            word.Tags = "tag1, tag2";
            word.Events.Add(new WordEvent(dateAdded, WordEventType.Added));
            word.Events.Add(new WordEvent(dateRepeated1, WordEventType.Remembered));
            word.Events.Add(new WordEvent(dateForgotten, WordEventType.Forgotten));
            word.Events.Add(new WordEvent(dateRepeated2, WordEventType.Remembered));

            WordList wordList = new WordList();
            wordList.Populate(new List<Word> {word});

            WordInfo wordInfo = WordInfo.Create(wordList, word);
            Assert.That(wordInfo.LastEvent.LastStateChange, Is.EqualTo(dateForgotten));
            Assert.That(wordInfo.State, Is.EqualTo(WordState.Studied));
            Assert.That(wordInfo.IsStudied);
            Assert.That(!wordInfo.IsLearned);
            Assert.That(!wordInfo.IsVerified);

            word.Events.Add(new WordEvent(dateRepeated3, WordEventType.Remembered));
            wordInfo.Update();
            Assert.That(wordInfo.LastEvent.LastStateChange, Is.EqualTo(dateRepeated3));
            Assert.That(wordInfo.State, Is.EqualTo(WordState.Repeated));
            Assert.That(wordInfo.IsStudied);
            Assert.That(!wordInfo.IsLearned);
            Assert.That(!wordInfo.IsVerified);

            word.Events.Add(new WordEvent(dateLearned, WordEventType.Remembered));
            wordInfo.Update();
            Assert.That(wordInfo.LastEvent.LastStateChange, Is.EqualTo(dateLearned));
            Assert.That(wordInfo.State, Is.EqualTo(WordState.Learned));
            Assert.That(wordInfo.IsStudied);
            Assert.That(wordInfo.IsLearned);
            Assert.That(!wordInfo.IsVerified);

            word.Events.Add(new WordEvent(dateVerified, WordEventType.Remembered));
            wordInfo.Update();
            Assert.That(wordInfo.LastEvent.LastStateChange, Is.EqualTo(dateVerified));
            Assert.That(wordInfo.State, Is.EqualTo(WordState.Verified));
            Assert.That(wordInfo.IsStudied);
            Assert.That(wordInfo.IsLearned);
            Assert.That(wordInfo.IsVerified);
        }
예제 #3
0
        public static WordsListStats BuildFrom(WordList wordList)
        {
            List<WordInfo> words = wordList.GetAllWords().ToList();
            List<TranslationInfo> translations = wordList.GetAllTranslations().ToList();

            WordsListStats stats = new WordsListStats();

            stats.WordCount = words.Count;
            stats.StudiedWordCount = words.Count(w => w.IsStudied);
            stats.RepeatedWordCount = words.Count(w => w.IsRepeated);
            stats.LearnedWordCount = words.Count(w => w.IsLearned);
            stats.VerifiedWordCount = words.Count(w => w.IsVerified);

            stats.TranslationCount = translations.Count;
            stats.StudiedTranslationCount = translations.Count(w => w.IsStudied);
            stats.RepeatedTranslationCount = translations.Count(w => w.IsRepeated);
            stats.LearnedTranslationCount = translations.Count(w => w.IsLearned);
            stats.VerifiedTranslationCount = translations.Count(w => w.IsVerified);
            
            return stats;
        }
예제 #4
0
        public static WordsListStats BuildFrom(WordList wordList)
        {
            List <WordInfo>        words        = wordList.GetAllWords().ToList();
            List <TranslationInfo> translations = wordList.GetAllTranslations().ToList();

            WordsListStats stats = new WordsListStats();

            stats.WordCount         = words.Count;
            stats.StudiedWordCount  = words.Count(w => w.IsStudied);
            stats.RepeatedWordCount = words.Count(w => w.IsRepeated);
            stats.LearnedWordCount  = words.Count(w => w.IsLearned);
            stats.VerifiedWordCount = words.Count(w => w.IsVerified);

            stats.TranslationCount         = translations.Count;
            stats.StudiedTranslationCount  = translations.Count(w => w.IsStudied);
            stats.RepeatedTranslationCount = translations.Count(w => w.IsRepeated);
            stats.LearnedTranslationCount  = translations.Count(w => w.IsLearned);
            stats.VerifiedTranslationCount = translations.Count(w => w.IsVerified);

            return(stats);
        }
예제 #5
0
        public void SaveDictionary(string filename)
        {
            if (File.Exists(filename))
            {
                string backupFilename = filename + ".bak";
                if (File.Exists(backupFilename))
                {
                    File.Delete(backupFilename);
                }
                File.Copy(filename, filename + ".bak");
            }
            using (FileStream stream = File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                WordListFileParser parser = new WordListFileParser();
                parser.GenerateZip(WordList, stream);
            }
            DictPath = filename;
            WordList.ResetModified();

            Settings.Load();
            Settings.AddRecentFile(filename);
            Settings.Save();
        }
예제 #6
0
        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"));
        }
예제 #7
0
        public static TranslationInfo Create(WordList wordList, string translation)
        {
            TranslationInfo res = new TranslationInfo();

            res.WordList = wordList;
            res.Translation = translation;

            res.Update();

            return res;
        }
예제 #8
0
        public static WordInfo Create(WordList wordList, Word word)
        {
            WordInfo res = new WordInfo();

            res.WordList = wordList;
            res.Word = word;

            res.Update();

            return res;
        }
예제 #9
0
 public void CreateNewDictionary()
 {
     WordList = new WordList();
     DictPath = null;
 }
예제 #10
0
        public void OpenDictionary(string filename)
        {
            bool oldFormat = false;
            try
            {
                using (FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    WordListFileParser parser = new WordListFileParser();
                    WordList = parser.ParseXml(stream);
                    oldFormat = true;
                }
            }
            catch (ParserException)
            {
                //ignore an attempt to read file in old format if it fails
            }

            if (!oldFormat)
            {
                using (FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    WordListFileParser parser = new WordListFileParser();
                    WordList = parser.ParseZip(stream);
                }
            }

            DictPath = oldFormat ? null : filename;

            if (!oldFormat)
            {
                Settings.Load();
                Settings.AddRecentFile(filename);
                Settings.Save();
            }
        }
예제 #11
0
 public void CreateNewDictionary()
 {
     WordList = new WordList();
     DictPath = null;
 }