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