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

Annotation of /trunk/TSAdminTool/frmAdmin.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 99 - (hide annotations) (download)
Sat Jul 14 04:50:27 2012 UTC (9 years ago) by william
File size: 44278 byte(s)
+ bulk commit

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

  ViewVC Help
Powered by ViewVC 1.1.22