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

Contents of /trunk/TSAdminTool/frmAdmin.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 357 - (show annotations) (download)
Tue Aug 28 03:41:07 2012 UTC (7 years, 11 months ago) by william
File size: 45774 byte(s)
+ add debug logging in UpdateClientsFromSession()

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

  ViewVC Help
Powered by ViewVC 1.1.22