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

Annotation of /trunk/TSAdminTool/frmClientProperties.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 61 - (hide annotations) (download)
Thu Jul 12 17:34:46 2012 UTC (8 years, 11 months ago) by william
File size: 45986 byte(s)
+ more wip for unhandled exception

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

  ViewVC Help
Powered by ViewVC 1.1.22