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

Contents of /trunk/TSAdminTool/frmClientProperties.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 59 - (show annotations) (download)
Thu Jul 12 17:03:02 2012 UTC (8 years, 1 month ago) by william
File size: 47266 byte(s)
don't change cursor to waitcursor on form load

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

  ViewVC Help
Powered by ViewVC 1.1.22