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

Annotation of /trunk/TSAdminTool/frmAdmin.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 64 - (hide annotations) (download)
Thu Jul 12 18:56:31 2012 UTC (9 years, 2 months ago) by william
File size: 43436 byte(s)
+ more exception logging

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

  ViewVC Help
Powered by ViewVC 1.1.22