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

Contents of /branches/TerminalServices/TSAdminTool/frmAdmin.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 271 - (show annotations) (download)
Sun Aug 26 00:04:01 2012 UTC (8 years, 1 month ago) by william
File size: 44460 byte(s)
+ switch TerminalServices backend to Cassia 2.0.0.60

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

  ViewVC Help
Powered by ViewVC 1.1.22