-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
144 lines (121 loc) · 3.89 KB
/
Copy pathProgram.cs
File metadata and controls
144 lines (121 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Forms;
using CloseEnoughDictionary.Data;
using CloseEnoughDictionary.Match;
using CloseEnoughDictionary.UI;
using CloseEnoughDictionary.Util;
namespace CloseEnoughDictionary
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//must be called before initialization
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Initialize components, give them references.
CedController programController = new CedController();
MainWindow window = new MainWindow(programController);
programController.Window = window;
Application.Run(window);
}
}
/// <summary>
/// Program flow, connects the UI to data layers
/// </summary>
public class CedController
{
private TrieBase myDictionary;
private MainWindow myWindow;
private DebugForm myDebug;
internal MainWindow Window
{
set
{
this.myWindow = value;
}
}
public CedController()
{
this.myDictionary = new TrieBase();
this.myWindow = null;
this.myDebug = new DebugForm();
this.myDebug.Hide();
}
internal void AddText(string p)
{
DisplayStatus("Adding Text '{0}'", p);
ThreadPool.QueueUserWorkItem(AddTextDelegate, p);
}
private void AddTextDelegate(object param)
{
myDictionary.AddWord((string)param);
List<string> allWords = this.myDictionary.GetWords();
this.myWindow.DisplayWords(allWords);
}
internal void FindText(string p)
{
DisplayStatus("Finding Text '{0}'", p);
ThreadPool.QueueUserWorkItem(FindTextDelegate, p);
}
private void FindTextDelegate(object param)
{
MatchFactory factory = MatchFactory.GetInstance();
IMatchSet matcher = factory.GetMatcher((string)param);
List<INode> INodes = this.myDictionary.Match(matcher);
DisplayStatus("Formatting...");
var str = new List<string>();
this.myDictionary.ShowWords(str.Add, INodes);
this.myWindow.DisplayWords(str);
}
private void DisplayStatus(string p, params object[] args)
{
myWindow.StatusText = String.Format(p, args);
}
// debug method to display all loaded words
internal void ShowAll()
{
var str = new List<string>();
DisplayStatus("Formatting...");
this.myDictionary.ShowWords(str.Add);
this.myWindow.DisplayWords(str);
}
internal void LoadDictionary(string path)
{
myWindow.StatusText = "Opening " + path;
ThreadPool.QueueUserWorkItem(LoadDictionaryDelegate, path);
}
private void LoadDictionaryDelegate(object p)
{
string path = (string)p;
int count = 0;
foreach (var word in FileLoader.LoadDictionary(path))
{
if (!String.IsNullOrWhiteSpace(word))
{
count++;
myDictionary.AddWord(word);
if (count % 50 == 0)
{
count = 0;
myWindow.StatusText = String.Format("Loaded {0}", word);
}
}
}
}
internal void ResetFunctionCount()
{
DebugCounts.Reset();
}
internal void DebugShow()
{
this.myDebug.Show();
}
}
}