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

Contents of /trunk/TSAdminTool/frmAdmin.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 59 - (show annotations) (download)
Thu Jul 12 17:03:02 2012 UTC (8 years, 1 month ago) by william
File size: 44263 byte(s)
don't change cursor to waitcursor on form load

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 }
28
29 static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
30 {
31 Exception ex = (e.ExceptionObject as Exception);
32 if (ex == null)
33 {
34 Logging.ATSAdminLog.Error("Encountered unhandled Exception, but the exception was null");
35 return;
36 }
37 if (ex.GetType() == typeof(SqlException))
38 {
39 SqlException sql_ex = (ex as SqlException);
40 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())))
41 {
42 Logging.ATSAdminLog.Error("Encountered unhandled SqlException");
43 }
44 }
45 else
46 {
47 using (log4net.NDC.Push(string.Format("Exception: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
48 {
49 Logging.ATSAdminLog.Error("Encountered unhandled Exception");
50 }
51 }
52 }
53
54 private void frmAdmin_Load(object sender, EventArgs e)
55 {
56 //this.Cursor = Cursors.WaitCursor;
57
58 UpdateControlsToReflectProgramVersion();
59
60 // Check if AnywhereTS is configured
61 if (ATSGlobals.configured == 0 || ATSGlobals.managedMode == 0)
62 { // ATS is not configured, configure
63 if (!ConfigureATS())
64 {
65 // ATS still not configured, abort
66 MessageBox.Show("You cannot run AnywhereTS without configuring it first.");
67 Application.Exit();
68 return;
69 }
70 }
71
72 // Setup controls and database
73 SetMode();
74
75 helpProvider.HelpNamespace = ATSGlobals.strHelpFilePath; // Initiate helpProvider
76
77 treeView.Nodes[1].Expand(); // Expand terminal servers node.
78
79 this.Cursor = Cursors.Default;
80
81 // Create a default record
82 ATSImageDesigntimeConfig newConfig = new ATSImageDesigntimeConfig();
83 newConfig.ReadDefaultFromDatabase();
84 newConfig.WriteDefaultsToDatabase();
85 } // form load
86
87 private void UpdateControlsToReflectProgramVersion()
88 {
89 // Update the application to reflect the type of license and release
90 ATSGlobals.isPro = true;
91 Globals.isPro = ATSGlobals.isPro; // Update program status for the VB part of the application.
92 // We are running in Pro Mode, add 'Open Source' to the Application name
93 ATSGlobals.ApplicationTitle = ATSGlobals.ApplicationName + " Open Source Version";
94
95 this.Text = ATSGlobals.ApplicationTitle; // Set name in window title
96 aboutToolStripMenuItem.Text = "About " + ATSGlobals.ApplicationTitle;
97 }
98
99 // Update database from terminal server sessions
100 private void UpdateClientsFromSession()
101 {
102 List<TSManager.TS_SESSION_INFO> Sessions;
103 Sessions = TSManager.ListSessions();
104 foreach (TSManager.TS_SESSION_INFO session in Sessions)
105 {
106 if (session.macAddress != "")
107 { // The client is an (Un-named) ATS client. We have a MAC address.
108
109 // Does the MAC adress for the session alreay exist in database?
110 if (datasetAllClients.Client.Rows.Find(session.macAddress) == null)
111 {
112 // The MAC address did not exist in database. Add the client, using properties from the default record.
113 DataRow newRow = datasetAllClients.Client.NewRow();
114 ATSImageRuntimeConfig newConfig = new ATSImageRuntimeConfig();
115 newConfig.ReadDefaultFromDatabase();
116 newConfig.WriteToDatabase(newRow);
117 newRow["macAddress"] = session.macAddress;
118 newRow["clientName"] = session.name;
119 datasetAllClients.Client.Rows.Add(newRow);
120 }
121 }
122 }
123 ProSupport.clientTableAdapter.Update(datasetAllClients.Client);
124 }
125
126
127 // Update the tree control and database from sessions
128 private void UpdateTree()
129 {
130 this.Cursor = Cursors.WaitCursor;
131
132 // Update the environment
133 AtsEnvironment.Refresh();
134 // Update general statistics
135 lblNoOfTS.Text = AtsEnvironment.TerminalServers.Count.ToString();
136 lblNoOfSessions.Text = AtsEnvironment.Sessions.Count.ToString();
137
138 // Get records from the database.
139 FillLicensedClients(datasetLicensedClients);
140 // Poulate a dataset with all clients (regardless of license) and default record for reference.
141 ProSupport.clientTableAdapter.FillClients(datasetAllClients.Client);
142
143 UpdateClientsFromSession();
144
145 // Update the no of clients text
146 if (datasetAllClients.Client.Rows.Count == 0)
147 {
148 rtxWelcome.Visible = true;
149 lblRoot.Text = "Welcome to " + ATSGlobals.ApplicationName + "!";
150 tlpGeneralData.Visible = false;
151 }
152 else
153 {
154 rtxWelcome.Visible = false;
155 lblRoot.Text = "Summary Statistics";
156 tlpGeneralData.Visible = true;
157 lblNoOfClients.Text = datasetAllClients.Client.Rows.Count.ToString();
158 }
159
160 // Add clients to the tree
161 treeView.Nodes[0].Nodes.Clear(); // Clear the clients node
162 foreach (DataRow row in datasetLicensedClients.Client.Rows)
163 {
164 AtsSession session; // Session for the current client
165 TreeNode addedNode;
166
167 session = TSManager.GetSession(row["MacAddress"].ToString());
168 if (session != null && session.username.Length > 0)
169 {
170 // There is a user name for the client, display client name and user name.
171 addedNode = treeView.Nodes[0].Nodes.Add(row["ClientName"].ToString() + " (" + session.username + ")");
172 }
173 else
174 {
175 // There is no user name for the client, just add client name.
176 addedNode = treeView.Nodes[0].Nodes.Add(row["ClientName"].ToString());
177 }
178
179 // Select the appropriate bitmap to show for the node according to its status.
180 // Default is disconnected, so no need to indicate that.
181 if (session != null)
182 {
183 // There is a session for the client
184 if (session.username.Length > 0)
185 { // There is a user logged in
186 addedNode.ImageIndex = 3;
187 addedNode.SelectedImageIndex = 3;
188 }
189 else
190 { // The session has no user
191 addedNode.ImageIndex = 2;
192 addedNode.SelectedImageIndex = 2;
193 }
194
195 } // if client has session
196 addedNode.ContextMenuStrip = contextMenuClient; // Add the context menu for the client. Enables to remove the client.
197
198 } // foreach client
199
200 ProSupport.WriteHostsFiles(); // Update the hosts files on all TFTP servers
201
202 // Add terminal servers to the tree
203 treeView.Nodes[1].Nodes.Clear(); // Clear the terminal server node
204 foreach (AtsTerminalServer ts in AtsEnvironment.TerminalServers)
205 {
206 // Add a terminal server to the tree
207 TreeNode addedServerNode;
208 if (ts.networkPath == "localhost")
209 {
210 addedServerNode = treeView.Nodes[1].Nodes.Add("This Computer");
211 }
212 else
213 {
214 addedServerNode = treeView.Nodes[1].Nodes.Add(ts.networkPath);
215 }
216 addedServerNode.ToolTipText = ts.strError;
217 if (ts.Online)
218 { // Display the online server icon
219 addedServerNode.ImageIndex = 5;
220 addedServerNode.SelectedImageIndex = 5;
221 }
222 else
223 { // Display the offline server icon
224 addedServerNode.ImageIndex = 6;
225 addedServerNode.SelectedImageIndex = 6;
226 }
227 //addedNode.ContextMenuStrip = contextMenuClient; // Add the context menu for the client. Enables to remove the client.
228
229 // Add sessions for the terminal server to the tree.
230 foreach (AtsSession session in ts.Session)
231 {
232 string sessionText;
233 int imageIndex;
234 if (session.sessionID == 0)
235 { // This is a console session
236 sessionText = "Console";
237 if (session.username.Length != 0)
238 { // Session has a username
239 sessionText += " (" + session.username + ")";
240 }
241 imageIndex = 7; // Display the active session icon
242 }
243 else if (session.sessionID == 65536)
244 { // This is the listener session
245 sessionText = "Listener";
246 imageIndex = 8; // Display the non-active session icon
247 }
248 else
249 { // This is a "normal" session
250 sessionText = session.sessionID.ToString() + " " + (session.username.Length != 0 ? " (" + session.username + ")" : "");
251 if (session.state == TSManager.WTS_CONNECTSTATE_CLASS.WTSActive)
252 { // Display the active session icon
253 imageIndex = 7;
254 }
255 else
256 { // Display the non-active session icon
257 imageIndex = 8;
258 }
259 }
260 TreeNode addedSessionNode;
261 addedSessionNode = addedServerNode.Nodes.Add(sessionText);
262 addedSessionNode.ImageIndex = imageIndex;
263 addedSessionNode.SelectedImageIndex = imageIndex;
264 addedSessionNode.Tag = session;
265 //addedNode.ContextMenuStrip = contextMenuClient; // Add the context menu for the client. Enables option to remove the client.
266 } // foreach session
267
268 } // foreach terminal server
269
270 // Add sesions to the tree
271 treeView.Nodes[2].Nodes.Clear(); // Clear the sessions node
272 foreach (AtsSession session in AtsEnvironment.Sessions)
273 {
274 string sessionText;
275 int imageIndex;
276 if (session.sessionID == 0)
277 { // This is a console session
278 sessionText = "Console";
279 if (session.username.Length != 0)
280 { // Session has a username
281 sessionText += " (" + session.username + ")";
282 }
283 imageIndex = 7; // Display the active session icon
284 }
285 else if (session.sessionID == 65536)
286 { // This is the listener session
287 sessionText = "Listener";
288 imageIndex = 8; // Display the non-active session icon
289 }
290 else
291 { // This is a "normal" session
292 if (session.username.Length != 0)
293 { // Session has a username
294 sessionText = session.username;
295 }
296 else
297 { // Session does not have a username
298 sessionText = "Not logged on";
299 }
300 // Select the icon to display
301 if (session.state == TSManager.WTS_CONNECTSTATE_CLASS.WTSActive)
302 { // Display the active session icon
303 imageIndex = 7;
304 }
305 else
306 { // Display the non-active session icon
307 imageIndex = 8;
308 }
309 }
310 // Add terminal server name if we have more than one terminal server
311 if (AtsEnvironment.TerminalServers.Count > 1)
312 { // We have more than one terminal server, display the name of the terminal server
313 sessionText += " (" + session.TerminalServerName + ")";
314 }
315
316 TreeNode addedSessionNode;
317 addedSessionNode = treeView.Nodes[2].Nodes.Add(sessionText);
318 addedSessionNode.ImageIndex = imageIndex;
319 addedSessionNode.SelectedImageIndex = imageIndex;
320 addedSessionNode.Tag = session;
321 //addedNode.ContextMenuStrip = contextMenuClient; // Add the context menu for the client. Enables option to remove the client.
322 } // foreach session
323
324 // Select the root node
325 treeView.SelectedNode = treeView.Nodes[0];
326 NodeSelected(treeView.Nodes[0]); // Update related controls
327
328 this.Cursor = Cursors.Default;
329 }
330
331 private void FillLicensedClients(atsDataSet dataset)
332 {
333 ProSupport.clientTableAdapter.FillClients(dataset.Client);
334 }
335
336 private void toolStripAddClient_Click(object sender, EventArgs e)
337 {
338 AddClient();
339 }
340
341 // Refresh database and controls
342 private void toolStripButtonRefresh_Click(object sender, EventArgs e)
343 {
344 UpdateTree();
345 }
346
347
348 private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
349 {
350 this.Cursor = Cursors.WaitCursor;
351 TreeNode selectedNode = e.Node;
352 NodeSelected(selectedNode);
353 this.Cursor = Cursors.Default;
354 }
355
356 private void NodeSelected(TreeNode node)
357 {
358 if (node.Parent != null)
359 {
360 // A child node selected in the tree view
361
362 if (node.Parent.Name == "nodeClients")
363 { // A client node is selected in the tree view.
364
365 // A client was selected in the tree
366
367 // Enable the delete tool button.
368 toolStripButtonDelete.Enabled = true;
369 deleteClientToolStripMenuItem.Enabled = true;
370
371 // Display client data
372 AtsSession sessionInfo; // Session info for the client that was selected in the tree
373 selectedClientMacAddress = datasetLicensedClients.Client.Rows[node.Index]["MacAddress"].ToString();
374 //selectedConfig.ReadFromDatabase(datasetClient.Client.Rows[e.Node.Index]);
375
376 lblClientName.Text = datasetLicensedClients.Client.Rows[node.Index]["ClientName"].ToString();
377 lblMacAddress.Text = selectedClientMacAddress;
378 lblConnectionType.Text = datasetLicensedClients.Client.Rows[node.Index]["SessionType"].ToString();
379 lblResolution.Text = datasetLicensedClients.Client.Rows[node.Index]["ScreenResolution"].ToString();
380 lblColorDepth.Text = datasetLicensedClients.Client.Rows[node.Index]["ScreenColorDepth"].ToString();
381
382 sessionInfo = TSManager.GetSession(selectedClientMacAddress);
383 if (sessionInfo != null)
384 {
385 // Display the session data for the selected client
386 UpdateSessionPanel(sessionInfo);
387 }
388 else
389 {
390 // There is no session for the selected client
391 tlpSessionDetails.Visible = false;
392 lblClientHasNoSession.Visible = true;
393 }
394 // Display the client panelValue
395 pnlClientSession.Visible = true;
396 pnlDefault.Visible = false;
397 pnlClientDetails.Visible = true;
398 PositionClientSessionPanels(false); // Put the client panel over the session panel
399 propertiesToolStripMenuItem1.Enabled = true;
400 toolStripButtonProperties.Enabled = true;
401 } // end if client node selected
402
403 else if (node.Parent.Name == "nodeTerminalServers")
404 { // A terminal server is selected in the tree view
405 // Display the default panel
406 pnlDefault.Visible = true;
407 pnlClientSession.Visible = false;
408 // Disable the delete tool button.
409 toolStripButtonDelete.Enabled = false;
410 deleteClientToolStripMenuItem.Enabled = false;
411 propertiesToolStripMenuItem1.Enabled = false;
412 toolStripButtonProperties.Enabled = false;
413
414 }
415 else if (node.Parent.Name == "nodeSessions" || (node.Level == 2))
416 { // A session under the "Sesssions" node is selected in the tree view.
417 // Or a session under a terminal server node is selected in the tree view
418
419 // Display the session data
420 AtsSession session = (AtsSession)node.Tag;
421
422 PositionClientSessionPanels(true);
423 UpdateSessionPanel(session);
424
425 // Display the ClientSession panel
426 pnlClientSession.Visible = true;
427 pnlDefault.Visible = false;
428 // Hide client panel
429 pnlClientDetails.Visible = false;
430 }
431
432 else
433 { // Unhandled node
434 MessageBox.Show("Error: unhandled node (28843)");
435 using (log4net.NDC.Push(string.Format("unhandled node={0}", node.Parent.Name)))
436 {
437 Logging.ATSAdminLog.Error("rror: unhandled node (28843)");
438 }
439 }
440 }
441 else
442 {
443 // One of the root nodes is selected in the tree view.
444 // Display the default panel
445 pnlDefault.Visible = true;
446 pnlClientSession.Visible = false;
447
448 // Disable the delete tool button.
449 toolStripButtonDelete.Enabled = false;
450 deleteClientToolStripMenuItem.Enabled = false;
451 propertiesToolStripMenuItem1.Enabled = false;
452 toolStripButtonProperties.Enabled = false;
453 }
454 }
455
456 // Updates the session panel in the right pane with session data from the session in "session"
457 private void UpdateSessionPanel(AtsSession session)
458 {
459 tlpSessionDetails.Visible = true;
460 lblClientHasNoSession.Visible = false;
461 lblUserName.Text = session.username.Length != 0 ? session.username : "-";
462 lblSessionID.Text = session.sessionID.ToString();
463 lblState.Text = TSManager.StateToString(session.state);
464 lblIPAddress.Text = session.ipAddress.Length != 0 ? session.ipAddress : "-";
465 if (session.HorizontalResolution != 0)
466 {
467 lblSessionScreenResolution.Text = session.HorizontalResolution.ToString() + "x" + session.VerticalResolution.ToString();
468 }
469 else
470 { // No screen resolution
471 lblSessionScreenResolution.Text = "-";
472 }
473 }
474
475 // Position the panels for session info and client info.
476 // sessionOnTop = true > Place the session panel over the client panel.
477 // sessionOnTop = false > Place the client panel over the session panel.
478 private void PositionClientSessionPanels(bool sessionOnTop)
479 {
480 if (sessionOnTop)
481 {
482 pnlClientDetails.Top = 163;
483 pnlSessionDetails.Top = 3;
484 }
485 else
486 {
487 pnlClientDetails.Top = 3;
488 pnlSessionDetails.Top = 224;
489 }
490 }
491
492 private void btnDefault_Click(object sender, EventArgs e)
493 {
494 // Display client default properties dialog
495 ClientDefaultSettings();
496 }
497
498 private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
499 {
500 // Delete a client
501 DeleteClient();
502 }
503
504 // User clicked Properties on the client toolstrip
505 private void propertiesToolStripMenuItem_Click(object sender, EventArgs e)
506 {
507 // Display client properties
508 ClientProperties();
509 }
510
511 private void treeView_DoubleClick(object sender, EventArgs e)
512 {
513 //The user has double clicked a tree node
514 // The node will autmatically be selected on the mouse down event, so
515 // now the After_Select event has already been run and variables updated accordingly.
516
517
518 if (treeView.SelectedNode.Parent != null)
519 {
520 // A child node selected in the tree view
521 if (treeView.SelectedNode.Parent.Name == "nodeClients")
522 { // A client node is selected in the tree view.
523 // Check if a client is selected
524 if (treeView.SelectedNode.Name != "nodeLicenseWarning")
525 { // A client is selected in the tree
526 // Display client properties
527 ClientProperties();
528 }
529 }
530 else if (treeView.SelectedNode.Parent.Name == "nodeTerminalServers")
531 { // A terminal server is selected in the tree view
532
533 }
534 }
535 else
536 {
537 // The user has double clicked the root node.
538 }
539 }
540
541 private void treeView_KeyDown(object sender, KeyEventArgs e)
542 {
543 if (treeView.SelectedNode.Parent != null)
544 {
545 // A child node is selected in the tree view
546 if (treeView.SelectedNode.Parent.Name == "nodeClients")
547 { // A client node is selected in the tree view.
548 if (treeView.SelectedNode.Name != "nodeLicenseWarning")
549 { // A client is selected in the tree
550 if (e.KeyCode == Keys.Delete)
551 {
552 // Delete client
553 DeleteClient();
554 }
555 else if (e.KeyCode == Keys.Enter)
556 {
557 // Display client properties
558 ClientProperties();
559 }
560 }
561 }
562 }
563 }
564
565 // Display properties for the currently selected client
566 private void ClientProperties()
567 {
568 this.Cursor = Cursors.WaitCursor;
569
570 using (frmClientProperties objCustomDialogBox = new frmClientProperties())
571 {
572 objCustomDialogBox.macAddress = selectedClientMacAddress;
573 objCustomDialogBox.dialogMode = frmClientProperties.ATSClientMode.EDIT_CLIENT; // Select the mode to run the form in.
574 this.Cursor = Cursors.Default;
575
576 if (objCustomDialogBox.ShowDialog() == DialogResult.OK)
577 {
578 UpdateTree();
579 }
580 } // Unload frm
581 }
582
583 // Display the add client dialog and add a client
584 private void AddClient()
585 {
586 // Display client properties dialog in Add mode
587 this.Cursor = Cursors.WaitCursor;
588 frmClientProperties objCustomDialogBox = new frmClientProperties();
589 objCustomDialogBox.dialogMode = frmClientProperties.ATSClientMode.NEW_CLIENT; // Select the mode to run the form in.
590 this.Cursor = Cursors.Default;
591
592 if (objCustomDialogBox.ShowDialog() == DialogResult.OK)
593 {
594 UpdateTree();
595 }
596 objCustomDialogBox = null;
597 treeView.Nodes[0].Expand(); // Expand ATS client node, in order to show the newly added client
598 }
599
600 private void toolStripButtonAdd_Click(object sender, EventArgs e)
601 {
602 AddClient();
603 }
604
605 private void DeleteClient()
606 {
607 DialogResult result;
608 result = MessageBox.Show(this, "Are you sure you want to delete the client '" + lblClientName.Text + "'?", ATSGlobals.ApplicationName , MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
609 if (result == DialogResult.Yes)
610 {
611 this.Cursor = Cursors.WaitCursor;
612
613 // Delete the client
614 DataRow rowToDelete;
615
616 rowToDelete = datasetAllClients.Client.Rows.Find(selectedClientMacAddress);
617
618 if (rowToDelete != null)
619 {
620 // Delete the client database row.
621 rowToDelete.Delete();
622 ProSupport.clientTableAdapter.Update(datasetAllClients.Client);
623 UpdateTree();
624 // Delete the client config file.
625 string fileToDelete;
626 fileToDelete = ATSGlobals.strTFTPdir + @"\" + selectedClientMacAddress;
627 if (File.Exists(fileToDelete))
628 {
629 File.Delete(fileToDelete);
630 }
631 this.Cursor = Cursors.Default;
632
633 }
634 else
635 {
636 throw new Exception("Error: Cannot find record to delete (43556)");
637 }
638 }
639 }
640
641 // View and change default settings for all clients
642 private void ClientDefaultSettings()
643 {
644 // Display client default properties dialog
645 this.Cursor = Cursors.WaitCursor;
646
647 frmClientProperties objCustomDialogBox = new frmClientProperties();
648 objCustomDialogBox.macAddress = ProSupport.DEFAULT_RECORD_MAC;
649 objCustomDialogBox.dialogMode = frmClientProperties.ATSClientMode.EDIT_DEFAULT; // Select the mode to run the form in.
650 this.Cursor = Cursors.Default;
651
652 if (objCustomDialogBox.ShowDialog() == DialogResult.OK)
653 {
654 // Possible improvement: Did any parameters change?
655
656 // One of more parameters changed, save parameters to database.
657
658 UpdateTree();
659 }
660 objCustomDialogBox = null;
661 }
662
663 private void toolStripButtonDelete_Click(object sender, EventArgs e)
664 {
665 DeleteClient();
666 }
667
668 private void treeView_MouseDown(object sender, MouseEventArgs e)
669 {
670 if (treeView.GetNodeAt(e.X, e.Y) != null)
671 treeView.SelectedNode = treeView.GetNodeAt(e.X, e.Y);
672 }
673
674 private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
675 {
676 frmAboutPro objCustomDialogBox = new frmAboutPro();
677 objCustomDialogBox.ShowDialog();
678 }
679
680 private void anywhereTSHomepageToolStripMenuItem_Click(object sender, EventArgs e)
681 {
682 wizardSupport.AnywhereTSHomepage();
683 }
684
685 private void exitToolStripMenuItem_Click(object sender, EventArgs e)
686 {
687 Application.Exit();
688 }
689
690 private void cDToolStripMenuItem_Click(object sender, EventArgs e)
691 {
692 wizardSupport.PXEBootType = wizardSupport.PXEBootTask.PXE_Boot_CD;
693 wizardSupport.PXEBoot();
694 }
695
696 private void floppyToolStripMenuItem_Click(object sender, EventArgs e)
697 {
698 wizardSupport.PXEBootType = wizardSupport.PXEBootTask.PXE_Boot_Floppy;
699 wizardSupport.PXEBoot();
700 }
701
702 private void addClientToolStripMenuItem_Click(object sender, EventArgs e)
703 {
704 AddClient();
705 }
706
707 private void deleteClientToolStripMenuItem_Click(object sender, EventArgs e)
708 {
709 DeleteClient();
710 }
711
712 private void clientDefaultsToolStripMenuItem_Click(object sender, EventArgs e)
713 {
714 ClientDefaultSettings();
715 }
716
717 private void propertiesToolStripMenuItem1_Click(object sender, EventArgs e)
718 {
719 ClientProperties();
720 }
721
722 private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
723 {
724 UpdateTree();
725 }
726
727 private void UserSelectedImage()
728 {
729 Globals.WizardMode = Globals.WizardTask.USER_SELECTED_DISTRIBUTION;
730 using (frmWizard objCustomDialogBox = new frmWizard())
731 {
732 objCustomDialogBox.ShowDialog();
733 } // Unload frmWizard, in order to run load event next time.
734 }
735
736 private void createClientBootToolStripMenuItem_Click(object sender, EventArgs e)
737 {
738 UserSelectedImage();
739 }
740
741 private void toolStripButtonProperties_Click(object sender, EventArgs e)
742 {
743 ClientProperties();
744 }
745
746 private void toolStripButtonNetworkBootImage_Click(object sender, EventArgs e)
747 {
748 UserSelectedImage();
749 }
750
751 private void toolStripButtonHomepage_Click(object sender, EventArgs e)
752 {
753 wizardSupport.AnywhereTSHomepage();
754 }
755
756 private void selectModeToolStripMenuItem_Click(object sender, EventArgs e)
757 {
758 ConfigureATS();
759 // Update controls and setup datbase etc.
760 SetMode();
761 }
762
763
764 // Configure AnywhereTS
765 // Run first time starting ATS and can also be invoked from the Tools menu.
766 private bool ConfigureATS()
767 {
768 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
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