예제 #1
0
        public void SavePointer()
        {
            var word = new Word();

            Assert.IsNotNull(word.SavePointer);
            Assert.IsInstanceOfType(word.SavePointer, typeof(WordSavePointer));
        }
예제 #2
0
        public WordEditorVM(DictionaryEditorVM parentVM, Word word)
        {
            this.Word = word;
            this.DictionaryEditorVM = parentVM;
            this.wordStorage = DIContainer.Instance.Get<IWordStorage>();

            if (this.Word == null)
            {
                this.Word = new Word() { ID = Guid.NewGuid(), Language = MainVM.Instance.Language };
                this.isNewWord = true;
            }
            else
                this.Word.SavePointer.MakeSavePoint();

            this.SaveTranslationCmd = new Command(SaveTranslation);
            this.AddTranslationCmd = new Command(AddTranslation);
            this.DeleteTranslationCmd = new Command(DeleteTranslation);
            this.MoveTranslationUpCmd = new Command(MoveTranslationUp);
            this.MoveTranslationDownCmd = new Command(MoveTranslationDown);

            this.SavePhraseCmd = new Command(SavePhrase);
            this.AddPhraseCmd = new Command(AddPhrase);
            this.DeletePhraseCmd = new Command(DeletePhrase);

            this.SaveCmd = new Command(Save);
            this.CancelCmd = new Command(Cancel);
        }
예제 #3
0
        public void Constructor()
        {
            var word = new Word();

            Assert.IsNotNull(word.Translations);
            Assert.IsNotNull(word.Phrases);
        }
        public DictionaryEditorVM(Word word = null)
        {
            this.WordStorage = DIContainer.Instance.Get<IWordStorage>();

            this.SaveCmd = new Command(Save);
            this.CancelCmd = new Command(Cancel);
            this.AddWordCmd = new Command(AddWord);
            this.EditWordCmd = new Command(EditWord);
            this.DeleteWordCmd = new Command(DeleteWord);

            this.WordStorage.Reopen();
            this.Words = new ObservableCollection<Word>(this.WordStorage.GetWordsByLanguage(MainVM.Instance.Language));

            if (word != null)
                this.GoToWord(word);
        }
        public void Copy()
        {
            var savePointer = new WordSavePointer(this.CreateWord());
            var actual = new Word();
            var expected = savePointer.Entity;

            savePointer.CopyTo(savePointer.Entity, actual);

            Assert.AreEqual(expected.ID, actual.ID);
            Assert.AreEqual(expected.Language, actual.Language);
            Assert.AreEqual(expected.Spelling, actual.Spelling);
            Assert.AreEqual(expected.UsingFrequencyNumber, actual.UsingFrequencyNumber);

            Assert.AreEqual(expected.Phrases.Count, actual.Phrases.Count);
            Assert.AreEqual(expected.Phrases[0], actual.Phrases[0]);

            Assert.AreEqual(expected.Translations.Count, actual.Translations.Count);
            Assert.AreEqual(expected.Translations[0].ID, actual.Translations[0].ID);
            Assert.AreEqual(expected.Translations[1].ID, actual.Translations[1].ID);
        }
예제 #6
0
        public IEnumerable<Word> ExtractWordsFromFile(string fileName)
        {
            var wordList = new List<Word>();

            var rows = new List<string>();
            string line;
            using(var reader = File.OpenText(fileName))
            {
                while (!reader.EndOfStream)
                {
                    line = reader.ReadLine();
                    if (!String.IsNullOrEmpty(line))
                        rows.Add(line);
                }
            }

            foreach(var s in rows)
            {
                var row = s;
                var firstBracket = row.IndexOf('(');
                var lastBracket = row.LastIndexOf(')');
                if (firstBracket >=0 && lastBracket >= 0)
                    row = row.Remove(firstBracket, lastBracket - firstBracket + 1).Trim();
                var words = row.Split(separators, StringSplitOptions.RemoveEmptyEntries).Select(w => w.Trim()).ToArray();
                var translations = words.Where(w => this.IsRussian(w));

                var word = new Word() { ID = Guid.NewGuid(), Language = Language.En, Spelling = words[1], UsingFrequencyNumber = wordList.Count + 1 };
                foreach(var t in translations)
                {
                    var translation = new Word() { ID = Guid.NewGuid(), Language = Language.Rus, Spelling = t/*, CreateDate = DateTime.Now*/ };
                    word.Translations.Add(translation);
                }

                wordList.Add(word);
            }

            return wordList;
        }
예제 #7
0
 public void FullRefresh()
 {
     var temp = this.Word;
     this.Word = null;
     this.Word = temp;
 }
 private void GoToWord(Word word)
 {
     var wordToSelect = this.Words.FirstOrDefault(w => w.ID == word.ID);
     if (wordToSelect != null)
         this.SelectedWord = wordToSelect;
 }
 private Word CreateWord()
 {
     var word = new Word()
     {
         ID = Guid.NewGuid(),
         Language = Language.En,
         Spelling = "dream",
         UsingFrequencyNumber = 9,
         Translations = new List<Word>() { new Word() { ID = Guid.NewGuid(), Language = Language.Rus, Spelling = "мечтать" }, new Word() { ID = Guid.NewGuid(), Language = Language.Rus, Spelling = "мечта" } },
         Phrases = new List<string>() { "sweet dream" }
     };
     return word;
 }