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

Annotation of /trunk/TSAdminTool/frmAdmin.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 46 - (hide annotations) (download)
Thu Jul 12 14:17:14 2012 UTC (9 years ago) by william
File size: 42932 byte(s)
+ add logging across ATSAdmin Tool project

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     using System.Data.SqlClient; // For File operations
13 william 4
14    
15     public partial class frmAdmin : Form
16     {
17     // Data variables
18    
19     //DatabaseSupport dataSupport;
20     private atsDataSet datasetAllClients; // Dataset containing all clients
21     private atsDataSet datasetLicensedClients; // Dataset containing only the licensed clients, sorted in order of creation
22    
23     private string selectedClientMacAddress; // The MAC address of the currently selected client.
24     public frmAdmin()
25     {
26     InitializeComponent();
27     }
28    
29    
30     private void frmAdmin_Load(object sender, EventArgs e)
31     {
32     this.Cursor = Cursors.WaitCursor;
33    
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     throw new Exception("Error: Cannot find record to delete (43556)");
613     }
614     }
615     }
616    
617     // View and change default settings for all clients
618     private void ClientDefaultSettings()
619     {
620     // Display client default properties dialog
621     this.Cursor = Cursors.WaitCursor;
622    
623     frmClientProperties objCustomDialogBox = new frmClientProperties();
624     objCustomDialogBox.macAddress = ProSupport.DEFAULT_RECORD_MAC;
625     objCustomDialogBox.dialogMode = frmClientProperties.ATSClientMode.EDIT_DEFAULT; // Select the mode to run the form in.
626     this.Cursor = Cursors.Default;
627    
628     if (objCustomDialogBox.ShowDialog() == DialogResult.OK)
629     {
630     // Possible improvement: Did any parameters change?
631    
632     // One of more parameters changed, save parameters to database.
633    
634     UpdateTree();
635     }
636     objCustomDialogBox = null;
637     }
638    
639     private void toolStripButtonDelete_Click(object sender, EventArgs e)
640     {
641     DeleteClient();
642     }
643    
644     private void treeView_MouseDown(object sender, MouseEventArgs e)
645     {
646     if (treeView.GetNodeAt(e.X, e.Y) != null)
647     treeView.SelectedNode = treeView.GetNodeAt(e.X, e.Y);
648     }
649    
650     private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
651     {
652     frmAboutPro objCustomDialogBox = new frmAboutPro();
653     objCustomDialogBox.ShowDialog();
654     }
655    
656     private void anywhereTSHomepageToolStripMenuItem_Click(object sender, EventArgs e)
657     {
658     wizardSupport.AnywhereTSHomepage();
659     }
660    
661     private void exitToolStripMenuItem_Click(object sender, EventArgs e)
662     {
663     Application.Exit();
664     }
665    
666     private void cDToolStripMenuItem_Click(object sender, EventArgs e)
667     {
668     wizardSupport.PXEBootType = wizardSupport.PXEBootTask.PXE_Boot_CD;
669     wizardSupport.PXEBoot();
670     }
671    
672     private void floppyToolStripMenuItem_Click(object sender, EventArgs e)
673     {
674     wizardSupport.PXEBootType = wizardSupport.PXEBootTask.PXE_Boot_Floppy;
675     wizardSupport.PXEBoot();
676     }
677    
678     private void addClientToolStripMenuItem_Click(object sender, EventArgs e)
679     {
680     AddClient();
681     }
682    
683     private void deleteClientToolStripMenuItem_Click(object sender, EventArgs e)
684     {
685     DeleteClient();
686     }
687    
688     private void clientDefaultsToolStripMenuItem_Click(object sender, EventArgs e)
689     {
690     ClientDefaultSettings();
691     }
692    
693     private void propertiesToolStripMenuItem1_Click(object sender, EventArgs e)
694     {
695     ClientProperties();
696     }
697    
698     private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
699     {
700     UpdateTree();
701     }
702    
703     private void UserSelectedImage()
704     {
705     Globals.WizardMode = Globals.WizardTask.USER_SELECTED_DISTRIBUTION;
706     using (frmWizard objCustomDialogBox = new frmWizard())
707     {
708     objCustomDialogBox.ShowDialog();
709     } // Unload frmWizard, in order to run load event next time.
710     }
711    
712     private void createClientBootToolStripMenuItem_Click(object sender, EventArgs e)
713     {
714     UserSelectedImage();
715     }
716    
717     private void toolStripButtonProperties_Click(object sender, EventArgs e)
718     {
719     ClientProperties();
720     }
721    
722     private void toolStripButtonNetworkBootImage_Click(object sender, EventArgs e)
723     {
724     UserSelectedImage();
725     }
726    
727     private void toolStripButtonHomepage_Click(object sender, EventArgs e)
728     {
729     wizardSupport.AnywhereTSHomepage();
730     }
731    
732     private void selectModeToolStripMenuItem_Click(object sender, EventArgs e)
733     {
734     ConfigureATS();
735     // Update controls and setup datbase etc.
736     SetMode();
737     }
738    
739    
740     // Configure AnywhereTS
741     // Run first time starting ATS and can also be invoked from the Tools menu.
742     private bool ConfigureATS()
743     {
744     DialogResult result;
745    
746     if (!ProSupport.IsAnAdministrator())
747     {
748     MessageBox.Show("Only administrators can configure AnywhereTS, you do not have currently have administrator privileges (23114)");
749     return false;
750     }
751    
752     // Setup managed mode. This can alternatively be set from frmConfigMode, but this form is now disabled
753     // Create Datbase directory
754     string dataDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\AnywhereTS";
755     try
756     {
757     Directory.CreateDirectory(dataDir);
758     }
759     catch (Exception ex)
760     {
761     this.Cursor = Cursors.Default;
762     MessageBox.Show("Could not create directory '" + dataDir + "'. Error: " + ex.Message);
763 william 46 using (log4net.NDC.Push(string.Format("directory={0}", dataDir)))
764     {
765     Logging.ATSAdminLog.Error("Could not create directory.");
766     }
767 william 4 return false;
768     }
769    
770     ATSGlobals.managedMode = 1; // We are running in Managed Mode
771    
772     // Save the database directory to registry
773     ProSupport.strDatabasePath = dataDir;
774     ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseDir, ProSupport.strDatabasePath);
775    
776     // Save mode
777     ATSGlobals.SetATSRegValue(ATSGlobals.strRegManagedMode, ATSGlobals.managedMode);
778    
779     // Set up database
780     DatabaseSupport dataSupport = new DatabaseSupport();
781     dataSupport.SetupDatabase(); // Creates updates the database if necessary
782    
783     DisplayMode: // Configure mode
784     /* The unmanged mode is presently not possible to select
785     using (frmConfigMode objCustomDialogBox = new frmConfigMode())
786     {
787     result = objCustomDialogBox.ShowDialog();
788     }
789     if (result == DialogResult.Cancel)
790     {
791     return false;
792     }
793     */
794    
795     DisplayConfig: // Config services
796     if (ATSGlobals.managedMode == 1) // If managed mode
797     {
798     // Show configuration screen for terminal servers, TFTP, DHCP
799     using (frmConfigServices formConfig = new frmConfigServices())
800     {
801     result = formConfig.ShowDialog();
802     }
803     if (result == DialogResult.Cancel)
804     { // Cancel pressed
805     return false;
806     }
807     else if (result == DialogResult.No) // 'No' is used for Back, since there is no DialogResult.Back
808     { // Back pressed
809     goto DisplayMode; // Display the mode window again.
810     }
811    
812     // Check if we are going to use the built in DHCP or TFTP server
813     if (ATSGlobals.dhcpConfig == 0 || ATSGlobals.tftpConfig == 0)
814     { // Use built in DHCP server
815     using (frmConfigInternalServices formDHCP = new frmConfigInternalServices())
816     {
817     result = formDHCP.ShowDialog();
818     }
819     if (result == DialogResult.Cancel)
820     {
821     return false;
822     }
823     else if (result == DialogResult.No)
824     {
825     goto DisplayConfig; // Display the server config screen again
826     }
827     }
828     }
829    
830     // Configure and start/stop TFTPD32
831     AtsDhcp.ConfigureTFTPD32service(ATSGlobals.tftpConfig == 0, ATSGlobals.dhcpConfig == 0);
832    
833     // Configuration completed
834     ATSGlobals.configured = 1; // Indicate that configuration process is completed
835     ATSGlobals.SetATSRegValue(ATSGlobals.strRegConfigured, ATSGlobals.configured); // Save to registry
836     return true;
837     }
838    
839     void SetMode()
840     {
841     if (ATSGlobals.managedMode == 1)
842     { // We are running in managed mode, enable all controls related to client administration.
843     lblClientProperties.Enabled = true;
844     lblClientDefaultProperties.Enabled = true;
845     clientToolStripMenuItem.Visible = true;
846     toolStripButtonRefresh.Enabled = true;
847     toolStripButtonAdd.Enabled = true;
848     toolStripButtonProperties.Enabled = true;
849     treeView.Enabled = true;
850     lblNoOfClients.Text = "";
851     lblClientDefaultProperties.Enabled = true;
852     rtxWelcome.Rtf = @"{\rtf1\ansi\ansicpg1252\deff0\deflang1053\deflangfe2052\deftab1304{\fonttbl{\f0\fswiss\fprq2\fcharset0 Arial;}{\f1\froman\fprq2\fcharset0 Times New Roman;}}
853     {\*\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
854     Select \b Make client image\b0 on the \b MakeClient\b0 menu.\par
855     \par
856     2. Boot your clients and have them connect to one of the terminal servers you registered into AnywhereTS. \par
857     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
858     If you want to register more terminal servers, select \b Configure \b0 from the \b Tools\b0 menu.\par
859     \par
860     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
861     }
862     ";
863    
864     if (ATSGlobals.runFirstTime == 1)
865     { // This version of the application is run for the first time.
866    
867     // Set up database
868     DatabaseSupport dataSupport = new DatabaseSupport();
869     dataSupport.SetupDatabase(); // Creates or updates the database if necessary
870     }
871    
872     ProSupport.InitDatabase(); // Create the database connection
873     datasetAllClients = new atsDataSet();
874     datasetLicensedClients = new atsDataSet();
875    
876     // Update dataset
877     try
878     {
879     ProSupport.clientTableAdapter.FillClients(datasetAllClients.Client);
880     }
881 william 46 catch (SqlException ex)
882 william 4 {
883     MessageBox.Show("Unhandled SQL error, please restart AnywhereTS. Details: " + ex.Message);
884 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())))
885     {
886     Logging.ATSAdminLog.Error("Encountered Unhandled or Unexcepected SQL error");
887     }
888 william 4 Application.Exit();
889     return;
890     }
891    
892     if (ATSGlobals.runFirstTime == 1)
893     { // This version of the application is run for the first time.
894    
895     // Recreate all config files and hosts file.
896     ProSupport.RecreateConfigFiles();
897    
898     // Indicate in registry that all the run first time stuff has been processed and should not be run again for this version.
899     ATSGlobals.SetATSRegValue(ATSGlobals.strRegRunFirstTime, 0);
900    
901     SaveMachineNameToDatabase(); // Make sure the machine name is in the database, in order for the control panel to work from version 3.0
902     }
903    
904    
905     UpdateTree();
906     treeView.Nodes[0].ExpandAll();
907    
908     }
909     else if (ATSGlobals.managedMode == 2)
910     { // We are running in unmanaged mode, disable all controls related to client administration.
911     lblClientProperties.Enabled = false;
912     lblClientDefaultProperties.Enabled = false;
913     clientToolStripMenuItem.Visible = false;
914     toolStripButtonRefresh.Enabled = false;
915     toolStripButtonAdd.Enabled = false;
916     toolStripButtonProperties.Enabled = false;
917     treeView.Enabled = false;
918     rtxWelcome.Visible = true;
919     rtxWelcome.Text = "AnywhereTS is running in unmanged mode. You can change mode on the Tools-Configure menu.";
920     lblClientDefaultProperties.Enabled = false;
921     pnlClientSession.Visible = false;
922     pnlDefault.Visible = false;
923     }
924     else
925     {
926     MessageBox.Show("Error, no mode selected (56541)");
927 william 46 using (log4net.NDC.Push(string.Format("ATSGlobals.managedMode={0}", ATSGlobals.managedMode)))
928     {
929     Logging.ATSAdminLog.Error("Error, no mode selected (56541)");
930     }
931 william 4 }
932     }
933    
934     private void frmAdmin_Resize(object sender, EventArgs e)
935     {
936     // Adjust the size of the splitter container to fit in the form.
937     splitContainerClient.Height = this.Height - 46; // Make space for the menubar and toolbar
938     splitContainerClient.Width = this.Width;
939     toolStrip1.Width = this.Width;
940     }
941    
942     private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
943     {
944     // Display client properties dialog
945     ClientProperties();
946     }
947    
948     private void lblClientDefault_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
949     {
950     // Display client default properties dialog
951     ClientDefaultSettings();
952     }
953    
954     private void contentsToolStripMenuItem_Click(object sender, EventArgs e)
955     {
956     Help.ShowHelp(this, ATSGlobals.strHelpFilePath, HelpNavigator.TableOfContents);
957     }
958    
959     private void searchForHelpToolStripMenuItem_Click(object sender, EventArgs e)
960     {
961     Help.ShowHelp(this, ATSGlobals.strHelpFilePath, HelpNavigator.Index);
962     }
963    
964     // Save the computer name to database.
965     // Saves the computer name of the current computer, being the one running the admin tool into the database
966     private void SaveMachineNameToDatabase()
967     {
968     string machineName = Environment.MachineName;
969     atsDataSet datasetAppInfo;
970     DataRow row;
971     ProSupport.appInfoTableAdapter = new atsDataSetTableAdapters.AppInfoTableAdapter();
972     datasetAppInfo = new atsDataSet();
973    
974     ProSupport.appInfoTableAdapter.Fill(datasetAppInfo.AppInfo);
975    
976     // Loook up the row
977     row = datasetAppInfo.AppInfo.Rows.Find("AdminComputer");
978     if (row != null)
979     { // Found row, update
980     row["Value"] = machineName;
981     }
982     else
983     { // Row could not be found
984     // Create a license key row
985     DataRow newRow = datasetAppInfo.AppInfo.NewRow();
986     newRow["Property"] = "AdminComputer";
987     newRow["Value"] = machineName;
988     // Save default row
989     datasetAppInfo.AppInfo.Rows.Add(newRow);
990     }
991     // Save changes
992     ProSupport.appInfoTableAdapter.Update(datasetAppInfo.AppInfo);
993     }
994    
995     } // FrmAdmin
996     } // Namespace AnywhereTS
997    
998    

  ViewVC Help
Powered by ViewVC 1.1.22