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

Annotation of /trunk/TSAdminTool/frmAdmin.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 94 - (hide annotations) (download)
Sat Jul 14 02:52:23 2012 UTC (8 years, 7 months ago) by william
File size: 44290 byte(s)
+ add lots of debug logging with proper context

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

  ViewVC Help
Powered by ViewVC 1.1.22