-
Notifications
You must be signed in to change notification settings - Fork 1
/
MainWindow.cs
480 lines (405 loc) · 21 KB
/
MainWindow.cs
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
// Default WinForms Imports
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace EHR_Monitor_Test
{
// TODO: Log the name of the window that the user has in focus when a test runs.
// TODO: If the focused window is the same as this window, don't allow the test to run.
// TODO: Attempt to log any errors coming back from the user32.dll when reading or writing text to another process.
public partial class MainWindow : Form
{
private const int ticks = 5; // How many seconds do we want to allow a user to find the EHR Window before attempting to poll it
private int currentTick = 0;
private const int numberOfTests = 6;
private bool[] results = new bool[numberOfTests + 1];
private int currentTestNumber = 0; // What test are we currently on
private delegate void TestDelegate();
private TestDelegate currentTest = null;
private bool warned = false; // Have we warned the user to move their cursor focus to the EHR window already for this test?
public MainWindow()
{
this.InitializeComponent();
this.timer1.Stop();
// Don't allow for maximizing the window as the layout is static...
this.MaximizeBox = false;
// Set any atributes on our own items that we may need
this.ourText.ReadOnly = true;
this.theirText.ReadOnly = true;
// Just for easier reading of results...
results[0] = true;
// Go ahead and setup the first test in the view.
this.SetupNextTest();
MessageBox.Show("On all tests, after pushing the 'Run Test' button, you will have 5 seconds to bring your EHR Application to the foreground and click into the text box (make sure it has focus). \n\nFor these tests to work, the cursor must be in the main text box like you were actively working or typing in it.");
}
private void SetupTestOne()
{
this.testNumber.Text = "Test Number: 1";
this.testDescription.Text = "First, we are going to test if we can successfully READ text from the text area inside the EHR Application. \r\nTo do this, YOU need to manually insert text into the EHR Application. The text on the left side below has been copied to your clipboard. \r\nPlease open your EHR Application and PASTE the text into the normal working area. \r\n\r\nThe test will attempt to read text from the EHR Application and place it on the right side. \r\nSuccess is when the right side contains the text from the left.";
this.ourText.Text = "Test One \r\nSimple Text Test \r\n\r\nThis is a test of reading text from the EHR Application.";
Clipboard.SetText(this.ourText.Text, TextDataFormat.Text);
}
private void RunTestOne()
{
if (!this.warned)
{
MessageBox.Show("Please make sure you have pasted the text from the left box into your EHR Application. \nOnce you push 'Ok', you will have 5 seconds to click into your EHR's main Text Box.");
this.ShowTestCountdown();
}
else
{
// Read the text from the EHR Application
string readText = EHRText.GetTextFromActiveWindowElement();
// Set the right side text to what we read
this.theirText.Text = readText;
if (this.theirText.Text.Contains(this.ourText.Text))
{
this.PrintPossibleSuccess();
}
else
{
this.PrintPossibleFailure();
}
}
}
private void SetupTestTwo()
{
this.testNumber.Text = "Test Number: 2";
this.testDescription.Text = "Next, we are going to test if we can successfully WRITE text to the text area inside the EHR Application. \r\nTo do this, WE will need to insert text into the EHR Application. \r\n\r\nThis test will attempt to write the text from the left side below into your EHR's Text Box. It will then read back your EHR's text and paste the read in value to the right side below. \r\nSuccess is when the right side matches the left side, AND the Text Box in the EHR Application contains the same text.";
this.ourText.Text = "Test Two; Test of writing text. The left and right text boxes should match once the test has run.";
}
private void RunTestTwo()
{
if (!this.warned)
{
MessageBox.Show("Once you push 'Ok', you will have 5 seconds to click into your EHR's main Text Box.");
this.ShowTestCountdown();
}
else
{
// Write our text to the EHR
EHRText.SetTextOfActiveWindowElement(ourText.Text);
// Read the text back from the EHR Application
string readText = EHRText.GetTextFromActiveWindowElement();
// Set the right side text to what we read
this.theirText.Text = readText;
if (this.theirText.Text.Equals(this.ourText.Text))
{
this.PrintPossibleSuccess();
}
else
{
this.PrintPossibleFailure();
}
}
}
private void SetupTestThree()
{
this.testNumber.Text = "Test Number: 3";
this.testDescription.Text = "Now, we are going to test if we can successfully READ RTF from the text area inside the EHR Application. \r\nTo do this, YOU need to manually insert RTF into the EHR Application. The RTF on the left side below has been copied to your clipboard. \r\nPlease open your EHR Application and PASTE the RTF into the normal working area. \r\n\r\nThe test will attempt to read RTF from the EHR Application and place it on the right side. \r\nSuccess is when the right side contains the RTF from the left with the same coloring and formatting.";
this.ourText.Rtf = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Calibri;}{\\f1\\fnil\\fcharset2 Symbol;}}"
+ "{\\colortbl ;\\red255\\green0\\blue0;\\red0\\green176\\blue80;}"
+ "{\\*\\generator Msftedit 5.41.21.2510;}\\viewkind4\\uc1\\pard\\sa200\\sl276\\slmult1\\cf1\\lang9\\ul\\b\\f0\\fs22 Test Three\\cf0\\ulnone\\b0\\par"
+ "\\cf2\\i Rich Text Test\\par"
+ "\\cf0\\i0 This test tests the following:\\par"
+ "\\pard{\\pntext\\f1\\'B7\\tab}{\\*\\pn\\pnlvlblt\\pnf1\\pnindent0{\\pntxtb\\'B7}}\\fi-360\\li720\\sa200\\sl276\\slmult1 Reading RTF Text from the EHR's Text Box via the Clipboard\\par"
+ "}";
Clipboard.SetText(this.ourText.Rtf, TextDataFormat.Rtf);
}
private void RunTestThree()
{
if (!this.warned)
{
MessageBox.Show("Please make sure you have pasted the RTF from the left box into your EHR Application. \nOnce you push 'Ok', you will have 5 seconds to click into your EHR's main Text Box.");
this.ShowTestCountdown();
}
else
{
Clipboard.Clear(); // just for sanity
EHRText.SetClipboardContentsToActiveWindowElement();
// Set the right side text to what we read
this.theirText.Rtf = Clipboard.GetText(TextDataFormat.Rtf);
if (this.theirText.Rtf.Contains(this.ourText.Rtf))
{
this.PrintPossibleSuccess();
}
else
{
this.PrintPossibleFailure();
}
}
}
private void SetupTestFour()
{
this.testNumber.Text = "Test Number: 4";
this.testDescription.Text = "Next, we are going to test if we can successfully WRITE RTF to the text area inside the EHR Application. \r\nTo do this, WE will need to insert text into the EHR Application. \r\n\r\nThis test will attempt to write the text from the left side below into your EHR's Text Box. It will then read back your EHR's text and paste the read in value to the right side below. \r\nSuccess is when the right, left side, and the EHR Application contain the same text with the same coloring and formatting.";
this.ourText.Rtf = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Calibri;}{\\f1\\fnil\\fcharset2 Symbol;}}"
+ "{\\colortbl ;\\red255\\green0\\blue0;\\red0\\green176\\blue80;}"
+ "{\\*\\generator Msftedit 5.41.21.2510;}\\viewkind4\\uc1\\pard\\sa200\\sl276\\slmult1\\cf1\\lang9\\ul\\b\\f0\\fs22 Test Four\\cf0\\ulnone\\b0\\par"
+ "\\cf2\\i Rich Text Test\\par"
+ "\\cf0\\i0 This test tests the following:\\par"
+ "\\pard{\\pntext\\f1\\'B7\\tab}{\\*\\pn\\pnlvlblt\\pnf1\\pnindent0{\\pntxtb\\'B7}}\\fi-360\\li720\\sa200\\sl276\\slmult1 Writing RTF Text to the EHR's Text Box\\par"
+ "}";
}
private void RunTestFour()
{
if (!this.warned)
{
MessageBox.Show("Once you push 'Ok', you will have 5 seconds to click into your EHR's main Text Box.");
this.ShowTestCountdown();
}
else
{
// Write our text to the EHR via the clipboard
Clipboard.SetText(this.ourText.Rtf, TextDataFormat.Rtf);
EHRText.SetActiveWindowElementToClipboardContents();
Clipboard.Clear(); // just for sanity
// Read back the text via the clipboard (temporary until the other direct method works)
EHRText.SetClipboardContentsToActiveWindowElement();
// Set the right side text to what we read
this.theirText.Rtf = Clipboard.GetText(TextDataFormat.Rtf);
if (this.theirText.Rtf.Contains(this.ourText.Rtf))
{
this.PrintPossibleSuccess();
}
else
{
this.PrintPossibleFailure();
}
}
}
private void SetupTestFive()
{
this.testNumber.Text = "Test Number: 5";
this.testDescription.Text = "These last tests are more complicated. We need to test a better method for READING RTF from the Text Area inside the EHR Application. \r\nTo do this, YOU will need to manually insert text into the EHR Application. The RTF on the left side below has been copied to your clipboard. \r\nPlease open your EHR Application and PASTE the RTF into the normal working area. It should have the same color and formatting as the text seen below. \r\n\r\nThe test will attempt to read text from the EHR Application via the Windows API and place it on the right side. \r\nSuccess is when the right side contains the text from the left with the same coloring and formatting.";
this.ourText.Rtf = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Calibri;}{\\f1\\fnil\\fcharset2 Symbol;}}"
+ "{\\colortbl ;\\red255\\green0\\blue0;\\red0\\green176\\blue80;}"
+ "{\\*\\generator Msftedit 5.41.21.2510;}\\viewkind4\\uc1\\pard\\sa200\\sl276\\slmult1\\cf1\\lang9\\ul\\b\\f0\\fs22 Test Five\\cf0\\ulnone\\b0\\par"
+ "\\cf2\\i Rich Text Test\\par"
+ "\\cf0\\i0 This test tests the following:\\par"
+ "\\pard{\\pntext\\f1\\'B7\\tab}{\\*\\pn\\pnlvlblt\\pnf1\\pnindent0{\\pntxtb\\'B7}}\\fi-360\\li720\\sa200\\sl276\\slmult1 Reading RTF Text from the EHR's Text Box via the Windows API\\par"
+ "}";
Clipboard.SetText(this.ourText.Rtf, TextDataFormat.Rtf);
}
private void RunTestFive()
{
if (!this.warned)
{
MessageBox.Show("Please make sure you have pasted the text from the left box into your EHR Application. \nOnce you push 'Ok', you will have 5 seconds to click into your EHR's main Text Box.");
this.ShowTestCountdown();
}
else
{
Clipboard.Clear();
string readRtf = EHRText.GetRTFFromActiveWindowElement();
this.theirText.Rtf = readRtf;
}
}
private void SetupTestSix()
{
this.testNumber.Text = "Test Number: 6";
this.testDescription.Text = "Finally we need to test a better method for WRITING RTF to the Text Area inside the EHR Application. \r\nTo do this, WE will need to insert text into the EHR Application. \r\n\r\nThis test will attempt to write the RTF from the left side below into your EHR's Text Box via the Windows API. It will then read back your EHR's text and paste the read in value to the right side below. \r\nSuccess is when the right, left side, and the EHR Application contain the same text with the same coloring and formatting.";
this.ourText.Rtf = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Calibri;}{\\f1\\fnil\\fcharset2 Symbol;}}"
+ "{\\colortbl ;\\red255\\green0\\blue0;\\red0\\green176\\blue80;}"
+ "{\\*\\generator Msftedit 5.41.21.2510;}\\viewkind4\\uc1\\pard\\sa200\\sl276\\slmult1\\cf1\\lang9\\ul\\b\\f0\\fs22 Test Six\\cf0\\ulnone\\b0\\par"
+ "\\cf2\\i Rich Text Test\\par"
+ "\\cf0\\i0 This test tests the following:\\par"
+ "\\pard{\\pntext\\f1\\'B7\\tab}{\\*\\pn\\pnlvlblt\\pnf1\\pnindent0{\\pntxtb\\'B7}}\\fi-360\\li720\\sa200\\sl276\\slmult1 Writing RTF Text to the EHR's Text Box via the Windows API\\par"
+ "}";
}
private void RunTestSix()
{
if (!this.warned)
{
MessageBox.Show("Once you push 'Ok', you will have 5 seconds to click into your EHR's main Text Box.");
this.ShowTestCountdown();
}
else
{
//// Write our text to the EHR
//EHRText.SetTextOfActiveWindowElement(ourText.Text);
//// Read the text back from the EHR Application
//string readText = EHRText.GetTextFromActiveWindowElement();
//// Set the right side text to what we read
//this.theirText.Text = readText;
//if (this.theirText.Text.Equals(this.ourText.Text))
//{
// this.PrintPossibleSuccess();
//}
//else
//{
// this.PrintPossibleFailure();
//}
this.PrintPossibleFailure();
}
}
private void PrintPossibleSuccess()
{
MessageBox.Show("It looks like the test was a success! \nIf you agree, please push the 'Success' button and continue.");
}
private void PrintPossibleFailure()
{
MessageBox.Show("It looks like the test was a failure, HOWEVER, we do get false detection when indeed the test did pass (due to stray white spaces) \nIf you agree this test failed, please push the 'Faied' button and report the issue. \nBut if you believe the test passed, please push the 'Success' button.");
}
private void ShowTestCountdown()
{
this.testCountdown.Text = "Test will begin in: " + ticks + " seconds";
this.testCountdown.Enabled = true;
this.testCountdown.Visible = true;
this.warned = true;
this.timer1.Start();
}
private void EnableRunButton()
{
this.runButton.Visible = true;
this.runButton.Enabled = true;
this.successButton.Enabled = false;
this.successButton.Visible = false;
this.failedButton.Enabled = false;
this.failedButton.Visible = false;
}
private void EnableResultButtons()
{
this.runButton.Visible = false;
this.runButton.Enabled = false;
this.successButton.Enabled = true;
this.successButton.Visible = true;
this.failedButton.Enabled = true;
this.failedButton.Visible = true;
}
private void runButton_Click(object sender, EventArgs e)
{
this.runButton.Enabled = false;
this.runButton.Visible = false;
switch (this.currentTestNumber)
{
case 1:
RunTestOne();
break;
case 2:
RunTestTwo();
break;
case 3:
RunTestThree();
break;
case 4:
RunTestFour();
break;
case 5:
RunTestFive();
break;
case 6:
RunTestSix();
break;
default:
EnableRunButton();
break;
}
}
private void ContinueCurrentTest()
{
this.EnableResultButtons();
this.currentTest();
}
private void SetupNextTest()
{
this.warned = false;
this.EnableRunButton();
this.ourText.Text = "";
this.theirText.Text = "";
switch (this.currentTestNumber)
{
case 0:
this.currentTestNumber = 1;
this.currentTest = RunTestOne;
SetupTestOne();
break;
case 1:
this.currentTestNumber = 2;
this.currentTest = RunTestTwo;
SetupTestTwo();
break;
case 2:
this.currentTestNumber = 3;
this.currentTest = RunTestThree;
SetupTestThree();
break;
case 3:
this.currentTestNumber = 4;
this.currentTest = RunTestFour;
SetupTestFour();
break;
case 4:
this.currentTestNumber = 5;
this.currentTest = RunTestFive;
SetupTestFive();
break;
case 5:
this.currentTestNumber = 6;
this.currentTest = RunTestSix;
SetupTestSix();
break;
case numberOfTests:
ShowResults();
break;
default:
break;
}
}
private void ShowResults()
{
this.runButton.Enabled = false;
this.runButton.Visible = false;
this.successButton.Enabled = false;
this.successButton.Visible = false;
this.failedButton.Enabled = false;
this.failedButton.Visible = false;
this.testNumber.Text = "Test Number: Done";
this.testDescription.Text = "Thank you for running all of our tests. \r\nPlease report back the below results.";
this.ourText.Text = "Results: \r\n\r\n" + String.Join(", ", this.results);
if (Array.TrueForAll(this.results, IsSuccess))
{
this.theirText.Text = "Good!";
}
else
{
this.theirText.Text = "Bad...";
}
}
private bool IsSuccess(bool value)
{
return value;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (this.currentTick >= ticks)
{
this.timer1.Stop();
this.currentTick = 0;
this.testCountdown.Enabled = false;
this.testCountdown.Visible = false;
this.ContinueCurrentTest();
}
else
{
this.currentTick++;
this.testCountdown.Text = "Test will begin in: " + (ticks - this.currentTick) + " seconds";
}
}
private void successButton_Click(object sender, EventArgs e)
{
this.results[this.currentTestNumber] = true;
this.SetupNextTest();
}
private void failedButton_Click(object sender, EventArgs e)
{
this.results[this.currentTestNumber] = false;
this.SetupNextTest();
}
}
}