private async void Button_exportList_Click(object sender, RoutedEventArgs e) { var fileName = MyLib.Save(); if (fileName == null) { return; } await stackPanel_tasksQueue.EnqueueTaskAsync($"Export Word List {fileName}", new Func <Task>(async() => { Log.WriteLine("Exporting Word List..."); await trie.ExportList(new FileStream(fileName, FileMode.Create, FileAccess.Write)); Log.Write(" OK"); })); }
private async void Button_save_Click(object sender, RoutedEventArgs e) { var fileName = MyLib.Save(); if (fileName == null) { return; } await stackPanel_tasksQueue.EnqueueTaskAsync($"Save Trie {fileName}", new Func <Task>(async() => { Log.WriteLine("Saving trie..."); await Task.Run(() => trie.Save(new FileStream(fileName, FileMode.Create, FileAccess.Write))); Log.Write(" OK"); })); }
private async void Button_wordsPerCount_Click(object sender, RoutedEventArgs e) { int targetWordLength = int.Parse(Microsoft.VisualBasic.Interaction.InputBox("targetWordLength?", "", "4")); var fileName = MyLib.Save(); if (fileName == null) { return; } await stackPanel_tasksQueue.EnqueueTaskAsync($"Words per Count {fileName} {targetWordLength}", async() => await Task.Run(() => { long percent = -1, progress = 0, total_progress = trie.Size; int wordLength = 0; SortedDictionary <long, long> ans = new SortedDictionary <long, long>(); for (int i = 1; i <= 10; i++) { ans[i] = 0; } trie.Traverse(c => wordLength++, () => wordLength--, cnt => { if (++progress * 100 / total_progress > percent) { Log.WriteLine($"Words per Count... {++percent}% {ans[1]} {ans[2]} {ans[3]} {ans[4]} {ans[5]} | {ans[6]} {ans[7]} {ans[8]} {ans[9]} {ans[10]}"); } if (wordLength != targetWordLength) { return; } if (!ans.ContainsKey(cnt)) { ans[cnt] = 0; } ans[cnt]++; }); Log.WriteLine($"Writing..."); using (StreamWriter writer = new StreamWriter(fileName, false, Encoding.UTF8)) { writer.WriteLine("Count,Words"); foreach (var p in ans) { writer.WriteLine($"{p.Key},{p.Value}"); } } Log.Write(" OK"); })); }