/[AnywhereTS-MSSQL]/trunk/TSAdminTool/frmAdmin.cs
ViewVC logotype

Contents of /trunk/TSAdminTool/frmAdmin.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 57 - (show annotations) (download)
Thu Jul 12 16:47:17 2012 UTC (8 years, 6 months ago) by william
File size: 44237 byte(s)
move appdomain unhandled exception clause to the forms that are called by program.cs

1 namespace AnywhereTS
2 {
3 using System;
4 using System.Collections.Generic;
5 using System.ComponentModel;
6 using System.Data;
7 using System.Drawing;
8 using System.Text;
9 using System.Windows.Forms;
10 using System.Runtime.InteropServices;
11 using System.IO;
12 using System.Data.SqlClient; // For File operations
13
14
15 public partial class frmAdmin : Form
16 {
17 // Data variables
18
19 //DatabaseSupport dataSupport;
20 private atsDataSet datasetAllClients; // Dataset containing all clients
21 private atsDataSet datasetLicensedClients; // Dataset containing only the licensed clients, sorted in order of creation
22
23 private string selectedClientMacAddress; // The MAC address of the currently selected client.
24 public frmAdmin()
25 {
26 InitializeComponent();
27 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
28 }
29
30 static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
31 {
32 Exception ex = (e.ExceptionObject as Exception);
33 if (ex == null)
34 {
35 Logging.ATSAdminLog.Error("Encountered unhandled Exception, but the exception was null");
36 return;
37 }
38 if (ex.GetType() == typeof(SqlException))
39 {
40 SqlException sql_ex = (ex as SqlException);
41 using (log4net.NDC.Push(string.Format("SqlException: ID={0} MESSAGE={1}{2}Diagnostics:{2}{3}", sql_ex.Number.ToString(), sql_ex.Message, System.Environment.NewLine, sql_ex.ToString())))
42 {
43 Logging.ATSAdminLog.Error("Encountered unhandled SqlException");
44 }
45 }
46 else
47 {
48 using (log4net.NDC.Push(string.Format("Exception: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
49 {
50 Logging.ATSAdminLog.Error("Encountered unhandled Exception");
51 }
52 }
53 }
54
55 private void frmAdmin_Load(object sender, EventArgs e)
56 {
57 this.Cursor = Cursors.WaitCursor;
58
59 UpdateControlsToReflectProgramVersion();
60
61 // Check if AnywhereTS is configured
62 if (ATSGlobals.configured == 0 || ATSGlobals.managedMode == 0)
63 { // ATS is not configured, configure
64 if (!ConfigureATS())
65 {
66 // ATS still not configured, abort
67 MessageBox.Show("You cannot run AnywhereTS without configuring it first.");
68 Application.Exit();
69 return;
70 }
71 }
72
73 // Setup controls and database
74 SetMode();
75
76 helpProvider.HelpNamespace = ATSGlobals.strHelpFilePath; // Initiate helpProvider
77
78 treeView.Nodes[1].Expand(); // Expand terminal servers node.
79
80 this.Cursor = Cursors.Default;
81
82 // Create a default record
83 ATSImageDesigntimeConfig newConfig = new ATSImageDesigntimeConfig();
84 newConfig.ReadDefaultFromDatabase();
85 newConfig.WriteDefaultsToDatabase();
86 } // form load
87
88 private void UpdateControlsToReflectProgramVersion()
89 {
90 // Update the application to reflect the type of license and release
91 ATSGlobals.isPro = true;
92 Globals.isPro = ATSGlobals.isPro; // Update program status for the VB part of the application.
93 // We are running in Pro Mode, add 'Open Source' to the Application name
94 ATSGlobals.ApplicationTitle = ATSGlobals.ApplicationName + " Open Source Version";
95
96 this.Text = ATSGlobals.ApplicationTitle; // Set name in window title
97 aboutToolStripMenuItem.Text = "About " + ATSGlobals.ApplicationTitle;
98 }
99
100 // Update database from terminal server sessions
101 private void UpdateClientsFromSession()
102 {
103 List<TSManager.TS_SESSION_INFO> Sessions;
104 Sessions = TSManager.ListSessions();
105 foreach (TSManager.TS_SESSION_INFO session in Sessions)
106 {
107 if (session.macAddress != "")
108 { // The client is an (Un-named) ATS client. We have a MAC address.
109
110 // Does the MAC adress for the session alreay exist in database?
111 if (datasetAllClients.Client.Rows.Find(session.macAddress) == null)
112 {
113 // The MAC address did not exist in database. Add the client, using properties from the default record.
114 DataRow newRow = datasetAllClients.Client.NewRow();
115 ATSImageRuntimeConfig newConfig = new ATSImageRuntimeConfig();
116 newConfig.ReadDefaultFromDatabase();
117 newConfig.WriteToDatabase(newRow);
118 newRow["macAddress"] = session.macAddress;
119 newRow["clientName"] = session.name;
120 datasetAllClients.Client.Rows.Add(newRow);
121 }
122 }
123 }
124 ProSupport.clientTableAdapter.Update(datasetAllClients.Client);
125 }
126
127
128 // Update the tree control and database from sessions
129 private void UpdateTree()
130 {
131 this.Cursor = Cursors.WaitCursor;
132
133 // Update the environment
134 AtsEnvironment.Refresh();
135 // Update general statistics
136 lblNoOfTS.Text = AtsEnvironment.TerminalServers.Count.ToString();
137 lblNoOfSessions.Text = AtsEnvironment.Sessions.Count.ToString();
138
139 // Get records from the database.
140 FillLicensedClients(datasetLicensedClients);
141 // Poulate a dataset with all clients (regardless of license) and default record for reference.
142 ProSupport.clientTableAdapter.FillClients(datasetAllClients.Client);
143
144 UpdateClientsFromSession();
145
146 // Update the no of clients text
147 if (datasetAllClients.Client.Rows.Count == 0)
148 {
149 rtxWelcome.Visible = true;
150 lblRoot.Text = "Welcome to " + ATSGlobals.ApplicationName + "!";
151 tlpGeneralData.Visible = false;
152 }
153 else
154 {
155 rtxWelcome.Visible = false;
156 lblRoot.Text = "Summary Statistics";
157 tlpGeneralData.Visible = true;
158 lblNoOfClients.Text = datasetAllClients.Client.Rows.Count.ToString();
159 }
160
161 // Add clients to the tree
162 treeView.Nodes[0].Nodes.Clear(); // Clear the clients node
163 foreach (DataRow row in datasetLicensedClients.Client.Rows)
164 {
165 AtsSession session; // Session for the current client
166 TreeNode addedNode;
167
168 session = TSManager.GetSession(row["MacAddress"].ToString());
169 if (session != null && session.username.Length > 0)
170 {
171 // There is a user name for the client, display client name and user name.
172 addedNode = treeView.Nodes[0].Nodes.Add(row["ClientName"].ToString() + " (" + session.username + ")");
173 }
174 else
175 {
176 // There is no user name for the client, just add client name.
177 addedNode = treeView.Nodes[0].Nodes.Add(row["ClientName"].ToString());
178 }
179
180 // Select the appropriate bitmap to show for the node according to its status.
181 // Default is disconnected, so no need to indicate that.
182 if (session != null)
183 {
184 // There is a session for the client
185 if (session.username.Length > 0)
186 { // There is a user logged in
187 addedNode.ImageIndex = 3;
188 addedNode.SelectedImageIndex = 3;
189 }
190 else
191 { // The session has no user
192 addedNode.ImageIndex = 2;
193 addedNode.SelectedImageIndex = 2;
194 }
195
196 } // if client has session
197 addedNode.ContextMenuStrip = contextMenuClient; // Add the context menu for the client. Enables to remove the client.
198
199 } // foreach client
200
201 ProSupport.WriteHostsFiles(); // Update the hosts files on all TFTP servers
202
203 // Add terminal servers to the tree
204 treeView.Nodes[1].Nodes.Clear(); // Clear the terminal server node
205 foreach (AtsTerminalServer ts in AtsEnvironment.TerminalServers)
206 {
207 // Add a terminal server to the tree
208 TreeNode addedServerNode;
209 if (ts.networkPath == "localhost")
210 {
211 addedServerNode = treeView.Nodes[1].Nodes.Add("This Computer");
212 }
213 else
214 {
215 addedServerNode = treeView.Nodes[1].Nodes.Add(ts.networkPath);
216 }
217 addedServerNode.ToolTipText = ts.strError;
218 if (ts.Online)
219 { // Display the online server icon
220 addedServerNode.ImageIndex = 5;
221 addedServerNode.SelectedImageIndex = 5;
222 }
223 else
224 { // Display the offline server icon
225 addedServerNode.ImageIndex = 6;
226 addedServerNode.SelectedImageIndex = 6;
227 }
228 //addedNode.ContextMenuStrip = contextMenuClient; // Add the context menu for the client. Enables to remove the client.
229
230 // Add sessions for the terminal server to the tree.
231 foreach (AtsSession session in ts.Session)
232 {
233 string sessionText;
234 int imageIndex;
235 if (session.sessionID == 0)
236 { // This is a console session
237 sessionText = "Console";
238 if (session.username.Length != 0)
239 { // Session has a username
240 sessionText += " (" + session.username + ")";
241 }
242 imageIndex = 7; // Display the active session icon
243 }
244 else if (session.sessionID == 65536)
245 { // This is the listener session
246 sessionText = "Listener";
247 imageIndex = 8; // Display the non-active session icon
248 }
249 else
250 { // This is a "normal" session
251 sessionText = session.sessionID.ToString() + " " + (session.username.Length != 0 ? " (" + session.username + ")" : "");
252 if (session.state == TSManager.WTS_CONNECTSTATE_CLASS.WTSActive)
253 { // Display the active session icon
254 imageIndex = 7;
255 }
256 else
257 { // Display the non-active session icon
258 imageIndex = 8;
259 }
260 }
261 TreeNode addedSessionNode;
262 addedSessionNode = addedServerNode.Nodes.Add(sessionText);
263 addedSessionNode.ImageIndex = imageIndex;
264 addedSessionNode.SelectedImageIndex = imageIndex;
265 addedSessionNode.Tag = session;
266 //addedNode.ContextMenuStrip = contextMenuClient; // Add the context menu for the client. Enables option to remove the client.
267 } // foreach session
268
269 } // foreach terminal server
270
271 // Add sesions to the tree
272 treeView.Nodes[2].Nodes.Clear(); // Clear the sessions node
273 foreach (AtsSession session in AtsEnvironment.Sessions)
274 {
275 string sessionText;
276 int imageIndex;
277 if (session.sessionID == 0)
278 { // This is a console session
279 sessionText = "Console";
280 if (session.username.Length != 0)
281 { // Session has a username
282 sessionText += " (" + session.username + ")";
283 }
284 imageIndex = 7; // Display the active session icon
285 }
286 else if (session.sessionID == 65536)
287 { // This is the listener session
288 sessionText = "Listener";
289 imageIndex = 8; // Display the non-active session icon
290 }
291 else
292 { // This is a "normal" session
293 if (session.username.Length != 0)
294 { // Session has a username
295 sessionText = session.username;
296 }
297 else
298 { // Session does not have a username
299 sessionText = "Not logged on";
300 }
301 // Select the icon to display
302 if (session.state == TSManager.WTS_CONNECTSTATE_CLASS.WTSActive)
303 { // Display the active session icon
304 imageIndex = 7;
305 }
306 else
307 { // Display the non-active session icon
308 imageIndex = 8;
309 }
310 }
311 // Add terminal server name if we have more than one terminal server
312 if (AtsEnvironment.TerminalServers.Count > 1)
313 { // We have more than one terminal server, display the name of the terminal server
314 sessionText += " (" + session.TerminalServerName + ")";
315 }
316
317 TreeNode addedSessionNode;
318 addedSessionNode = treeView.Nodes[2].Nodes.Add(sessionText);
319 addedSessionNode.ImageIndex = imageIndex;
320 addedSessionNode.SelectedImageIndex = imageIndex;
321 addedSessionNode.Tag = session;
322 //addedNode.ContextMenuStrip = contextMenuClient; // Add the context menu for the client. Enables option to remove the client.
323 } // foreach session
324
325 // Select the root node
326 treeView.SelectedNode = treeView.Nodes[0];
327 NodeSelected(treeView.Nodes[0]); // Update related controls
328
329 this.Cursor = Cursors.Default;
330 }
331
332 private void FillLicensedClients(atsDataSet dataset)
333 {
334 ProSupport.clientTableAdapter.FillClients(dataset.Client);
335 }
336
337 private void toolStripAddClient_Click(object sender, EventArgs e)
338 {
339 AddClient();
340 }
341
342 // Refresh database and controls
343 private void toolStripButtonRefresh_Click(object sender, EventArgs e)
344 {
345 UpdateTree();
346 }
347
348
349 private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
350 {
351 this.Cursor = Cursors.WaitCursor;
352 TreeNode selectedNode = e.Node;
353 NodeSelected(selectedNode);
354 this.Cursor = Cursors.Default;
355 }
356
357 private void NodeSelected(TreeNode node)
358 {
359 if (node.Parent != null)
360 {
361 // A child node selected in the tree view
362
363 if (node.Parent.Name == "nodeClients")
364 { // A client node is selected in the tree view.
365
366 // A client was selected in the tree
367
368 // Enable the delete tool button.
369 toolStripButtonDelete.Enabled = true;
370 deleteClientToolStripMenuItem.Enabled = true;
371
372 // Display client data
373 AtsSession sessionInfo; // Session info for the client that was selected in the tree
374 selectedClientMacAddress = datasetLicensedClients.Client.Rows[node.Index]["MacAddress"].ToString();
375 //selectedConfig.ReadFromDatabase(datasetClient.Client.Rows[e.Node.Index]);
376
377 lblClientName.Text = datasetLicensedClients.Client.Rows[node.Index]["ClientName"].ToString();
378 lblMacAddress.Text = selectedClientMacAddress;
379 lblConnectionType.Text = datasetLicensedClients.Client.Rows[node.Index]["SessionType"].ToString();
380 lblResolution.Text = datasetLicensedClients.Client.Rows[node.Index]["ScreenResolution"].ToString();
381 lblColorDepth.Text = datasetLicensedClients.Client.Rows[node.Index]["ScreenColorDepth"].ToString();
382
383 sessionInfo = TSManager.GetSession(selectedClientMacAddress);
384 if (sessionInfo != null)
385 {
386 // Display the session data for the selected client
387 UpdateSessionPanel(sessionInfo);
388 }
389 else
390 {
391 // There is no session for the selected client
392 tlpSessionDetails.Visible = false;
393 lblClientHasNoSession.Visible = true;
394 }
395 // Display the client panelValue
396 pnlClientSession.Visible = true;
397 pnlDefault.Visible = false;
398 pnlClientDetails.Visible = true;
399 PositionClientSessionPanels(false); // Put the client panel over the session panel
400 propertiesToolStripMenuItem1.Enabled = true;
401 toolStripButtonProperties.Enabled = true;
402 } // end if client node selected
403
404 else if (node.Parent.Name == "nodeTerminalServers")
405 { // A terminal server is selected in the tree view
406 // Display the default panel
407 pnlDefault.Visible = true;
408 pnlClientSession.Visible = false;
409 // Disable the delete tool button.
410 toolStripButtonDelete.Enabled = false;
411 deleteClientToolStripMenuItem.Enabled = false;
412 propertiesToolStripMenuItem1.Enabled = false;
413 toolStripButtonProperties.Enabled = false;
414
415 }
416 else if (node.Parent.Name == "nodeSessions" || (node.Level == 2))
417 { // A session under the "Sesssions" node is selected in the tree view.
418 // Or a session under a terminal server node is selected in the tree view
419
420 // Display the session data
421 AtsSession session = (AtsSession)node.Tag;
422
423 PositionClientSessionPanels(true);
424 UpdateSessionPanel(session);
425
426 // Display the ClientSession panel
427 pnlClientSession.Visible = true;
428 pnlDefault.Visible = false;
429 // Hide client panel
430 pnlClientDetails.Visible = false;
431 }
432
433 else
434 { // Unhandled node
435 MessageBox.Show("Error: unhandled node (28843)");
436 using (log4net.NDC.Push(string.Format("unhandled node={0}", node.Parent.Name)))
437 {
438 Logging.ATSAdminLog.Error("rror: unhandled node (28843)");
439 }
440 }
441 }
442 else
443 {
444 // One of the root nodes is selected in the tree view.
445 // Display the default panel
446 pnlDefault.Visible = true;
447 pnlClientSession.Visible = false;
448
449 // Disable the delete tool button.
450 toolStripButtonDelete.Enabled = false;
451 deleteClientToolStripMenuItem.Enabled = false;
452 propertiesToolStripMenuItem1.Enabled = false;
453 toolStripButtonProperties.Enabled = false;
454 }
455 }
456
457 // Updates the session panel in the right pane with session data from the session in "session"
458 private void UpdateSessionPanel(AtsSession session)
459 {
460 tlpSessionDetails.Visible = true;
461 lblClientHasNoSession.Visible = false;
462 lblUserName.Text = session.username.Length != 0 ? session.username : "-";
463 lblSessionID.Text = session.sessionID.ToString();
464 lblState.Text = TSManager.StateToString(session.state);
465 lblIPAddress.Text = session.ipAddress.Length != 0 ? session.ipAddress : "-";
466 if (session.HorizontalResolution != 0)
467 {
468 lblSessionScreenResolution.Text = session.HorizontalResolution.ToString() + "x" + session.VerticalResolution.ToString();
469 }
470 else
471 { // No screen resolution
472 lblSessionScreenResolution.Text = "-";
473 }
474 }
475
476 // Position the panels for session info and client info.
477 // sessionOnTop = true > Place the session panel over the client panel.
478 // sessionOnTop = false > Place the client panel over the session panel.
479 private void PositionClientSessionPanels(bool sessionOnTop)
480 {
481 if (sessionOnTop)
482 {
483 pnlClientDetails.Top = 163;
484 pnlSessionDetails.Top = 3;
485 }
486 else
487 {
488 pnlClientDetails.Top = 3;
489 pnlSessionDetails.Top = 224;
490 }
491 }
492
493 private void btnDefault_Click(object sender, EventArgs e)
494 {
495 // Display client default properties dialog
496 ClientDefaultSettings();
497 }
498
499 private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
500 {
501 // Delete a client
502 DeleteClient();
503 }
504
505 // User clicked Properties on the client toolstrip
506 private void propertiesToolStripMenuItem_Click(object sender, EventArgs e)
507 {
508 // Display client properties
509 ClientProperties();
510 }
511
512 private void treeView_DoubleClick(object sender, EventArgs e)
513 {
514 //The user has double clicked a tree node
515 // The node will autmatically be selected on the mouse down event, so
516 // now the After_Select event has already been run and variables updated accordingly.
517
518
519 if (treeView.SelectedNode.Parent != null)
520 {
521 // A child node selected in the tree view
522 if (treeView.SelectedNode.Parent.Name == "nodeClients")
523 { // A client node is selected in the tree view.
524 // Check if a client is selected
525 if (treeView.SelectedNode.Name != "nodeLicenseWarning")
526 { // A client is selected in the tree
527 // Display client properties
528 ClientProperties();
529 }
530 }
531 else if (treeView.SelectedNode.Parent.Name == "nodeTerminalServers")
532 { // A terminal server is selected in the tree view
533
534 }
535 }
536 else
537 {
538 // The user has double clicked the root node.
539 }
540 }
541
542 private void treeView_KeyDown(object sender, KeyEventArgs e)
543 {
544 if (treeView.SelectedNode.Parent != null)
545 {
546 // A child node is selected in the tree view
547 if (treeView.SelectedNode.Parent.Name == "nodeClients")
548 { // A client node is selected in the tree view.
549 if (treeView.SelectedNode.Name != "nodeLicenseWarning")
550 { // A client is selected in the tree
551 if (e.KeyCode == Keys.Delete)
552 {
553 // Delete client
554 DeleteClient();
555 }
556 else if (e.KeyCode == Keys.Enter)
557 {
558 // Display client properties
559 ClientProperties();
560 }
561 }
562 }
563 }
564 }
565
566 // Display properties for the currently selected client
567 private void ClientProperties()
568 {
569 this.Cursor = Cursors.WaitCursor;
570
571 using (frmClientProperties objCustomDialogBox = new frmClientProperties())
572 {
573 objCustomDialogBox.macAddress = selectedClientMacAddress;
574 objCustomDialogBox.dialogMode = frmClientProperties.ATSClientMode.EDIT_CLIENT; // Select the mode to run the form in.
575 this.Cursor = Cursors.Default;
576
577 if (objCustomDialogBox.ShowDialog() == DialogResult.OK)
578 {
579 UpdateTree();
580 }
581 } // Unload frm
582 }
583
584 // Display the add client dialog and add a client
585 private void AddClient()
586 {
587 // Display client properties dialog in Add mode
588 this.Cursor = Cursors.WaitCursor;
589 frmClientProperties objCustomDialogBox = new frmClientProperties();
590 objCustomDialogBox.dialogMode = frmClientProperties.ATSClientMode.NEW_CLIENT; // Select the mode to run the form in.
591 this.Cursor = Cursors.Default;
592
593 if (objCustomDialogBox.ShowDialog() == DialogResult.OK)
594 {
595 UpdateTree();
596 }
597 objCustomDialogBox = null;
598 treeView.Nodes[0].Expand(); // Expand ATS client node, in order to show the newly added client
599 }
600
601 private void toolStripButtonAdd_Click(object sender, EventArgs e)
602 {
603 AddClient();
604 }
605
606 private void DeleteClient()
607 {
608 DialogResult result;
609 result = MessageBox.Show(this, "Are you sure you want to delete the client '" + lblClientName.Text + "'?", ATSGlobals.ApplicationName , MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
610 if (result == DialogResult.Yes)
611 {
612 this.Cursor = Cursors.WaitCursor;
613
614 // Delete the client
615 DataRow rowToDelete;
616
617 rowToDelete = datasetAllClients.Client.Rows.Find(selectedClientMacAddress);
618
619 if (rowToDelete != null)
620 {
621 // Delete the client database row.
622 rowToDelete.Delete();
623 ProSupport.clientTableAdapter.Update(datasetAllClients.Client);
624 UpdateTree();
625 // Delete the client config file.
626 string fileToDelete;
627 fileToDelete = ATSGlobals.strTFTPdir + @"\" + selectedClientMacAddress;
628 if (File.Exists(fileToDelete))
629 {
630 File.Delete(fileToDelete);
631 }
632 this.Cursor = Cursors.Default;
633
634 }
635 else
636 {
637 throw new Exception("Error: Cannot find record to delete (43556)");
638 }
639 }
640 }
641
642 // View and change default settings for all clients
643 private void ClientDefaultSettings()
644 {
645 // Display client default properties dialog
646 this.Cursor = Cursors.WaitCursor;
647
648 frmClientProperties objCustomDialogBox = new frmClientProperties();
649 objCustomDialogBox.macAddress = ProSupport.DEFAULT_RECORD_MAC;
650 objCustomDialogBox.dialogMode = frmClientProperties.ATSClientMode.EDIT_DEFAULT; // Select the mode to run the form in.
651 this.Cursor = Cursors.Default;
652
653 if (objCustomDialogBox.ShowDialog() == DialogResult.OK)
654 {
655 // Possible improvement: Did any parameters change?
656
657 // One of more parameters changed, save parameters to database.
658
659 UpdateTree();
660 }
661 objCustomDialogBox = null;
662 }
663
664 private void toolStripButtonDelete_Click(object sender, EventArgs e)
665 {
666 DeleteClient();
667 }
668
669 private void treeView_MouseDown(object sender, MouseEventArgs e)
670 {
671 if (treeView.GetNodeAt(e.X, e.Y) != null)
672 treeView.SelectedNode = treeView.GetNodeAt(e.X, e.Y);
673 }
674
675 private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
676 {
677 frmAboutPro objCustomDialogBox = new frmAboutPro();
678 objCustomDialogBox.ShowDialog();
679 }
680
681 private void anywhereTSHomepageToolStripMenuItem_Click(object sender, EventArgs e)
682 {
683 wizardSupport.AnywhereTSHomepage();
684 }
685
686 private void exitToolStripMenuItem_Click(object sender, EventArgs e)
687 {
688 Application.Exit();
689 }
690
691 private void cDToolStripMenuItem_Click(object sender, EventArgs e)
692 {
693 wizardSupport.PXEBootType = wizardSupport.PXEBootTask.PXE_Boot_CD;
694 wizardSupport.PXEBoot();
695 }
696
697 private void floppyToolStripMenuItem_Click(object sender, EventArgs e)
698 {
699 wizardSupport.PXEBootType = wizardSupport.PXEBootTask.PXE_Boot_Floppy;
700 wizardSupport.PXEBoot();
701 }
702
703 private void addClientToolStripMenuItem_Click(object sender, EventArgs e)
704 {
705 AddClient();
706 }
707
708 private void deleteClientToolStripMenuItem_Click(object sender, EventArgs e)
709 {
710 DeleteClient();
711 }
712
713 private void clientDefaultsToolStripMenuItem_Click(object sender, EventArgs e)
714 {
715 ClientDefaultSettings();
716 }
717
718 private void propertiesToolStripMenuItem1_Click(object sender, EventArgs e)
719 {
720 ClientProperties();
721 }
722
723 private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
724 {
725 UpdateTree();
726 }
727
728 private void UserSelectedImage()
729 {
730 Globals.WizardMode = Globals.WizardTask.USER_SELECTED_DISTRIBUTION;
731 using (frmWizard objCustomDialogBox = new frmWizard())
732 {
733 objCustomDialogBox.ShowDialog();
734 } // Unload frmWizard, in order to run load event next time.
735 }
736
737 private void createClientBootToolStripMenuItem_Click(object sender, EventArgs e)
738 {
739 UserSelectedImage();
740 }
741
742 private void toolStripButtonProperties_Click(object sender, EventArgs e)
743 {
744 ClientProperties();
745 }
746
747 private void toolStripButtonNetworkBootImage_Click(object sender, EventArgs e)
748 {
749 UserSelectedImage();
750 }
751
752 private void toolStripButtonHomepage_Click(object sender, EventArgs e)
753 {
754 wizardSupport.AnywhereTSHomepage();
755 }
756
757 private void selectModeToolStripMenuItem_Click(object sender, EventArgs e)
758 {
759 ConfigureATS();
760 // Update controls and setup datbase etc.
761 SetMode();
762 }
763
764
765 // Configure AnywhereTS
766 // Run first time starting ATS and can also be invoked from the Tools menu.
767 private bool ConfigureATS()
768 {
769 DialogResult result;
770
771 if (!ProSupport.IsAnAdministrator())
772 {
773 MessageBox.Show("Only administrators can configure AnywhereTS, you do not have currently have administrator privileges (23114)");
774 return false;
775 }
776
777 // Setup managed mode. This can alternatively be set from frmConfigMode, but this form is now disabled
778 // Create Datbase directory
779 string dataDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\AnywhereTS";
780 try
781 {
782 Directory.CreateDirectory(dataDir);
783 }
784 catch (Exception ex)
785 {
786 this.Cursor = Cursors.Default;
787 MessageBox.Show("Could not create directory '" + dataDir + "'. Error: " + ex.Message);
788 using (log4net.NDC.Push(string.Format("directory={0}", dataDir)))
789 {
790 Logging.ATSAdminLog.Error("Could not create directory.");
791 }
792 return false;
793 }
794
795 ATSGlobals.managedMode = 1; // We are running in Managed Mode
796
797 // Save the database directory to registry
798 ProSupport.strDatabasePath = dataDir;
799 ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseDir, ProSupport.strDatabasePath);
800
801 // Save mode
802 ATSGlobals.SetATSRegValue(ATSGlobals.strRegManagedMode, ATSGlobals.managedMode);
803
804 // Set up database
805 DatabaseSupport dataSupport = new DatabaseSupport();
806 dataSupport.SetupDatabase(); // Creates updates the database if necessary
807
808 DisplayMode: // Configure mode
809 /* The unmanged mode is presently not possible to select
810 using (frmConfigMode objCustomDialogBox = new frmConfigMode())
811 {
812 result = objCustomDialogBox.ShowDialog();
813 }
814 if (result == DialogResult.Cancel)
815 {
816 return false;
817 }
818 */
819
820 DisplayConfig: // Config services
821 if (ATSGlobals.managedMode == 1) // If managed mode
822 {
823 // Show configuration screen for terminal servers, TFTP, DHCP
824 using (frmConfigServices formConfig = new frmConfigServices())
825 {
826 result = formConfig.ShowDialog();
827 }
828 if (result == DialogResult.Cancel)
829 { // Cancel pressed
830 return false;
831 }
832 else if (result == DialogResult.No) // 'No' is used for Back, since there is no DialogResult.Back
833 { // Back pressed
834 goto DisplayMode; // Display the mode window again.
835 }
836
837 // Check if we are going to use the built in DHCP or TFTP server
838 if (ATSGlobals.dhcpConfig == 0 || ATSGlobals.tftpConfig == 0)
839 { // Use built in DHCP server
840 using (frmConfigInternalServices formDHCP = new frmConfigInternalServices())
841 {
842 result = formDHCP.ShowDialog();
843 }
844 if (result == DialogResult.Cancel)
845 {
846 return false;
847 }
848 else if (result == DialogResult.No)
849 {
850 goto DisplayConfig; // Display the server config screen again
851 }
852 }
853 }
854
855 // Configure and start/stop TFTPD32
856 AtsDhcp.ConfigureTFTPD32service(ATSGlobals.tftpConfig == 0, ATSGlobals.dhcpConfig == 0);
857
858 // Configuration completed
859 ATSGlobals.configured = 1; // Indicate that configuration process is completed
860 ATSGlobals.SetATSRegValue(ATSGlobals.strRegConfigured, ATSGlobals.configured); // Save to registry
861 return true;
862 }
863
864 void SetMode()
865 {
866 if (ATSGlobals.managedMode == 1)
867 { // We are running in managed mode, enable all controls related to client administration.
868 lblClientProperties.Enabled = true;
869 lblClientDefaultProperties.Enabled = true;
870 clientToolStripMenuItem.Visible = true;
871 toolStripButtonRefresh.Enabled = true;
872 toolStripButtonAdd.Enabled = true;
873 toolStripButtonProperties.Enabled = true;
874 treeView.Enabled = true;
875 lblNoOfClients.Text = "";
876 lblClientDefaultProperties.Enabled = true;
877 rtxWelcome.Rtf = @"{\rtf1\ansi\ansicpg1252\deff0\deflang1053\deflangfe2052\deftab1304{\fonttbl{\f0\fswiss\fprq2\fcharset0 Arial;}{\f1\froman\fprq2\fcharset0 Times New Roman;}}
878 {\*\generator Msftedit 5.41.21.2500;}\viewkind4\uc1\pard\lang2057\f0\fs16 1. Start creating your thin client solution by making a thin client image that will load onto your client PC:s.\par
879 Select \b Make client image\b0 on the \b MakeClient\b0 menu.\par
880 \par
881 2. Boot your clients and have them connect to one of the terminal servers you registered into AnywhereTS. \par
882 They will then appear in the tree to the left. You can also manually add clients on the \b ManageClients\b0 menu or by using the toolbar or right click in the tree. \par
883 If you want to register more terminal servers, select \b Configure \b0 from the \b Tools\b0 menu.\par
884 \par
885 3. Administer your clients, customise and change settings in the tree to the left and by using the \b ManageClients\b0 menu.\f1\fs24\par
886 }
887 ";
888
889 if (ATSGlobals.runFirstTime == 1)
890 { // This version of the application is run for the first time.
891
892 // Set up database
893 DatabaseSupport dataSupport = new DatabaseSupport();
894 dataSupport.SetupDatabase(); // Creates or updates the database if necessary
895 }
896
897 ProSupport.InitDatabase(); // Create the database connection
898 datasetAllClients = new atsDataSet();
899 datasetLicensedClients = new atsDataSet();
900
901 // Update dataset
902 try
903 {
904 ProSupport.clientTableAdapter.FillClients(datasetAllClients.Client);
905 }
906 catch (SqlException ex)
907 {
908 MessageBox.Show("Unhandled SQL error, please restart AnywhereTS. Details: " + ex.Message);
909 using (log4net.NDC.Push(string.Format("SqlException: ID={0} MESSAGE={1}{2}Diagnostics:{2}{3}", ex.Number.ToString(), ex.Message, System.Environment.NewLine, ex.ToString())))
910 {
911 Logging.ATSAdminLog.Error("Encountered Unhandled or Unexcepected SQL error");
912 }
913 Application.Exit();
914 return;
915 }
916
917 if (ATSGlobals.runFirstTime == 1)
918 { // This version of the application is run for the first time.
919
920 // Recreate all config files and hosts file.
921 ProSupport.RecreateConfigFiles();
922
923 // Indicate in registry that all the run first time stuff has been processed and should not be run again for this version.
924 ATSGlobals.SetATSRegValue(ATSGlobals.strRegRunFirstTime, 0);
925
926 SaveMachineNameToDatabase(); // Make sure the machine name is in the database, in order for the control panel to work from version 3.0
927 }
928
929
930 UpdateTree();
931 treeView.Nodes[0].ExpandAll();
932
933 }
934 else if (ATSGlobals.managedMode == 2)
935 { // We are running in unmanaged mode, disable all controls related to client administration.
936 lblClientProperties.Enabled = false;
937 lblClientDefaultProperties.Enabled = false;
938 clientToolStripMenuItem.Visible = false;
939 toolStripButtonRefresh.Enabled = false;
940 toolStripButtonAdd.Enabled = false;
941 toolStripButtonProperties.Enabled = false;
942 treeView.Enabled = false;
943 rtxWelcome.Visible = true;
944 rtxWelcome.Text = "AnywhereTS is running in unmanged mode. You can change mode on the Tools-Configure menu.";
945 lblClientDefaultProperties.Enabled = false;
946 pnlClientSession.Visible = false;
947 pnlDefault.Visible = false;
948 }
949 else
950 {
951 MessageBox.Show("Error, no mode selected (56541)");
952 using (log4net.NDC.Push(string.Format("ATSGlobals.managedMode={0}", ATSGlobals.managedMode)))
953 {
954 Logging.ATSAdminLog.Error("Error, no mode selected (56541)");
955 }
956 }
957 }
958
959 private void frmAdmin_Resize(object sender, EventArgs e)
960 {
961 // Adjust the size of the splitter container to fit in the form.
962 splitContainerClient.Height = this.Height - 46; // Make space for the menubar and toolbar
963 splitContainerClient.Width = this.Width;
964 toolStrip1.Width = this.Width;
965 }
966
967 private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
968 {
969 // Display client properties dialog
970 ClientProperties();
971 }
972
973 private void lblClientDefault_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
974 {
975 // Display client default properties dialog
976 ClientDefaultSettings();
977 }
978
979 private void contentsToolStripMenuItem_Click(object sender, EventArgs e)
980 {
981 Help.ShowHelp(this, ATSGlobals.strHelpFilePath, HelpNavigator.TableOfContents);
982 }
983
984 private void searchForHelpToolStripMenuItem_Click(object sender, EventArgs e)
985 {
986 Help.ShowHelp(this, ATSGlobals.strHelpFilePath, HelpNavigator.Index);
987 }
988
989 // Save the computer name to database.
990 // Saves the computer name of the current computer, being the one running the admin tool into the database
991 private void SaveMachineNameToDatabase()
992 {
993 string machineName = Environment.MachineName;
994 atsDataSet datasetAppInfo;
995 DataRow row;
996 ProSupport.appInfoTableAdapter = new atsDataSetTableAdapters.AppInfoTableAdapter();
997 datasetAppInfo = new atsDataSet();
998
999 ProSupport.appInfoTableAdapter.Fill(datasetAppInfo.AppInfo);
1000
1001 // Loook up the row
1002 row = datasetAppInfo.AppInfo.Rows.Find("AdminComputer");
1003 if (row != null)
1004 { // Found row, update
1005 row["Value"] = machineName;
1006 }
1007 else
1008 { // Row could not be found
1009 // Create a license key row
1010 DataRow newRow = datasetAppInfo.AppInfo.NewRow();
1011 newRow["Property"] = "AdminComputer";
1012 newRow["Value"] = machineName;
1013 // Save default row
1014 datasetAppInfo.AppInfo.Rows.Add(newRow);
1015 }
1016 // Save changes
1017 ProSupport.appInfoTableAdapter.Update(datasetAppInfo.AppInfo);
1018 }
1019
1020 } // FrmAdmin
1021 } // Namespace AnywhereTS
1022
1023

  ViewVC Help
Powered by ViewVC 1.1.22