private void Update() { if (Loaded) { string[] inputWords = ParseInputWords(); var ankiImportCreator = new AnkiImportCreator(MaxMeanings, MaxReadings); Matches = new List <JWord>(); NotFoundWords = new ObservableCollection <string>(); var alreadyFound = new HashSet <string>(); NotFoundWordsCount = 0; OutputCount = 0; Duplicates = new ObservableCollection <string>(); InputCount = 0; foreach (string inputWord in inputWords) { if (JWords.ContainsKey(inputWord)) { if (alreadyFound.Add(inputWord)) // prevent duplicates { Matches.Add(JWords[inputWord]); OutputCount++; } else { Duplicates.Add(inputWord); } } else { NotFoundWords.Add(inputWord); NotFoundWordsCount++; } InputCount++; } byte[] bytes; using (var ms = new MemoryStream()) { ankiImportCreator.WriteImportStream(ms, Matches); bytes = ms.ToArray(); } using (var ms = new MemoryStream(bytes)) { using (var streamReader = new StreamReader(ms)) { Output = streamReader.ReadToEnd(); } } } }
internal void WriteFile() { string dir = Path.GetDirectoryName(OutputFile); if (!string.IsNullOrEmpty(dir)) { if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } using (var fs = new FileStream(OutputFile, FileMode.Create, FileAccess.Write)) { //TODO: // maybe just write the output field since we already called this var ankiImportCreator = new AnkiImportCreator(MaxMeanings, MaxReadings); ankiImportCreator.WriteImportStream(fs, Matches); } } }