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

Contents of /trunk/TSAdminTool/frmClientProperties.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 185 - (show annotations) (download)
Mon Jul 16 14:14:09 2012 UTC (7 years, 7 months ago) by william
File size: 50128 byte(s)
+ add some logging for macaddess and clientname

1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8 using System.Data.SqlClient;
9 using System.Security.Permissions;
10
11 namespace AnywhereTS
12 {
13 public partial class frmClientProperties : Form
14 {
15 public frmClientProperties()
16 {
17 InitializeComponent();
18 }
19
20 public enum ATSClientMode //The modes that this form can be started in.
21 { EDIT_CLIENT, // Normal mode edit a client (only admins)
22 EDIT_DEFAULT, // Edit the default record, that will be used for all new clients. (only admins)
23 NEW_CLIENT, // Create a new client (only admins)
24 CONTROL_PANEL}; // User control panel (all users)
25
26
27 public enum ATSRecordState //Indicates if we are adding a new record or editing an existing.
28 {
29 ADD, // Add a new record
30 EDIT // Edit an existing record
31 }
32
33 public ATSClientMode dialogMode; // The mode the form is running in.
34 private ATSImageRuntimeConfig currentConfig;
35 private ATSRecordState recordState;
36 public string macAddress; // The mac address for the currently selected client. If used for editing the default client, the value Globals.DEFAULT_RECORD_MAC is used. Not used when this form is used for creating a new client record.
37
38 // Data variables
39 private atsDataSet datasetAllClientsAndDefault;
40 DataRow rowCurrentClient; // The row for the selected client in the table "Client".
41
42 bool changedByUser = true; // Used on some checkbox controls to determine if state was changed by user or code.
43
44
45 private void frmClientProperties_Load(object sender, EventArgs e)
46 {
47 //this.Cursor = Cursors.WaitCursor;
48 changedByUser = false; // To prevent the some controls from triggering changed event.
49
50
51 tbrScreenResolution.Maximum = ATSGlobals.ScreenResolutions.GetLength(0); // The number of predefined screen resolutions.
52
53 if (IntPtr.Size == 8)
54 { // 64 bit OS, change the background color on the track bar to controls, as it becomes white on 64 bit
55 tbrIcaAudioQuality.BackColor = System.Drawing.SystemColors.Control;
56 tbrPointerSpeed.BackColor = System.Drawing.SystemColors.Control;
57 tbrScreenResolution.BackColor = System.Drawing.SystemColors.Control;
58 tbrVolume.BackColor = System.Drawing.SystemColors.Control;
59 }
60
61 Logging.TSControlPanelLog.DebugFormat("dialogMode={0}", dialogMode);
62 switch (dialogMode)
63 { case ATSClientMode.EDIT_CLIENT:
64 this.Text = "Client Properties";
65 tabClientProperties.SelectTab("TabGeneral"); // Make the General tab start tab when editing a client.
66 recordState = ATSRecordState.EDIT;
67 break;
68 case ATSClientMode.EDIT_DEFAULT:
69 this.Text = "Default settings for not yet discovered clients";
70
71 // Disable controls for Client name & MAC address, not applicable for default settings.
72 lblClientName.Enabled = false;
73 lblMacAddress.Enabled = false;
74 lblComment.Enabled = false;
75
76 txtClientName.Enabled = false;
77 txtMacAddress.Enabled = false;
78 txtComment.Enabled = false;
79 txtComment.Text = "You cannot change default settings for this tab, since all settings here are for idividual clients, and the default settings apply to all new clients. In order to change any of the settings here, select a client in the tree and then select 'Properties'.";
80 tabClientProperties.SelectTab("TabConnection"); // Make the Connections tab start tab when editing defaults
81
82 recordState = ATSRecordState.EDIT;
83
84 break;
85 case ATSClientMode.NEW_CLIENT:
86 this.Text = "Add client";
87 recordState = ATSRecordState.ADD;
88 break;
89 case ATSClientMode.CONTROL_PANEL:
90 this.Text = "Interface settings";
91
92 // Check that AnywhereTS is configured
93 if (ATSGlobals.configured == 0)
94 { // ATS is not configured
95 // Is user Admin?
96 if (ProSupport.IsAnAdministrator())
97 { // User is admin, show config screen
98
99 frmConfigureControlPanel objCustomDialogBox = new frmConfigureControlPanel();
100 if (objCustomDialogBox.ShowDialog() == DialogResult.OK)
101 {
102 ATSGlobals.configured = 2; // Control panel mode
103 ATSGlobals.SetATSRegValue(ATSGlobals.strRegConfigured,ATSGlobals.configured);
104
105 ATSGlobals.managedMode = 1; // ManagedMode
106 ATSGlobals.SetATSRegValue(ATSGlobals.strRegManagedMode, ATSGlobals.managedMode);
107
108 ATSGlobals.tftpConfig = 1; // This computer is not an AnywhereTS TFTP server.
109 ATSGlobals.SetATSRegValue(ATSGlobals.strRegTFTPconfig,ATSGlobals.tftpConfig);
110
111 }
112 objCustomDialogBox = null;
113
114 }
115 else
116 { // User is not admin
117 this.Cursor = Cursors.Default;
118 MessageBox.Show("The AnywhereTS control panel is not yet configured. Before you can use it, it needs to be configured by an administrator.");
119 Application.Exit();
120 return;
121 }
122 }
123
124 // Check if we are trying to run the control panel in unmanged mode
125 if (ATSGlobals.managedMode != 1)
126 {
127 MessageBox.Show("AnywhereTS is not running in managed mode. In order to run this application, an administrator must first run AnywhereTS Admin and configure AnywhereTS to run in Managed Mode");
128 Application.Exit();
129 }
130
131 // If we are running as control panel, we first need to set up the database, as this is
132 // not being done anywhere else.
133 ProSupport.InitDatabase();
134
135 recordState = ATSRecordState.EDIT;
136 tabClientProperties.TabPages.Remove(tabClientProperties.TabPages["tabGeneral"]);
137 tabClientProperties.TabPages.Remove(tabClientProperties.TabPages["tabICA"]);
138 tabClientProperties.TabPages.Remove(tabClientProperties.TabPages["tabRDP"]);
139 tabClientProperties.TabPages.Remove(tabClientProperties.TabPages["tabMisc"]);
140
141 // Swap the Interface and connection tab, so that interface will be the first tab displayed on the control panel.
142 TabPage tabTemp;
143 tabTemp = tabClientProperties.TabPages["TabInterface"];
144 tabClientProperties.TabPages.Remove(tabInterface);
145 tabClientProperties.TabPages.Insert(0, tabTemp);
146 tabClientProperties.SelectTab("TabInterface");
147
148 // Disable most controls on the connection tab, ordinary users should only be able to set user name
149 lblServer.Enabled = false;
150 txtServer.Enabled = false;
151 cboConnection.Enabled = false;
152
153 chkReconnect.Enabled = false;
154
155 chkRedirectSound.Visible = false; // Users cannot enable/disable audio.
156 break;
157 } // switch dialog mode
158 currentConfig = new ATSImageRuntimeConfig();
159
160 // Set up database
161 datasetAllClientsAndDefault = new atsDataSet();
162
163 // Update dataset
164 try
165 {
166 ProSupport.clientTableAdapter.Fill(datasetAllClientsAndDefault.Client);
167 }
168 catch (Exception ex)
169 {
170 MessageBox.Show("Could not open datbase (77886). Error: " + ex.Message, "AnywhereTS");
171 Application.Exit();
172 return;
173 }
174
175 // If this dialog is run in edit default client, the mac address
176 // should be set to the default record
177 if (dialogMode == ATSClientMode.EDIT_DEFAULT)
178 {
179 macAddress = ProSupport.DEFAULT_RECORD_MAC;
180 }
181
182 // If this dialog is run in control panel mode, the mac address
183 // should be set to the one belonging to the current session
184 if (dialogMode == ATSClientMode.CONTROL_PANEL)
185 {
186 string myName = TSManager.GetMyName();
187
188 Logging.TSControlPanelLog.DebugFormat("TSManager.GetMyName()={0}", myName);
189
190 // If the session does not have a client name. Most likely, the user is running in console mode.
191 if (myName.Length > 0)
192 { // Session has name
193 // Try to extract MAC address from client name.
194 macAddress = ATSGlobals.GetMacFromATSname(myName);
195 Logging.TSControlPanelLog.DebugFormat("ATSGlobals.GetMacFromATSname()={0}", macAddress);
196 if (macAddress.Length == 0)
197 { // MAC not in name, try to lookup client name in database
198 atsDataSet datasetClientName = new atsDataSet();
199 // Update dataset
200 try
201 {
202 ProSupport.clientTableAdapter.FillOnName(datasetClientName.Client, myName);
203 }
204 catch (Exception ex)
205 {
206 MessageBox.Show("Could not open datbase (77887). Error: " + ex.Message, "AnywhereTS");
207 Application.Exit();
208 return;
209 }
210 if (datasetClientName.Client.Rows.Count > 0)
211 { // The client has a record in the database, get MAC address from database.
212 macAddress = datasetClientName.Client.Rows[0]["MacAddress"].ToString();
213 }
214 else
215 { // Name not found, client does not have a record in database.
216 macAddress = "";
217 }
218 } // Mac address is not in name
219 else
220 { // Mac address is in client name
221
222 }
223 }
224 else
225 { // The session does not have a client name. Most likely, the user is running in console mode.
226 macAddress = "";
227 }
228
229 if (macAddress == "")
230 {
231 this.Cursor = Cursors.Default;
232 MessageBox.Show("Your computer cannot be identified as an AnywhereTS client. This application is used to configure settings for AnywhereTS-clients and can only be run from a client powered by AnywhereTS. If you still get this error message, please contact your system adminstrator or feedback@anywherets.com");
233 Application.Exit(); //Quit
234 return;
235 }
236
237 // Check if the client belong to the ones that are licensed.
238 atsDataSet datasetLicensedClients = new atsDataSet();
239
240 // Populate dataset
241 try
242 {
243 ProSupport.clientTableAdapter.FillClients(datasetLicensedClients.Client);
244 }
245 catch (Exception ex)
246 {
247 MessageBox.Show("Could not open datbase (77887). Error: " + ex.Message, "AnywhereTS");
248 Application.Exit();
249 return;
250 }
251 // Try to locate the client in the dataset of licensed clients.
252 DataRow rowThisClient = datasetLicensedClients.Client.Rows.Find(macAddress);
253 // Does the MAC adress not exist in database?
254 if (rowThisClient == null)
255 { // We have exceeded the license limit, terminate.
256 MessageBox.Show("The maxiumum number of licensed clients is reached. Please contact your system administrator.");
257 using (log4net.NDC.Push(string.Format("client macaddress={0}", macAddress)))
258 {
259 Logging.ATSAdminLog.Warn("The maxiumum number of licensed clients has been reached");
260 }
261 Application.Exit();
262 return;
263 }
264
265 } // if (dialogMode == ATSClientMode.CONTROL_PANEL)
266
267 // Look for the client record to edit (not when adding client)
268 if (recordState == ATSRecordState.EDIT)
269 {
270 rowCurrentClient = datasetAllClientsAndDefault.Client.Rows.Find(macAddress);
271 }
272 // Does the MAC adress not exist in database?
273 if (rowCurrentClient == null)
274 {
275 recordState = ATSRecordState.ADD;
276 }
277
278 // If in add mode, add new record
279 if (recordState == ATSRecordState.ADD)
280 {
281 // Add the client, using properties from the default record.
282 // Look up default record
283 // improve samma som i frmAdmin
284
285 rowCurrentClient = datasetAllClientsAndDefault.Client.NewRow();
286
287 ATSImageRuntimeConfig newConfig = new ATSImageRuntimeConfig();
288 newConfig.ReadDefaultFromDatabase();
289 newConfig.WriteToDatabase(rowCurrentClient);
290
291 if (dialogMode == ATSClientMode.CONTROL_PANEL)
292 { // We are running as control panel for a user that yet has no record
293
294 rowCurrentClient["macAddress"] = macAddress;
295 rowCurrentClient["clientName"] = "ATS" + macAddress;
296 }
297 else
298 { // We are adding a client from the Admin tool
299 rowCurrentClient["macAddress"] = "";
300 macAddress = "";
301 rowCurrentClient["clientName"] = "";
302 }
303 }
304
305 // Load controls
306 if (tabClientProperties.TabPages.ContainsKey("TabGeneral"))
307 {
308 if (dialogMode != ATSClientMode.EDIT_DEFAULT)
309 {
310 txtMacAddress.Text = macAddress; // Mac address for the selected client
311 txtClientName.Text = rowCurrentClient["ClientName"].ToString();
312 txtComment.Text = rowCurrentClient["Comment"].ToString();
313 }
314 }
315
316 // Read config from database
317 currentConfig.ReadFromDatabase(rowCurrentClient);
318
319 // Update controls from config
320 UpdateScreenResolutionControls(currentConfig.ScreenResolutionX, currentConfig.ScreenResolutionY);
321
322 switch (currentConfig.ScreenColorDepth)
323 {
324 case ATSImageRuntimeConfig.ATSScreenColorDepth.ATS16Bit:
325 cboColorQuality.SelectedIndex = 0;
326 break;
327 case ATSImageRuntimeConfig.ATSScreenColorDepth.ATS24Bit:
328 cboColorQuality.SelectedIndex = 1;
329 break;
330 default:
331 string error = "Error: Unhandled color depth (29901)";
332 using (log4net.NDC.Push(string.Format("ColorDepth={0}",currentConfig.ScreenColorDepth)))
333 {
334 Logging.ATSAdminLog.Error(error);
335 }
336 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("ColorDepth={0}", currentConfig.ScreenColorDepth)));
337 break;
338 }
339 chkDigitalMonitor.Checked = currentConfig.DigitalMonitor;
340 chkRedirectSound.Checked = currentConfig.RedirectSound;
341
342 txtServer.Text = currentConfig.ServerName;
343 txtDomain.Text = currentConfig.ServerDomain;
344 txtUsername.Text = currentConfig.UserName;
345 txtPassword.Text = currentConfig.Password;
346 txtApplicationSet.Text = currentConfig.ICAApplicationSet;
347 txtCitrixServerURL.Text = currentConfig.ICAServerURL;
348 txtCitrixResource.Text = currentConfig.ICAResource;
349
350 if (currentConfig.SessionType == ATSImageRuntimeConfig.ATSSessionType.ATSRDP)
351 {
352 cboConnection.SelectedIndex = 0;
353 }
354 else if (currentConfig.SessionType == ATSImageRuntimeConfig.ATSSessionType.ATSICA)
355 {
356 cboConnection.SelectedIndex = 1;
357 }
358 else if (currentConfig.SessionType == ATSImageRuntimeConfig.ATSSessionType.ATSPNA)
359 {
360 cboConnection.SelectedIndex = 2;
361 }
362 else
363 {
364 string error = "Unhandled session type (65332)";
365 using (log4net.NDC.Push(string.Format("SessionType={0}", currentConfig.SessionType)))
366 {
367 Logging.ATSAdminLog.Error(error);
368 }
369 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("SessionType={0}", currentConfig.SessionType)));
370 return;
371 }
372
373 SessionTypeChanged(); // Enable and disable rdp and ica tabs
374
375 chkReconnect.Checked = !currentConfig.ReconnectPrompt;
376
377 if (dialogMode == ATSClientMode.CONTROL_PANEL)
378 { // We are running in control panel mode. Hide password box.
379 lblPassword.Visible = false;
380 txtPassword.Visible = false;
381 }
382
383 tbrVolume.Value = currentConfig.AudioLevel;
384 tbrPointerSpeed.Value = currentConfig.MouseResolution;
385
386 // If ICA tab exists (could have been removed in the control panel)
387 if (tabClientProperties.TabPages.ContainsKey("tabIca"))
388 {
389 chkIcaCompression.Checked = currentConfig.ICACompression;
390 if (currentConfig.IcaAudioQuality == ATSImageRuntimeConfig.ATSIcaAudioQuality.Low)
391 tbrIcaAudioQuality.Value = 1;
392 else if (currentConfig.IcaAudioQuality == ATSImageRuntimeConfig.ATSIcaAudioQuality.Medium)
393 tbrIcaAudioQuality.Value = 2;
394 else if (currentConfig.IcaAudioQuality == ATSImageRuntimeConfig.ATSIcaAudioQuality.High)
395 tbrIcaAudioQuality.Value = 3;
396 else
397 {
398 string error = "Error: Unhandled audio quality (66432)";
399 using (log4net.NDC.Push(string.Format("IcaAudioQuality={0}", currentConfig.IcaAudioQuality)))
400 {
401 Logging.ATSAdminLog.Error(error);
402 }
403 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("IcaAudioQuality={0}", currentConfig.IcaAudioQuality)));
404 return;
405 }
406
407 if (currentConfig.ICAProtocol == ATSImageRuntimeConfig.ATSIcaProtocol.ATSUDP)
408 radIcaProtocolUDP.Checked = true;
409 else if (currentConfig.ICAProtocol == ATSImageRuntimeConfig.ATSIcaProtocol.ATSHTTPOnTCP)
410 radIcaProtocolHTTP.Checked = true;
411 else
412 {
413 string error = "Error: Unhandlced ICA protocol (60032)";
414 using (log4net.NDC.Push(string.Format("ICAProtocol={0}", currentConfig.ICAProtocol)))
415 {
416 Logging.ATSAdminLog.Error(error);
417 }
418 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("ICAProtocol={0}", currentConfig.ICAProtocol)));
419 return;
420 }
421
422 int i = cboIcaEncryption.FindStringExact(currentConfig.ICAEncryption);
423 if (i != -1) // Check if the item was found in the combobox.
424 {
425 cboIcaEncryption.SelectedIndex = i;
426 }
427 else
428 {
429 string error = "Error: Unhandlced ICA encryption(60033)";
430 using (log4net.NDC.Push(string.Format("ICAEncryption={0}", currentConfig.ICAEncryption)))
431 {
432 Logging.ATSAdminLog.Error(error);
433 }
434 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("ICAEncryption={0}", currentConfig.ICAEncryption)));
435 return;
436 }
437
438 }
439
440 // If RDP tab exists (could have been removed in the control panel)
441 if (tabClientProperties.TabPages.ContainsKey("tabRdp"))
442 {
443 // Update RDP controls
444 chkRedirectFloppy.Checked = currentConfig.RedirectFloppy;
445 chkRedirectCD.Checked = currentConfig.RedirectCD;
446 chkMiscCOM1.Checked = currentConfig.MiscRedirectCom1;
447 chkMiscCOM2.Checked = currentConfig.MiscRedirectCom2;
448 chkUsbMemory.Checked = currentConfig.UsbDrive == ATSImageRuntimeConfig.ATSUsbDrive.One;
449 lblServerPort.Font = new Font(lblServerPort.Font, FontStyle.Regular);
450
451
452 // Initialise server port
453 if (currentConfig.ServerPort == -1)
454 {
455 txtServerPort.Text = "";
456 }
457 else
458 {
459 txtServerPort.Text = currentConfig.ServerPort.ToString();
460 }
461 }
462
463 // If Misc tab exists (could have been removed in the control panel)
464 if (tabClientProperties.TabPages.ContainsKey("tabMisc"))
465 {
466
467 chkMiscNumLock.Font = new Font(chkMiscNumLock.Font, FontStyle.Regular);
468
469 // Initate controls from current configuration
470 chkMiscDailyreboot.Checked = currentConfig.DailyReboot;
471 chkMiscMousefix.Checked = currentConfig.MiscMousefix;
472 chkMiscFlippedFix.Checked = currentConfig.MiscFlippedFix;
473 chkMiscNoaccel.Checked = currentConfig.MiscNoAcceleration;
474 chkMiscNumLock.Checked = currentConfig.NumLock; // Note that state of ChangedByUser affects this control.
475
476 // Initiate keyboard combo
477 cboKeyboard.Items.AddRange(ATSKeyboard.keyboardDescription); // Load keyboard descriptions
478 cboKeyboard.SelectedIndex = ATSKeyboard.KeyboardCodeToIndex(currentConfig.KeyboardMap);
479
480 // Initiate timezone combo
481 cboTimezone.Items.AddRange(ATSTimeZone.timeZoneCode); // Load timezones
482 cboTimezone.SelectedIndex = ATSTimeZone.TimeZoneCodeToIndex(currentConfig.TimeZone);
483 }
484 changedByUser = true;
485 this.Cursor = Cursors.Default;
486 }
487
488
489 // OK Pressed
490 private void btnOK_Click(object sender, EventArgs e)
491 {
492 string strValidatedMacAdress = ""; // The validated MAC address.
493 string strValidatedClientName = ""; // The validated client name.
494 string strValidatedServerName = ""; // The validated server name.
495 UriHostNameType hostname; // used to validate host name
496
497 // Validate MAC address and client name, unless in Default Parameters mode, where these two
498 // parameters do not exist.
499 if (dialogMode == ATSClientMode.EDIT_CLIENT || dialogMode == ATSClientMode.NEW_CLIENT)
500 {
501 if (tabClientProperties.TabPages.ContainsKey("TabGeneral"))
502 {
503 // Validate MAC address
504 if (txtMacAddress.Text == "")
505 {
506 tabClientProperties.SelectTab("TabGeneral");
507 MessageBox.Show("You must enter a MAC address!");
508 txtMacAddress.Focus();
509 return;
510 }
511 strValidatedMacAdress = ATSGlobals.IsValidMAC(txtMacAddress.Text);
512 if (strValidatedMacAdress == "")
513 {
514 tabClientProperties.SelectTab("TabGeneral");
515 MessageBox.Show("Invalid MAC address! Please enter a valid MAC address");
516 txtMacAddress.Focus();
517 txtMacAddress.SelectAll();
518 return;
519 }
520 // For new clients:
521 if (recordState == ATSRecordState.ADD)
522 { // Does MAC address already exist?
523 if (datasetAllClientsAndDefault.Client.Rows.Find(strValidatedMacAdress) != null)
524 {
525 tabClientProperties.SelectTab("TabGeneral");
526 MessageBox.Show("MAC address " + txtMacAddress.Text.ToUpper() + " is already in use by another client! Maybe you are trying to add the same client twice?");
527 using (log4net.NDC.Push(string.Format("macaddress={0}", strValidatedMacAdress)))
528 {
529 Logging.ATSAdminLog.Warn("Attempt to duplicate an already existing MAC Address.");
530 }
531 txtMacAddress.Focus();
532 txtMacAddress.SelectAll();
533 return;
534 }
535 }
536
537 // Validate Client name, maxlen 15 already given from text box.
538 if (txtClientName.Text == "")
539 {
540 tabClientProperties.SelectTab("TabGeneral");
541 MessageBox.Show("You must enter a name for the client!");
542 txtClientName.Focus();
543 return;
544 }
545
546 strValidatedClientName = txtClientName.Text.ToUpper();
547
548 hostname = Uri.CheckHostName(strValidatedClientName);
549 if (hostname == UriHostNameType.Unknown)
550 {
551 tabClientProperties.SelectTab("TabGeneral");
552 MessageBox.Show("Client name contains invalid characters! You must enter a valid client name.");
553 txtClientName.Focus();
554 txtClientName.SelectAll();
555 return;
556 }
557
558 // Currently possible to have the same name for two clients.
559
560 /*
561 // For new clients, client name alredy taken?
562 if (dialogMode == ATSClientMode.NEW_CLIENT)
563 {
564 if (datasetClient.Client.Rows.Find(strValidatedClientName) != null)
565 {
566 MessageBox.Show("Client name " + strValidatedClientName + " is already in use by another client!");
567 txtClientName.Focus();
568 txtClientName.SelectAll();
569 return;
570 }
571 }
572 */
573 } // Tab General
574 } // If edit client or new client (but not defuault)
575
576 // Check that server name is entered.
577 strValidatedServerName = txtServer.Text.Trim();
578 if (strValidatedServerName.Length == 0)
579 {
580 tabClientProperties.SelectTab("TabConnection");
581 MessageBox.Show("You must enter a server name!");
582 txtServer.Focus();
583 txtServer.SelectAll();
584 return;
585 }
586
587 // Validate server name, maxlen 30 already given from text box.
588 strValidatedServerName = txtServer.Text.ToUpper();
589
590 hostname = Uri.CheckHostName(strValidatedServerName);
591 if (hostname == UriHostNameType.Unknown)
592 {
593 tabClientProperties.SelectTab("TabConnection");
594 MessageBox.Show("Invalid server name!");
595 txtServer.Focus();
596 txtServer.SelectAll();
597 return;
598 }
599
600 // Validate and convert server port
601 if (tabClientProperties.TabPages.ContainsKey("tabRdp"))
602 {
603 if (txtServerPort.Text.Trim().Length == 0)
604 { // No server port specified
605 currentConfig.ServerPort = -1;
606 }
607 else
608 { // The user has specified a server port
609 try
610 {
611 currentConfig.ServerPort = Int32.Parse(txtServerPort.Text.Trim());
612 }
613 catch (Exception ex)
614 {
615 tabClientProperties.SelectTab("tabRdp");
616 MessageBox.Show("Invalid server port!");
617 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
618 {
619 using (log4net.NDC.Push(string.Format("serverport={0}", txtServerPort.Text)))
620 {
621 Logging.ATSAdminLog.ErrorFormat("Invalid server port!");
622 }
623 }
624 txtServerPort.Focus();
625 txtServerPort.SelectAll();
626 return;
627 }
628 if (currentConfig.ServerPort < 0 || currentConfig.ServerPort > 65535)
629 { // Value to high or to low
630 tabClientProperties.SelectTab("tabRdp");
631 MessageBox.Show("Invalid server port!");
632 using (log4net.NDC.Push(string.Format("serverport={0}", txtServerPort.Text)))
633 {
634 Logging.ATSAdminLog.ErrorFormat("Invalid server port!");
635 }
636 txtServerPort.Focus();
637 txtServerPort.SelectAll();
638 return;
639 }
640 }
641 }
642
643
644 // Possible improvement: Did any parameters change?
645
646 // Possible improvement: One of more parameters changed, save parameters to database.
647
648
649 // Save properties to database
650 if(dialogMode != ATSClientMode.EDIT_DEFAULT) // If we are editing default, server name and MAC address should not be saved.
651 {
652 if (tabClientProperties.TabPages.ContainsKey("TabGeneral"))
653 {
654 rowCurrentClient["ClientName"] = strValidatedClientName;
655 macAddress = strValidatedMacAdress;
656 rowCurrentClient["MacAddress"] = macAddress;
657 rowCurrentClient["Comment"] = txtComment.Text;
658 }
659 }
660
661 // Resolution set by text boxes
662 try
663 {
664 currentConfig.ScreenResolutionX = Int32.Parse(txtScreenResX.Text.Trim());
665 }
666 catch (Exception ex)
667 {
668 tabClientProperties.SelectTab("TabInterface");
669 MessageBox.Show("Invalid screen resolution!");
670 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
671 {
672 using (log4net.NDC.Push(string.Format("ScreenResolutionX={0}", txtScreenResX.Text)))
673 {
674 Logging.ATSAdminLog.ErrorFormat("Invalid X screen resolution!");
675 }
676 }
677 txtScreenResX.Focus();
678 txtScreenResX.SelectAll();
679 return;
680 }
681 if (currentConfig.ScreenResolutionX < 100 || currentConfig.ScreenResolutionX > 9999)
682 { // Value to high or to low
683 tabClientProperties.SelectTab("TabInterface");
684 MessageBox.Show("Invalid screen resolution!");
685
686 using (log4net.NDC.Push(string.Format("ScreenResolutionX={0}", txtScreenResX.Text)))
687 {
688 Logging.ATSAdminLog.ErrorFormat("Invalid X screen resolution!");
689 }
690
691 txtScreenResX.Focus();
692 txtScreenResX.SelectAll();
693 return;
694 }
695
696 try
697 {
698 currentConfig.ScreenResolutionY = Int32.Parse(txtScreenResY.Text.Trim());
699 }
700 catch (Exception ex)
701 {
702 tabClientProperties.SelectTab("TabInterface");
703 MessageBox.Show("Invalid screen resolution!");
704 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
705 {
706 using (log4net.NDC.Push(string.Format("ScreenResolutionY={0}", txtScreenResY.Text)))
707 {
708 Logging.ATSAdminLog.ErrorFormat("Invalid Y screen resolution!");
709 }
710 }
711 txtScreenResY.Focus();
712 txtScreenResY.SelectAll();
713 return;
714 }
715 if (currentConfig.ScreenResolutionY < 100 || currentConfig.ScreenResolutionY > 9999)
716 { // Value to high or to low
717 tabClientProperties.SelectTab("TabInterface");
718 MessageBox.Show("Invalid screen resolution!");
719 using (log4net.NDC.Push(string.Format("ScreenResolutionY={0}", txtScreenResY.Text)))
720 {
721 Logging.ATSAdminLog.ErrorFormat("Invalid Y screen resolution!");
722 }
723 txtScreenResY.Focus();
724 txtScreenResY.SelectAll();
725 return;
726 }
727
728 switch (cboColorQuality.SelectedIndex)
729 {
730 case 0:
731 currentConfig.ScreenColorDepth = ATSImageRuntimeConfig.ATSScreenColorDepth.ATS16Bit;
732 break;
733 case 1:
734 currentConfig.ScreenColorDepth = ATSImageRuntimeConfig.ATSScreenColorDepth.ATS24Bit;
735 break;
736 default:
737 string error = "rror: Unhandled color depth (41255)";
738 using (log4net.NDC.Push(string.Format("ScreenColorDepth={0}", currentConfig.ScreenColorDepth)))
739 {
740 Logging.ATSAdminLog.Error(error);
741 }
742 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("ScreenColorDepth={0}", currentConfig.ScreenColorDepth)));
743 return;
744 }
745
746 currentConfig.ServerName = txtServer.Text.Trim();
747 currentConfig.ServerDomain = txtDomain.Text.Trim();
748 currentConfig.UserName = txtUsername.Text.Trim();
749 currentConfig.Password = txtPassword.Text;
750 currentConfig.ICAApplicationSet = txtApplicationSet.Text.Trim();
751 currentConfig.ICAServerURL = txtCitrixServerURL.Text.Trim();
752 currentConfig.ICAResource = txtCitrixResource.Text.Trim();
753
754 if (cboConnection.SelectedIndex == 0)
755 {
756 currentConfig.SessionType = ATSImageRuntimeConfig.ATSSessionType.ATSRDP;
757 }
758 else if (cboConnection.SelectedIndex == 1)
759 {
760 currentConfig.SessionType = ATSImageRuntimeConfig.ATSSessionType.ATSICA;
761 }
762 else if (cboConnection.SelectedIndex == 2)
763 {
764 currentConfig.SessionType = ATSImageRuntimeConfig.ATSSessionType.ATSPNA;
765 }
766 else
767 {
768 string error = "Error: Unhandled session type(41283)";
769 using (log4net.NDC.Push(string.Format("SessionType={0}", currentConfig.SessionType)))
770 {
771 Logging.ATSAdminLog.Error(error);
772 }
773 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("SessionType={0}", currentConfig.SessionType)));
774 return;
775 }
776
777 currentConfig.ReconnectPrompt = !chkReconnect.Checked;
778 currentConfig.AudioLevel = tbrVolume.Value;
779 currentConfig.MouseResolution = tbrPointerSpeed.Value;
780 currentConfig.DigitalMonitor = chkDigitalMonitor.Checked;
781 currentConfig.RedirectSound = chkRedirectSound.Checked;
782
783 // If ICA tab exists (could have been removed in the control panel)
784 if (tabClientProperties.TabPages.ContainsKey("tabIca"))
785 {
786 currentConfig.ICACompression = chkIcaCompression.Checked;
787 currentConfig.ICAEncryption = cboIcaEncryption.Items[cboIcaEncryption.SelectedIndex].ToString();
788 if (radIcaProtocolUDP.Checked)
789 currentConfig.ICAProtocol = ATSImageRuntimeConfig.ATSIcaProtocol.ATSUDP;
790 else
791 currentConfig.ICAProtocol = ATSImageRuntimeConfig.ATSIcaProtocol.ATSHTTPOnTCP;
792
793 if (tbrIcaAudioQuality.Value == 1)
794 currentConfig.IcaAudioQuality = ATSImageRuntimeConfig.ATSIcaAudioQuality.Low;
795 else if (tbrIcaAudioQuality.Value == 2)
796 currentConfig.IcaAudioQuality = ATSImageRuntimeConfig.ATSIcaAudioQuality.Medium;
797 else
798 currentConfig.IcaAudioQuality = ATSImageRuntimeConfig.ATSIcaAudioQuality.High;
799 }
800
801 // If RDP tab exists (could have been removed in the control panel)
802 if (tabClientProperties.TabPages.ContainsKey("tabRdp"))
803 {
804 // Save RDP options
805 currentConfig.RedirectFloppy = chkRedirectFloppy.Checked;
806 currentConfig.RedirectCD = chkRedirectCD.Checked;
807 currentConfig.MiscRedirectCom1 = chkMiscCOM1.Checked;
808 currentConfig.MiscRedirectCom2 = chkMiscCOM2.Checked;
809 if (chkUsbMemory.Checked)
810 {
811 currentConfig.UsbDrive = ATSImageRuntimeConfig.ATSUsbDrive.One;
812 }
813 else
814 {
815 currentConfig.UsbDrive = ATSImageRuntimeConfig.ATSUsbDrive.None;
816 }
817 }
818
819 // If Misc tab exists (could have been removed in the control panel)
820 if (tabClientProperties.TabPages.ContainsKey("tabMisc"))
821 {
822 // Update current configuration from controls
823 currentConfig.NumLock = chkMiscNumLock.Checked;
824 currentConfig.DailyReboot = chkMiscDailyreboot.Checked;
825 currentConfig.MiscMousefix = chkMiscMousefix.Checked;
826 currentConfig.MiscFlippedFix = chkMiscFlippedFix.Checked;
827 currentConfig.MiscNoAcceleration = chkMiscNoaccel.Checked;
828 currentConfig.TimeZone = cboTimezone.Items[cboTimezone.SelectedIndex].ToString();
829 currentConfig.KeyboardMap = ATSKeyboard.keyboardCode[cboKeyboard.SelectedIndex];
830 }
831
832 currentConfig.WriteToDatabase(rowCurrentClient); // Save config to the row
833
834 // If it is a new client, we need to add the row to the client table.
835 if (recordState == ATSRecordState.ADD)
836 {
837 datasetAllClientsAndDefault.Client.Rows.Add(rowCurrentClient);
838 }
839
840 try
841 {
842 ProSupport.clientTableAdapter.Update(datasetAllClientsAndDefault.Client);
843 }
844 catch
845 {
846 MessageBox.Show("Error, could not update database (10084). Try to redo the operation.");
847 }
848
849 if (dialogMode == ATSClientMode.EDIT_DEFAULT)
850 { // Write network config file, since the default values should be saved in the network file.
851 ProSupport.WriteConfigFiles(currentConfig, ProSupport.strNetworkConfigFilename, false);
852 }
853 else
854 {
855 // Write client config file
856 ProSupport.WriteConfigFiles(currentConfig, macAddress, true);
857 }
858
859 // If admin, try to send message to the session to restart
860
861 if (dialogMode == ATSClientMode.CONTROL_PANEL)
862 { // This form is the main and only form
863 Application.Exit();
864 }
865 else
866 { // This form is called from another form
867 DialogResult = DialogResult.OK;
868 }
869 this.Cursor = Cursors.Default;
870 }
871
872 private void btnCancel_Click(object sender, EventArgs e)
873 {
874 if (dialogMode == ATSClientMode.CONTROL_PANEL)
875 { // This form is the main and only form
876 Application.Exit();
877 }
878 else
879 { // This form is called from another form
880 DialogResult = DialogResult.Cancel;
881 }
882 }
883
884 // Display context sensitive ATS help, depending on mode (default properties or normal properties) and selected tab
885 private void ShowAtsHelp()
886 {
887 string helpKeyword = "";
888 if (dialogMode == ATSClientMode.EDIT_CLIENT || dialogMode == ATSClientMode.NEW_CLIENT)
889 { // We are running the form in edit or new mode
890 switch (tabClientProperties.SelectedTab.Name)
891 {
892 case "tabGeneral":
893 helpKeyword = "clientpropertiesgeneral.htm";
894 break;
895 case "tabConnection":
896 helpKeyword = "clientpropertiesconnection.htm";
897 break;
898 case "tabInterface":
899 helpKeyword = "clientpropertiesinterface.htm";
900 break;
901 case "tabRdp":
902 helpKeyword = "clientpropertiesrdp.htm";
903 break;
904 case "tabIca":
905 helpKeyword = "clientpropertiesica.htm";
906 break;
907 case "tabMisc":
908 helpKeyword = "clientpropertiesmisc.htm";
909 break;
910 default:
911 string error = "Error:Invalid tab (63326)";
912 using (log4net.NDC.Push(string.Format("tab={0}", tabClientProperties.SelectedTab.Name)))
913 {
914 Logging.ATSAdminLog.Error(error);
915 }
916 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("tab={0}", tabClientProperties.SelectedTab.Name)));
917 return;
918 }
919 }
920 else if (dialogMode == ATSClientMode.EDIT_DEFAULT)
921 { // We are running the form in default settings mode
922 switch (tabClientProperties.SelectedTab.Name)
923 {
924 case "tabGeneral":
925 helpKeyword = "defaultsettingsgeneral.htm";
926 break;
927 case "tabConnection":
928 helpKeyword = "defaultsettingsconnection.htm";
929 break;
930 case "tabInterface":
931 helpKeyword = "defaultsettingsinterface.htm";
932 break;
933 case "tabRdp":
934 helpKeyword = "defaultsettingsrdp.htm";
935 break;
936 case "tabIca":
937 helpKeyword = "defaultsettingsica.htm";
938 break;
939 case "tabMisc":
940 helpKeyword = "defaultsettingsmisc.htm";
941 break;
942 default:
943 string error = "Error: Invalid tab (63327)";
944 using (log4net.NDC.Push(string.Format("tab={0}", tabClientProperties.SelectedTab.Name)))
945 {
946 Logging.ATSAdminLog.Error(error);
947 }
948 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("tab={0}", tabClientProperties.SelectedTab.Name)));
949 return;
950 }
951 }
952 Help.ShowHelp(this, ATSGlobals.strHelpFilePath, HelpNavigator.Topic, helpKeyword);
953 }
954
955 private void frmClientProperties_KeyDown(object sender, KeyEventArgs e)
956 {
957 if (e.KeyCode == Keys.F1)
958 { // F1 pressed, show ATS help
959 ShowAtsHelp();
960 }
961 }
962
963 private void frmClientProperties_HelpRequested(object sender, HelpEventArgs hlpevent)
964 {
965 hlpevent.Handled = true;
966 }
967
968 // Changed connection type, enable rdp and ica tabs respectively
969 private void SessionTypeChanged()
970 {
971 if (cboConnection.SelectedIndex == 0)
972 { //RDP
973 pnlCitrixPN.Visible = false;
974 pnlApplicationSet.Visible = false;
975 }
976 else if (cboConnection.SelectedIndex == 1)
977 { //ICA
978 pnlCitrixPN.Visible = false;
979 pnlApplicationSet.Visible = true;
980 }
981 else if (cboConnection.SelectedIndex == 2)
982 { // PNA
983 pnlCitrixPN.Visible = true;
984 pnlApplicationSet.Visible = false;
985 }
986 else
987 {
988 string error = "Error: Unhandled session type (95333)";
989 using (log4net.NDC.Push(string.Format("SessionType={0}", currentConfig.SessionType)))
990 {
991 Logging.ATSAdminLog.Error(error);
992 }
993 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("SessionType={0}", currentConfig.SessionType)));
994 return;
995 }
996 }
997
998 private void UpdateScreenResolutionControls(int x, int y)
999 {
1000 txtScreenResX.Text = x.ToString();
1001 txtScreenResY.Text = y.ToString();
1002
1003 for (int i = 0; i < ATSGlobals.ScreenResolutions.GetLength(0); i++)
1004 {
1005 if (x == ATSGlobals.ScreenResolutions[i, 0] && y == ATSGlobals.ScreenResolutions[i, 1])
1006 {
1007 tbrScreenResolution.Value = i + 1;
1008 return;
1009 }
1010
1011 }
1012 // Values could not be expressed using the track bar. Set it at default.
1013 tbrScreenResolution.Value = 4;
1014 }
1015
1016 private void GetScreenResolutionFromTrackbar(TrackBar tbr, out int x, out int y)
1017 {
1018 x = ATSGlobals.ScreenResolutions[tbr.Value -1,0];
1019 y = ATSGlobals.ScreenResolutions[tbr.Value - 1, 1];
1020 }
1021
1022 private void tbrScreenResolution_Scroll(object sender, EventArgs e)
1023 {
1024 if (changedByUser)
1025 {
1026 int x, y;
1027 // Convert values from trackbar
1028 GetScreenResolutionFromTrackbar(tbrScreenResolution, out x, out y);
1029 txtScreenResX.Text = x.ToString();
1030 txtScreenResY.Text = y.ToString();
1031 }
1032 }
1033
1034 private void UpdateResolutionTrackbar()
1035 { // Try to convert x, y values to trackbar.
1036 int x, y;
1037 try
1038 {
1039 x = Int32.Parse(txtScreenResX.Text.Trim());
1040 }
1041 catch (Exception)
1042 {
1043 x = 0;
1044 }
1045
1046 try
1047 {
1048 y = Int32.Parse(txtScreenResY.Text.Trim());
1049 }
1050 catch (Exception)
1051 {
1052 y = 0;
1053 }
1054
1055 UpdateScreenResolutionControls(x, y);
1056 }
1057
1058
1059 private void cboConnection_SelectedIndexChanged(object sender, EventArgs e)
1060 {
1061 SessionTypeChanged();
1062 }
1063
1064 }
1065 }

  ViewVC Help
Powered by ViewVC 1.1.22