source: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet.Tools.ComponentTestBench/ComponentTestBenchMainWindow.cs@ 1148

Last change on this file since 1148 was 1146, checked in by Sam Habiel, 14 years ago

Initial Import of BMX4

File size: 19.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Text;
7using System.Windows.Forms;
8using IndianHealthService.BMXNet.WinForm;
9using IndianHealthService.BMXNet.WinForm.Configuration;
10using System.Reflection;
11using System.IO;
12using IndianHealthService.BMXNet.Model;
13using IndianHealthService.BMXNet.WinForm.Model;
14using IndianHealthService.BMXNet.Services;
15using IndianHealthService.BMXNet.Net;
16using IndianHealthService.BMXNet.Util;
17
18namespace IndianHealthService.BMXNet.Tools.ComponentTestBench
19{
20 public partial class ComponentTestBenchMainWindow : Form
21 {
22
23 public ComponentTestBenchMainWindow(UserControl aControl)
24 {
25 InitializeComponent();
26 this.ConstructorProvidedControl = aControl;
27 }
28
29 public ComponentTestBenchMainWindow()
30 {
31 InitializeComponent();
32 }
33
34 private UserControl _constructorProvidedControl = null;
35
36 public UserControl ConstructorProvidedControl
37 {
38 get { return _constructorProvidedControl; }
39 set { _constructorProvidedControl = value; }
40 }
41
42 private WinFramework _framework = null;
43
44 public WinFramework Framework
45 {
46 get { return _framework; }
47 set { _framework = value; }
48 }
49
50 private RemoteSession _remoteSession = null;
51
52 public RemoteSession RemoteSession
53 {
54 get { return _remoteSession; }
55 set { _remoteSession = value; }
56 }
57
58
59 private void WindowsApplicationMainWindow_Load(object sender, EventArgs e)
60 {
61 bool usePrimarySession = this.Framework == null;
62
63 if (this.Framework == null)
64 {
65 this.Framework = WinFramework.CreateWithNetworkBroker(true,(Log)this.logTranscriptControl1);
66 this.Framework.HardCodedSettings.Set("SetHardcodedSettingsHereOrAnywhere", "Hello");
67 //Settings are tierted ... Command-line / Persistent / hardcoded
68 this.Framework.LoadSettings(LocalPersistentStore.CreateIn(Environment.SpecialFolder.LocalApplicationData, EntryAssemblyInfo.AssemblyCompany + "/" + EntryAssemblyInfo.AssemblyProduct, false), "settings");
69 this.Framework.LoadConnectionSpecs(LocalPersistentStore.CreateIn(Environment.SpecialFolder.LocalApplicationData, EntryAssemblyInfo.AssemblyCompany + "/" + EntryAssemblyInfo.AssemblyProduct, false), "connections");
70
71 if (this.Framework.ConnectionSettings.ConnectionSpecs.Count == 0)
72 {
73 try
74 {
75 Assembly priorAssembly = Assembly.LoadFrom("PriorBmxForEvidence/BMXNet30.dll");
76 this.Framework.LoadConnectionSpecsAndMergeWithExistingBMXConfiguration(priorAssembly, LocalPersistentStore.CreateDefaultStorage(true), "MyApplication", "v5");
77 }
78 catch
79 {
80 }
81 }
82
83 LoginProcess login = this.Framework.CreateLoginProcess();
84 login.AttemptingLogin += new EventHandler<AttemptingLoginEventArgs>(login_AttemptingLogin);
85
86 login.LoginAttempted += new EventHandler<LoginAttemptedEventArgs>(login_LoginAttempted);
87 if (login.HasDefaultConnectionWithUseWindowsAuth)
88 {
89 login.AttemptWindowsAuthLogin();
90 }
91
92 if (!login.WasLoginAttempted || !login.WasSuccessful)
93 {
94 login.AttemptUserInputLogin("BMXNet Testbench Login", 3, !this.Framework.BootStrapSettings.Get("lockedit", false), this);
95 }
96
97 if (!login.WasSuccessful)
98 {
99 this.Close();
100 return;
101 }
102 LocalSession local = this.Framework.LocalSession;
103
104 if ((this.Framework.User.Division==null) && !this.Framework.AttemptUserInputSetDivision("Set Initial Division", this))
105 {
106 this.Close();
107 return;
108 }
109 }
110
111 if (usePrimarySession) {
112 this.RemoteSession =this.Framework.PrimaryRemoteSession;
113 } else {
114 this.RemoteSession = this.Framework.RemoteSessionPool.OpenSession((Log)this.logTranscriptControl1);
115 this.changeUserToolStripMenuItem.Enabled = false;
116 }
117
118 this.RemoteSession.SendTimeout= 20000;
119 this.RemoteSession.ReceiveTimeout = 20000;
120
121 this.AddControl();
122
123 this.Framework.Context.Changed += new EventHandler<ContextChangedArgs>(Context_Changed);
124 this.currentCheckBox.Checked = this.Framework.BootStrapSettings.Get("CurrentVisit", true);
125 this.patientCombo.Focus();
126
127 this.UpdateTitle();
128 }
129
130 void login_AttemptingLogin(object sender, AttemptingLoginEventArgs e)
131 {
132 e.Process.ConnectionSpec.SendTimeout = 10000;
133 e.Process.ConnectionSpec.ReceiveTimeout= 10000;
134 }
135
136 /// <summary>
137 /// Example for providing another broker key so key can be routinely updated by application/broker
138 /// developers.
139 /// </summary>
140 /// <param name="aBroker"></param>
141 // protected void RekeyBroker(BMXNetBroker aBroker)
142 // {
143 // this.Framework.Broker.EncryptionProvider = BmxAdeEncryptionProvider.Keyed(new string[2]);
144 // }
145
146 void login_LoginAttempted(object sender, LoginAttemptedEventArgs e)
147 {
148 this.Framework.Log.Log("Bench", "Login", e.WasSuccessful ? "Succesful Login" : e.Process.FailureMessage);
149 e.Cancel = false;
150 }
151
152 private Context _managedContext = null;
153
154 public Context ManagedContext
155 {
156 get { return _managedContext; }
157 set { _managedContext = value; }
158 }
159
160 void Context_Changed(object sender, ContextChangedArgs e)
161 {
162 if (e.IsPatientChange)
163 {
164 if (e.IsPatientChange && e.AfterContext.Patient == null)
165 {
166 this.patientCombo.Items.Clear();
167 this.patientCombo.Text = "";
168 }
169 this.UpdateVisits();
170 }
171 }
172
173
174
175 private String _componentClassName;
176
177 public String ComponentClassName
178 {
179 get { return _componentClassName; }
180 set { _componentClassName = value; }
181 }
182 private String _componentAssemblyName;
183
184 public String ComponentAssemblyName
185 {
186 get { return _componentAssemblyName; }
187 set { _componentAssemblyName = value; }
188 }
189
190 private void AddControl(UserControl aControl)
191 {
192 try
193 {
194 (aControl as LocalConsumer).LocalSession = this.Framework.LocalSession;
195 (aControl as RemoteSessionConsumer).RemoteSession = this.RemoteSession;
196 aControl.Dock = DockStyle.Fill;
197
198 this.controlPanel.Controls.Clear();
199 this.controlPanel.Controls.Add(aControl);
200 }
201 catch (Exception problem)
202 {
203 this.Framework.LocalSession.Notify("Unable to create control from command line " + Environment.CommandLine,problem);
204 }
205 }
206
207 private void AddControl()
208 {
209 if (this.ConstructorProvidedControl != null)
210 {
211 this.AddControl(this.ConstructorProvidedControl);
212 }
213 else if (this.Framework.BootStrapSettings.Get("assembly", "").Length == 0)
214 {
215 return;
216 }
217 else
218 {
219 try
220 {
221 Assembly componentAssembly = Assembly.LoadFrom(this.Framework.BootStrapSettings.Get("assembly", ""));
222 UserControl control = (UserControl)componentAssembly.CreateInstance(this.Framework.BootStrapSettings.Get("class", ""));
223 this.AddControl(control);
224 }
225 catch
226 {
227 MessageBox.Show("Unable to create control from command line " + Environment.CommandLine);
228 }
229 }
230 }
231
232 private void button1_Click(object sender, EventArgs e)
233 {
234 AboutDialog dialog = new AboutDialog();
235 dialog.ShowDialog(this);
236 }
237
238
239 public Patient SelectedPatient
240 {
241 get { return (Patient)this.patientCombo.SelectedItem; }
242 }
243
244 private void patientCombo_SelectedIndexChanged(object sender, EventArgs e)
245 {
246 if (this.SelectedPatient == this.Framework.Context.Patient)
247 {
248 return;
249 }
250
251 if (!this.Framework.ChangePatient(this.SelectedPatient, this.overrideContextVeto.Checked))
252 {
253 this.Framework.LocalSession.Notify("Patient Change Vetoed", "Unable to change patient");
254 this.patientCombo.SelectedItem = this.Framework.Context.Patient;
255 }
256 }
257
258 private void UpdateVisits()
259 {
260 this.visitComboBox.BeginUpdate();
261 this.visitComboBox.Items.Clear();
262 if (this.SelectedPatient != null)
263 {
264 List<Visit> visits = this.Framework.Visits(this.SelectedPatient, 20);
265 this.visitComboBox.Items.AddRange(visits.ToArray());
266 this.visitComboBox.SelectedIndex = (this.currentCheckBox.Checked ? Math.Min(visits.Count - 1, 0) : -1);
267 }
268 this.visitComboBox.EndUpdate();
269 }
270
271 private void findButton_Click(object sender, EventArgs e)
272 {
273 this.DoSearch();
274 }
275
276 protected void DoSearch()
277 {
278
279 List<Patient> found = this.Framework.FindPatients(this.patientCombo.Text.ToUpper(), 20);
280
281 this.patientCombo.BeginUpdate();
282 this.patientCombo.Items.Clear();
283 foreach (Patient each in found)
284 {
285 this.patientCombo.Items.Add(each);
286 }
287
288 if (found.Count == 1)
289 {
290 this.patientCombo.SelectedItem = found[0];
291 }
292 else if (found.Count == 0)
293 {
294 this.patientCombo.Text = "<No patients found>";
295 this.patientCombo.Focus();
296 }
297 else
298 {
299 this.patientCombo.Text = found.Count.ToString() + " patients found...";
300 }
301
302 this.patientCombo.EndUpdate();
303 }
304
305 private void patientCombo_KeyDown(object sender, KeyEventArgs e)
306 {
307 if (e.KeyCode == Keys.Enter)
308 {
309 this.DoSearch();
310 }
311 }
312
313 private void resetButton_Click(object sender, EventArgs e)
314 {
315 this.Framework.ChangePatient(this.Framework.Context.Patient,this.overrideContextVeto.Checked);
316 }
317
318 private void refreshButton_Click(object sender, EventArgs e)
319 {
320 this.Framework.TriggerLocalEvent("REFRESH", "UserSelected");
321 }
322
323 public Visit SelectedVisit
324 {
325 get { return (Visit)this.visitComboBox.SelectedItem; }
326 }
327
328
329 private void visitComboBox_SelectedIndexChanged(object sender, EventArgs e)
330 {
331 if (this.SelectedVisit == this.Framework.Context.Visit)
332 {
333 return;
334 }
335
336 if (!this.Framework.ChangeVisit(this.SelectedVisit, this.overrideContextVeto.Checked))
337 {
338 this.Framework.LocalSession.Notify("Visit Change Vetoed", "Unable to change visit");
339 this.visitComboBox.SelectedItem = this.Framework.Context.Visit;
340 }
341 }
342
343 private void divisionButton_Click(object sender, EventArgs e)
344 {
345 if (this.Framework.AttemptUserInputSetDivision("Change Divsion @ " + DateTime.Now.ToLongTimeString(), this))
346 {
347 this.patientCombo.Items.Clear();
348 this.patientCombo.Text = null;
349 this.patientCombo.Focus();
350 }
351
352 }
353
354 private void keyEntry_TextChanged(object sender, EventArgs e)
355 {
356 this.keyEntry.BackColor = Color.White;
357 }
358
359 private void keyButton_Click(object sender, EventArgs e)
360 {
361 this.keyEntry.BackColor = this.Framework.User.HasSecurityKey(this.keyEntry.Text.Trim()) ? Color.LightGreen : Color.Red;
362 }
363
364 private void aboutDialogToolStripMenuItem_Click(object sender, EventArgs e)
365 {
366 new AboutDialog().ShowDialog(this);
367 }
368
369 private void bMXVersionInfoToolStripMenuItem_Click(object sender, EventArgs e)
370 {
371 // DataTable peek = this.Framework.Bmx.VersionInfo;
372 this.NotYetImplemented();
373 }
374
375 private void NotYetImplemented()
376 {
377 MessageBox.Show("Not yet implement", "Demo App Message");
378 }
379
380 private void WindowsApplicationMainWindow_FormClosing(object sender, FormClosingEventArgs e)
381 {
382 if (this.RemoteSession != null)
383 {
384 this.RemoteSession.Close();
385 }
386 }
387
388 private void spawnSessionToolStripMenuItem_Click(object sender, EventArgs e)
389 {
390 ComponentTestBenchMainWindow window = new ComponentTestBenchMainWindow();
391 window.Framework = this.Framework;
392 window.Show();
393 }
394
395 public void UpdateTitle()
396 {
397 this.Text = "BMXNet Testbench :: " + this.RemoteSession.ToString();
398 }
399
400 private void closeRemoteSessionToolStripMenuItem_Click(object sender, EventArgs e)
401 {
402 this.RemoteSession.Close();
403 }
404
405 private void remoteTriggerButton_Click(object sender, EventArgs e)
406 {
407 String eventName = this.remoteEventTriggerCombo.Text.Trim();
408 String eventParam = this.remoteParamTriggerCombo.Text.Trim();
409
410 if (eventName.Length > 0)
411 {
412 int result = this.RemoteSession.EventServices.TriggerEvent(eventName, eventParam, this.remoteCallBackCheck.Checked);
413 }
414 }
415
416 private void localTriggerButton_Click(object sender, EventArgs e)
417 {
418 String eventName = this.localEventTriggerCombo.Text.Trim();
419 String eventParam = this.localParamTriggerCombo.Text.Trim();
420
421 if (eventName.Length > 0)
422 {
423 this.Framework.TriggerLocalEvent(eventName, eventParam);
424 }
425 }
426
427 private void logViewerToolStripMenuItem_Click(object sender, EventArgs e)
428 {
429 this.showLogTranscriptToolStripMenuItem.Checked = !this.showLogTranscriptToolStripMenuItem.Checked;
430 this.componentTranscriptSplitter.Panel2Collapsed = !this.showLogTranscriptToolStripMenuItem.Checked;
431 }
432
433 private void openToolStripMenuItem_Click(object sender, EventArgs e)
434 {
435 Type componentType = null;
436 OpenFileDialog open = new OpenFileDialog();
437 open.Filter = "BMX Component (*.dll)|*.dll";
438 if (open.ShowDialog(this) == DialogResult.OK)
439 {
440 //Find RemoteConsumer or LocalConsumer
441 Assembly target = Assembly.LoadFile(open.FileName);
442 foreach (Type each in target.GetTypes())
443 {
444 foreach (Type eachInterface in each.GetInterfaces())
445 {
446 if (eachInterface.Equals(typeof(LocalConsumer)) || eachInterface.Equals(typeof(RemoteSessionConsumer)))
447 {
448 componentType = each;
449 break;
450 }
451 }
452 if (componentType != null)
453 {
454 break;
455 }
456 }
457 }
458 if (componentType != null)
459 {
460 this.AddControl((UserControl)Activator.CreateInstance(componentType));
461 }
462 }
463
464 private void changeDivisionToolStripMenuItem_Click(object sender, EventArgs e)
465 {
466 this.Framework.AttemptUserInputSetDivision("Reset Division", this);
467 }
468
469 private void changeUserToolStripMenuItem_Click(object sender, EventArgs e)
470 {
471 this.Framework.Close();
472 this.controlPanel.Controls.Clear();
473
474 this.Framework = WinFramework.CreateWithNetworkBroker(true, (Log)this.logTranscriptControl1);
475 this.Framework.LoadSettings(LocalPersistentStore.CreateIn(Environment.SpecialFolder.LocalApplicationData, EntryAssemblyInfo.AssemblyCompany + "/" + EntryAssemblyInfo.AssemblyProduct, false), "settings");
476 this.Framework.LoadConnectionSpecs(LocalPersistentStore.CreateIn(Environment.SpecialFolder.LocalApplicationData, EntryAssemblyInfo.AssemblyCompany + "/" + EntryAssemblyInfo.AssemblyProduct, false), "connections");
477
478 if (this.Framework.ConnectionSettings.ConnectionSpecs.Count == 0)
479 {
480 try
481 {
482 Assembly priorAssembly = Assembly.LoadFrom("PriorBmxForEvidence/BMXNet30.dll");
483 this.Framework.LoadConnectionSpecsAndMergeWithExistingBMXConfiguration(priorAssembly, LocalPersistentStore.CreateDefaultStorage(true), "MyApplication", "v5");
484 }
485 catch
486 {
487 }
488 }
489
490 LoginProcess login = this.Framework.CreateLoginProcess();
491
492 login.IsSwitchServerModeEnabled = true;
493 login.LoginAttempted += new EventHandler<LoginAttemptedEventArgs>(login_LoginAttempted);
494 login.AttemptUserInputLogin("BMXNet Testbench Login", 3, true, this);
495
496 if (!login.WasSuccessful)
497 {
498 this.Close();
499 return;
500 }
501 LocalSession local = this.Framework.LocalSession;
502
503 if (!this.Framework.AttemptUserInputSetDivision("Set Initial Division", this))
504 {
505 this.Close();
506 return;
507 }
508
509 this.RemoteSession = this.Framework.PrimaryRemoteSession;
510
511 this.AddControl();
512
513 this.Framework.Context.Changed += new EventHandler<ContextChangedArgs>(Context_Changed);
514 this.currentCheckBox.Checked = this.Framework.BootStrapSettings.Get("CurrentVisit", true);
515 this.patientCombo.Focus();
516
517 this.UpdateTitle();
518 }
519
520
521
522
523 }
524}
Note: See TracBrowser for help on using the repository browser.