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

Annotation of /trunk/TSAdminTool/frmClientProperties.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 64 - (hide annotations) (download)
Thu Jul 12 18:56:31 2012 UTC (8 years, 11 months ago) by william
File size: 49867 byte(s)
+ more exception logging

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 william 64 string error = "Error: Unhandled color depth (29901)";
328     using (log4net.NDC.Push(string.Format("ColorDepth={0}",currentConfig.ScreenColorDepth)))
329     {
330     Logging.ATSAdminLog.Error(error);
331     }
332     MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("ColorDepth={0}", currentConfig.ScreenColorDepth)));
333     break;
334 william 4 }
335     chkDigitalMonitor.Checked = currentConfig.DigitalMonitor;
336     chkRedirectSound.Checked = currentConfig.RedirectSound;
337    
338     txtServer.Text = currentConfig.ServerName;
339     txtDomain.Text = currentConfig.ServerDomain;
340     txtUsername.Text = currentConfig.UserName;
341     txtPassword.Text = currentConfig.Password;
342     txtApplicationSet.Text = currentConfig.ICAApplicationSet;
343     txtCitrixServerURL.Text = currentConfig.ICAServerURL;
344     txtCitrixResource.Text = currentConfig.ICAResource;
345    
346     if (currentConfig.SessionType == ATSImageRuntimeConfig.ATSSessionType.ATSRDP)
347     {
348     cboConnection.SelectedIndex = 0;
349     }
350     else if (currentConfig.SessionType == ATSImageRuntimeConfig.ATSSessionType.ATSICA)
351     {
352     cboConnection.SelectedIndex = 1;
353     }
354     else if (currentConfig.SessionType == ATSImageRuntimeConfig.ATSSessionType.ATSPNA)
355     {
356     cboConnection.SelectedIndex = 2;
357     }
358     else
359 william 64 {
360     string error = "Unhandled session type (65332)";
361     using (log4net.NDC.Push(string.Format("SessionType={0}", currentConfig.SessionType)))
362     {
363     Logging.ATSAdminLog.Error(error);
364     }
365     MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("SessionType={0}", currentConfig.SessionType)));
366     return;
367     }
368 william 4
369     SessionTypeChanged(); // Enable and disable rdp and ica tabs
370    
371     chkReconnect.Checked = !currentConfig.ReconnectPrompt;
372    
373     if (dialogMode == ATSClientMode.CONTROL_PANEL)
374     { // We are running in control panel mode. Hide password box.
375     lblPassword.Visible = false;
376     txtPassword.Visible = false;
377     }
378    
379     tbrVolume.Value = currentConfig.AudioLevel;
380     tbrPointerSpeed.Value = currentConfig.MouseResolution;
381    
382     // If ICA tab exists (could have been removed in the control panel)
383     if (tabClientProperties.TabPages.ContainsKey("tabIca"))
384     {
385     chkIcaCompression.Checked = currentConfig.ICACompression;
386     if (currentConfig.IcaAudioQuality == ATSImageRuntimeConfig.ATSIcaAudioQuality.Low)
387     tbrIcaAudioQuality.Value = 1;
388     else if (currentConfig.IcaAudioQuality == ATSImageRuntimeConfig.ATSIcaAudioQuality.Medium)
389     tbrIcaAudioQuality.Value = 2;
390     else if (currentConfig.IcaAudioQuality == ATSImageRuntimeConfig.ATSIcaAudioQuality.High)
391     tbrIcaAudioQuality.Value = 3;
392     else
393 william 64 {
394     string error = "Error: Unhandled audio quality (66432)";
395     using (log4net.NDC.Push(string.Format("IcaAudioQuality={0}", currentConfig.IcaAudioQuality)))
396     {
397     Logging.ATSAdminLog.Error(error);
398     }
399     MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("IcaAudioQuality={0}", currentConfig.IcaAudioQuality)));
400     return;
401     }
402 william 4
403     if (currentConfig.ICAProtocol == ATSImageRuntimeConfig.ATSIcaProtocol.ATSUDP)
404     radIcaProtocolUDP.Checked = true;
405     else if (currentConfig.ICAProtocol == ATSImageRuntimeConfig.ATSIcaProtocol.ATSHTTPOnTCP)
406     radIcaProtocolHTTP.Checked = true;
407     else
408 william 64 {
409     string error = "Error: Unhandlced ICA protocol (60032)";
410     using (log4net.NDC.Push(string.Format("ICAProtocol={0}", currentConfig.ICAProtocol)))
411     {
412     Logging.ATSAdminLog.Error(error);
413     }
414     MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("ICAProtocol={0}", currentConfig.ICAProtocol)));
415     return;
416     }
417 william 4
418     int i = cboIcaEncryption.FindStringExact(currentConfig.ICAEncryption);
419     if (i != -1) // Check if the item was found in the combobox.
420     {
421 william 64 cboIcaEncryption.SelectedIndex = i;
422 william 4 }
423     else
424 william 64 {
425     string error = "Error: Unhandlced ICA encryption(60033)";
426     using (log4net.NDC.Push(string.Format("ICAEncryption={0}", currentConfig.ICAEncryption)))
427     {
428     Logging.ATSAdminLog.Error(error);
429     }
430     MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("ICAEncryption={0}", currentConfig.ICAEncryption)));
431     return;
432     }
433 william 4
434     }
435    
436     // If RDP tab exists (could have been removed in the control panel)
437     if (tabClientProperties.TabPages.ContainsKey("tabRdp"))
438     {
439     // Update RDP controls
440     chkRedirectFloppy.Checked = currentConfig.RedirectFloppy;
441     chkRedirectCD.Checked = currentConfig.RedirectCD;
442     chkMiscCOM1.Checked = currentConfig.MiscRedirectCom1;
443     chkMiscCOM2.Checked = currentConfig.MiscRedirectCom2;
444     chkUsbMemory.Checked = currentConfig.UsbDrive == ATSImageRuntimeConfig.ATSUsbDrive.One;
445     lblServerPort.Font = new Font(lblServerPort.Font, FontStyle.Regular);
446    
447    
448     // Initialise server port
449     if (currentConfig.ServerPort == -1)
450     {
451     txtServerPort.Text = "";
452     }
453     else
454     {
455     txtServerPort.Text = currentConfig.ServerPort.ToString();
456     }
457     }
458    
459     // If Misc tab exists (could have been removed in the control panel)
460     if (tabClientProperties.TabPages.ContainsKey("tabMisc"))
461     {
462    
463     chkMiscNumLock.Font = new Font(chkMiscNumLock.Font, FontStyle.Regular);
464    
465     // Initate controls from current configuration
466     chkMiscDailyreboot.Checked = currentConfig.DailyReboot;
467     chkMiscMousefix.Checked = currentConfig.MiscMousefix;
468     chkMiscFlippedFix.Checked = currentConfig.MiscFlippedFix;
469     chkMiscNoaccel.Checked = currentConfig.MiscNoAcceleration;
470     chkMiscNumLock.Checked = currentConfig.NumLock; // Note that state of ChangedByUser affects this control.
471    
472     // Initiate keyboard combo
473     cboKeyboard.Items.AddRange(ATSKeyboard.keyboardDescription); // Load keyboard descriptions
474     cboKeyboard.SelectedIndex = ATSKeyboard.KeyboardCodeToIndex(currentConfig.KeyboardMap);
475    
476     // Initiate timezone combo
477     cboTimezone.Items.AddRange(ATSTimeZone.timeZoneCode); // Load timezones
478     cboTimezone.SelectedIndex = ATSTimeZone.TimeZoneCodeToIndex(currentConfig.TimeZone);
479     }
480     changedByUser = true;
481     this.Cursor = Cursors.Default;
482     }
483    
484    
485     // OK Pressed
486     private void btnOK_Click(object sender, EventArgs e)
487     {
488     string strValidatedMacAdress = ""; // The validated MAC address.
489     string strValidatedClientName = ""; // The validated client name.
490     string strValidatedServerName = ""; // The validated server name.
491     UriHostNameType hostname; // used to validate host name
492    
493     // Validate MAC address and client name, unless in Default Parameters mode, where these two
494     // parameters do not exist.
495     if (dialogMode == ATSClientMode.EDIT_CLIENT || dialogMode == ATSClientMode.NEW_CLIENT)
496     {
497     if (tabClientProperties.TabPages.ContainsKey("TabGeneral"))
498     {
499     // Validate MAC address
500     if (txtMacAddress.Text == "")
501     {
502     tabClientProperties.SelectTab("TabGeneral");
503     MessageBox.Show("You must enter a MAC address!");
504     txtMacAddress.Focus();
505     return;
506     }
507     strValidatedMacAdress = ATSGlobals.IsValidMAC(txtMacAddress.Text);
508     if (strValidatedMacAdress == "")
509     {
510     tabClientProperties.SelectTab("TabGeneral");
511     MessageBox.Show("Invalid MAC address! Please enter a valid MAC address");
512     txtMacAddress.Focus();
513     txtMacAddress.SelectAll();
514     return;
515     }
516     // For new clients:
517     if (recordState == ATSRecordState.ADD)
518     { // Does MAC address already exist?
519     if (datasetAllClientsAndDefault.Client.Rows.Find(strValidatedMacAdress) != null)
520     {
521     tabClientProperties.SelectTab("TabGeneral");
522     MessageBox.Show("MAC address " + txtMacAddress.Text.ToUpper() + " is already in use by another client! Maybe you are trying to add the same client twice?");
523 william 46 using (log4net.NDC.Push(string.Format("macaddress={0}", strValidatedMacAdress)))
524     {
525     Logging.ATSAdminLog.Warn("Attempt to duplicate an already existing MAC Address.");
526     }
527 william 4 txtMacAddress.Focus();
528     txtMacAddress.SelectAll();
529     return;
530     }
531     }
532    
533     // Validate Client name, maxlen 15 already given from text box.
534     if (txtClientName.Text == "")
535     {
536     tabClientProperties.SelectTab("TabGeneral");
537     MessageBox.Show("You must enter a name for the client!");
538     txtClientName.Focus();
539     return;
540     }
541    
542     strValidatedClientName = txtClientName.Text.ToUpper();
543    
544     hostname = Uri.CheckHostName(strValidatedClientName);
545     if (hostname == UriHostNameType.Unknown)
546     {
547     tabClientProperties.SelectTab("TabGeneral");
548     MessageBox.Show("Client name contains invalid characters! You must enter a valid client name.");
549     txtClientName.Focus();
550     txtClientName.SelectAll();
551     return;
552     }
553    
554     // Currently possible to have the same name for two clients.
555    
556     /*
557     // For new clients, client name alredy taken?
558     if (dialogMode == ATSClientMode.NEW_CLIENT)
559     {
560     if (datasetClient.Client.Rows.Find(strValidatedClientName) != null)
561     {
562     MessageBox.Show("Client name " + strValidatedClientName + " is already in use by another client!");
563     txtClientName.Focus();
564     txtClientName.SelectAll();
565     return;
566     }
567     }
568     */
569     } // Tab General
570     } // If edit client or new client (but not defuault)
571    
572     // Check that server name is entered.
573     strValidatedServerName = txtServer.Text.Trim();
574     if (strValidatedServerName.Length == 0)
575     {
576     tabClientProperties.SelectTab("TabConnection");
577     MessageBox.Show("You must enter a server name!");
578     txtServer.Focus();
579     txtServer.SelectAll();
580     return;
581     }
582    
583     // Validate server name, maxlen 30 already given from text box.
584     strValidatedServerName = txtServer.Text.ToUpper();
585    
586     hostname = Uri.CheckHostName(strValidatedServerName);
587     if (hostname == UriHostNameType.Unknown)
588     {
589     tabClientProperties.SelectTab("TabConnection");
590     MessageBox.Show("Invalid server name!");
591     txtServer.Focus();
592     txtServer.SelectAll();
593     return;
594     }
595    
596     // Validate and convert server port
597     if (tabClientProperties.TabPages.ContainsKey("tabRdp"))
598     {
599     if (txtServerPort.Text.Trim().Length == 0)
600     { // No server port specified
601     currentConfig.ServerPort = -1;
602     }
603     else
604     { // The user has specified a server port
605     try
606     {
607     currentConfig.ServerPort = Int32.Parse(txtServerPort.Text.Trim());
608     }
609 william 47 catch (Exception ex)
610 william 4 {
611     tabClientProperties.SelectTab("tabRdp");
612     MessageBox.Show("Invalid server port!");
613 william 47 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
614 william 46 {
615     using (log4net.NDC.Push(string.Format("serverport={0}", txtServerPort.Text)))
616     {
617     Logging.ATSAdminLog.ErrorFormat("Invalid server port!");
618     }
619     }
620 william 4 txtServerPort.Focus();
621     txtServerPort.SelectAll();
622     return;
623     }
624     if (currentConfig.ServerPort < 0 || currentConfig.ServerPort > 65535)
625     { // Value to high or to low
626     tabClientProperties.SelectTab("tabRdp");
627 william 46 MessageBox.Show("Invalid server port!");
628     using (log4net.NDC.Push(string.Format("serverport={0}", txtServerPort.Text)))
629     {
630     Logging.ATSAdminLog.ErrorFormat("Invalid server port!");
631     }
632 william 4 txtServerPort.Focus();
633     txtServerPort.SelectAll();
634     return;
635     }
636     }
637     }
638    
639    
640     // Possible improvement: Did any parameters change?
641    
642     // Possible improvement: One of more parameters changed, save parameters to database.
643    
644    
645     // Save properties to database
646     if(dialogMode != ATSClientMode.EDIT_DEFAULT) // If we are editing default, server name and MAC address should not be saved.
647     {
648     if (tabClientProperties.TabPages.ContainsKey("TabGeneral"))
649     {
650     rowCurrentClient["ClientName"] = strValidatedClientName;
651     macAddress = strValidatedMacAdress;
652     rowCurrentClient["MacAddress"] = macAddress;
653     rowCurrentClient["Comment"] = txtComment.Text;
654     }
655     }
656    
657     // Resolution set by text boxes
658     try
659     {
660     currentConfig.ScreenResolutionX = Int32.Parse(txtScreenResX.Text.Trim());
661     }
662 william 46 catch (Exception ex)
663 william 4 {
664     tabClientProperties.SelectTab("TabInterface");
665     MessageBox.Show("Invalid screen resolution!");
666 william 46 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
667     {
668     using (log4net.NDC.Push(string.Format("ScreenResolutionX={0}", txtScreenResX.Text)))
669     {
670     Logging.ATSAdminLog.ErrorFormat("Invalid X screen resolution!");
671     }
672     }
673 william 4 txtScreenResX.Focus();
674     txtScreenResX.SelectAll();
675     return;
676     }
677     if (currentConfig.ScreenResolutionX < 100 || currentConfig.ScreenResolutionX > 9999)
678     { // Value to high or to low
679     tabClientProperties.SelectTab("TabInterface");
680     MessageBox.Show("Invalid screen resolution!");
681 william 46
682     using (log4net.NDC.Push(string.Format("ScreenResolutionX={0}", txtScreenResX.Text)))
683     {
684     Logging.ATSAdminLog.ErrorFormat("Invalid X screen resolution!");
685     }
686    
687 william 4 txtScreenResX.Focus();
688     txtScreenResX.SelectAll();
689     return;
690     }
691    
692     try
693     {
694     currentConfig.ScreenResolutionY = Int32.Parse(txtScreenResY.Text.Trim());
695     }
696 william 46 catch (Exception ex)
697 william 4 {
698     tabClientProperties.SelectTab("TabInterface");
699     MessageBox.Show("Invalid screen resolution!");
700 william 46 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
701     {
702     using (log4net.NDC.Push(string.Format("ScreenResolutionY={0}", txtScreenResY.Text)))
703     {
704     Logging.ATSAdminLog.ErrorFormat("Invalid Y screen resolution!");
705     }
706     }
707 william 4 txtScreenResY.Focus();
708     txtScreenResY.SelectAll();
709     return;
710     }
711     if (currentConfig.ScreenResolutionY < 100 || currentConfig.ScreenResolutionY > 9999)
712     { // Value to high or to low
713     tabClientProperties.SelectTab("TabInterface");
714     MessageBox.Show("Invalid screen resolution!");
715 william 46 using (log4net.NDC.Push(string.Format("ScreenResolutionY={0}", txtScreenResY.Text)))
716     {
717     Logging.ATSAdminLog.ErrorFormat("Invalid Y screen resolution!");
718     }
719 william 4 txtScreenResY.Focus();
720     txtScreenResY.SelectAll();
721     return;
722     }
723    
724     switch (cboColorQuality.SelectedIndex)
725     {
726     case 0:
727     currentConfig.ScreenColorDepth = ATSImageRuntimeConfig.ATSScreenColorDepth.ATS16Bit;
728     break;
729     case 1:
730     currentConfig.ScreenColorDepth = ATSImageRuntimeConfig.ATSScreenColorDepth.ATS24Bit;
731     break;
732 william 64 default:
733     string error = "rror: Unhandled color depth (41255)";
734     using (log4net.NDC.Push(string.Format("ScreenColorDepth={0}", currentConfig.ScreenColorDepth)))
735     {
736     Logging.ATSAdminLog.Error(error);
737     }
738     MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("ScreenColorDepth={0}", currentConfig.ScreenColorDepth)));
739     return;
740 william 4 }
741    
742     currentConfig.ServerName = txtServer.Text.Trim();
743     currentConfig.ServerDomain = txtDomain.Text.Trim();
744     currentConfig.UserName = txtUsername.Text.Trim();
745     currentConfig.Password = txtPassword.Text;
746     currentConfig.ICAApplicationSet = txtApplicationSet.Text.Trim();
747     currentConfig.ICAServerURL = txtCitrixServerURL.Text.Trim();
748     currentConfig.ICAResource = txtCitrixResource.Text.Trim();
749    
750     if (cboConnection.SelectedIndex == 0)
751     {
752     currentConfig.SessionType = ATSImageRuntimeConfig.ATSSessionType.ATSRDP;
753     }
754     else if (cboConnection.SelectedIndex == 1)
755     {
756     currentConfig.SessionType = ATSImageRuntimeConfig.ATSSessionType.ATSICA;
757     }
758     else if (cboConnection.SelectedIndex == 2)
759     {
760     currentConfig.SessionType = ATSImageRuntimeConfig.ATSSessionType.ATSPNA;
761     }
762     else
763 william 64 {
764     string error = "Error: Unhandled session type(41283)";
765     using (log4net.NDC.Push(string.Format("SessionType={0}", currentConfig.SessionType)))
766     {
767     Logging.ATSAdminLog.Error(error);
768     }
769     MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("SessionType={0}", currentConfig.SessionType)));
770     return;
771     }
772 william 4
773     currentConfig.ReconnectPrompt = !chkReconnect.Checked;
774     currentConfig.AudioLevel = tbrVolume.Value;
775     currentConfig.MouseResolution = tbrPointerSpeed.Value;
776     currentConfig.DigitalMonitor = chkDigitalMonitor.Checked;
777     currentConfig.RedirectSound = chkRedirectSound.Checked;
778    
779     // If ICA tab exists (could have been removed in the control panel)
780     if (tabClientProperties.TabPages.ContainsKey("tabIca"))
781     {
782     currentConfig.ICACompression = chkIcaCompression.Checked;
783     currentConfig.ICAEncryption = cboIcaEncryption.Items[cboIcaEncryption.SelectedIndex].ToString();
784     if (radIcaProtocolUDP.Checked)
785     currentConfig.ICAProtocol = ATSImageRuntimeConfig.ATSIcaProtocol.ATSUDP;
786     else
787     currentConfig.ICAProtocol = ATSImageRuntimeConfig.ATSIcaProtocol.ATSHTTPOnTCP;
788    
789     if (tbrIcaAudioQuality.Value == 1)
790     currentConfig.IcaAudioQuality = ATSImageRuntimeConfig.ATSIcaAudioQuality.Low;
791     else if (tbrIcaAudioQuality.Value == 2)
792     currentConfig.IcaAudioQuality = ATSImageRuntimeConfig.ATSIcaAudioQuality.Medium;
793     else
794     currentConfig.IcaAudioQuality = ATSImageRuntimeConfig.ATSIcaAudioQuality.High;
795     }
796    
797     // If RDP tab exists (could have been removed in the control panel)
798     if (tabClientProperties.TabPages.ContainsKey("tabRdp"))
799     {
800     // Save RDP options
801     currentConfig.RedirectFloppy = chkRedirectFloppy.Checked;
802     currentConfig.RedirectCD = chkRedirectCD.Checked;
803     currentConfig.MiscRedirectCom1 = chkMiscCOM1.Checked;
804     currentConfig.MiscRedirectCom2 = chkMiscCOM2.Checked;
805     if (chkUsbMemory.Checked)
806     {
807     currentConfig.UsbDrive = ATSImageRuntimeConfig.ATSUsbDrive.One;
808     }
809     else
810     {
811     currentConfig.UsbDrive = ATSImageRuntimeConfig.ATSUsbDrive.None;
812     }
813     }
814    
815     // If Misc tab exists (could have been removed in the control panel)
816     if (tabClientProperties.TabPages.ContainsKey("tabMisc"))
817     {
818     // Update current configuration from controls
819     currentConfig.NumLock = chkMiscNumLock.Checked;
820     currentConfig.DailyReboot = chkMiscDailyreboot.Checked;
821     currentConfig.MiscMousefix = chkMiscMousefix.Checked;
822     currentConfig.MiscFlippedFix = chkMiscFlippedFix.Checked;
823     currentConfig.MiscNoAcceleration = chkMiscNoaccel.Checked;
824     currentConfig.TimeZone = cboTimezone.Items[cboTimezone.SelectedIndex].ToString();
825     currentConfig.KeyboardMap = ATSKeyboard.keyboardCode[cboKeyboard.SelectedIndex];
826     }
827    
828     currentConfig.WriteToDatabase(rowCurrentClient); // Save config to the row
829    
830     // If it is a new client, we need to add the row to the client table.
831     if (recordState == ATSRecordState.ADD)
832     {
833     datasetAllClientsAndDefault.Client.Rows.Add(rowCurrentClient);
834     }
835    
836     try
837     {
838     ProSupport.clientTableAdapter.Update(datasetAllClientsAndDefault.Client);
839     }
840     catch
841     {
842     MessageBox.Show("Error, could not update database (10084). Try to redo the operation.");
843     }
844    
845     if (dialogMode == ATSClientMode.EDIT_DEFAULT)
846     { // Write network config file, since the default values should be saved in the network file.
847     ProSupport.WriteConfigFiles(currentConfig, ProSupport.strNetworkConfigFilename, false);
848     }
849     else
850     {
851     // Write client config file
852     ProSupport.WriteConfigFiles(currentConfig, macAddress, true);
853     }
854    
855     // If admin, try to send message to the session to restart
856    
857     if (dialogMode == ATSClientMode.CONTROL_PANEL)
858     { // This form is the main and only form
859     Application.Exit();
860     }
861     else
862     { // This form is called from another form
863     DialogResult = DialogResult.OK;
864     }
865     this.Cursor = Cursors.Default;
866     }
867    
868     private void btnCancel_Click(object sender, EventArgs e)
869     {
870     if (dialogMode == ATSClientMode.CONTROL_PANEL)
871     { // This form is the main and only form
872     Application.Exit();
873     }
874     else
875     { // This form is called from another form
876     DialogResult = DialogResult.Cancel;
877     }
878     }
879    
880     // Display context sensitive ATS help, depending on mode (default properties or normal properties) and selected tab
881     private void ShowAtsHelp()
882     {
883     string helpKeyword = "";
884     if (dialogMode == ATSClientMode.EDIT_CLIENT || dialogMode == ATSClientMode.NEW_CLIENT)
885     { // We are running the form in edit or new mode
886     switch (tabClientProperties.SelectedTab.Name)
887     {
888     case "tabGeneral":
889     helpKeyword = "clientpropertiesgeneral.htm";
890     break;
891     case "tabConnection":
892     helpKeyword = "clientpropertiesconnection.htm";
893     break;
894     case "tabInterface":
895     helpKeyword = "clientpropertiesinterface.htm";
896     break;
897     case "tabRdp":
898     helpKeyword = "clientpropertiesrdp.htm";
899     break;
900     case "tabIca":
901     helpKeyword = "clientpropertiesica.htm";
902     break;
903     case "tabMisc":
904     helpKeyword = "clientpropertiesmisc.htm";
905     break;
906     default:
907 william 64 string error = "Error:Invalid tab (63326)";
908     using (log4net.NDC.Push(string.Format("tab={0}", tabClientProperties.SelectedTab.Name)))
909     {
910     Logging.ATSAdminLog.Error(error);
911     }
912     MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("tab={0}", tabClientProperties.SelectedTab.Name)));
913     return;
914 william 4 }
915     }
916     else if (dialogMode == ATSClientMode.EDIT_DEFAULT)
917     { // We are running the form in default settings mode
918     switch (tabClientProperties.SelectedTab.Name)
919     {
920     case "tabGeneral":
921     helpKeyword = "defaultsettingsgeneral.htm";
922     break;
923     case "tabConnection":
924     helpKeyword = "defaultsettingsconnection.htm";
925     break;
926     case "tabInterface":
927     helpKeyword = "defaultsettingsinterface.htm";
928     break;
929     case "tabRdp":
930     helpKeyword = "defaultsettingsrdp.htm";
931     break;
932     case "tabIca":
933     helpKeyword = "defaultsettingsica.htm";
934     break;
935     case "tabMisc":
936     helpKeyword = "defaultsettingsmisc.htm";
937     break;
938     default:
939 william 64 string error = "Error: Invalid tab (63327)";
940     using (log4net.NDC.Push(string.Format("tab={0}", tabClientProperties.SelectedTab.Name)))
941     {
942     Logging.ATSAdminLog.Error(error);
943     }
944     MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("tab={0}", tabClientProperties.SelectedTab.Name)));
945     return;
946 william 4 }
947     }
948     Help.ShowHelp(this, ATSGlobals.strHelpFilePath, HelpNavigator.Topic, helpKeyword);
949     }
950    
951     private void frmClientProperties_KeyDown(object sender, KeyEventArgs e)
952     {
953     if (e.KeyCode == Keys.F1)
954     { // F1 pressed, show ATS help
955     ShowAtsHelp();
956     }
957     }
958    
959     private void frmClientProperties_HelpRequested(object sender, HelpEventArgs hlpevent)
960     {
961     hlpevent.Handled = true;
962     }
963    
964     // Changed connection type, enable rdp and ica tabs respectively
965     private void SessionTypeChanged()
966     {
967     if (cboConnection.SelectedIndex == 0)
968     { //RDP
969     pnlCitrixPN.Visible = false;
970     pnlApplicationSet.Visible = false;
971     }
972     else if (cboConnection.SelectedIndex == 1)
973     { //ICA
974     pnlCitrixPN.Visible = false;
975     pnlApplicationSet.Visible = true;
976     }
977     else if (cboConnection.SelectedIndex == 2)
978     { // PNA
979     pnlCitrixPN.Visible = true;
980     pnlApplicationSet.Visible = false;
981     }
982     else
983 william 64 {
984     string error = "Error: Unhandled session type (95333)";
985     using (log4net.NDC.Push(string.Format("SessionType={0}", currentConfig.SessionType)))
986     {
987     Logging.ATSAdminLog.Error(error);
988     }
989     MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("SessionType={0}", currentConfig.SessionType)));
990     return;
991     }
992 william 4 }
993    
994     private void UpdateScreenResolutionControls(int x, int y)
995     {
996     txtScreenResX.Text = x.ToString();
997     txtScreenResY.Text = y.ToString();
998    
999     for (int i = 0; i < ATSGlobals.ScreenResolutions.GetLength(0); i++)
1000     {
1001     if (x == ATSGlobals.ScreenResolutions[i, 0] && y == ATSGlobals.ScreenResolutions[i, 1])
1002     {
1003     tbrScreenResolution.Value = i + 1;
1004     return;
1005     }
1006    
1007     }
1008     // Values could not be expressed using the track bar. Set it at default.
1009     tbrScreenResolution.Value = 4;
1010     }
1011    
1012     private void GetScreenResolutionFromTrackbar(TrackBar tbr, out int x, out int y)
1013     {
1014     x = ATSGlobals.ScreenResolutions[tbr.Value -1,0];
1015     y = ATSGlobals.ScreenResolutions[tbr.Value - 1, 1];
1016     }
1017    
1018     private void tbrScreenResolution_Scroll(object sender, EventArgs e)
1019     {
1020     if (changedByUser)
1021     {
1022     int x, y;
1023     // Convert values from trackbar
1024     GetScreenResolutionFromTrackbar(tbrScreenResolution, out x, out y);
1025     txtScreenResX.Text = x.ToString();
1026     txtScreenResY.Text = y.ToString();
1027     }
1028     }
1029    
1030     private void UpdateResolutionTrackbar()
1031     { // Try to convert x, y values to trackbar.
1032     int x, y;
1033     try
1034     {
1035     x = Int32.Parse(txtScreenResX.Text.Trim());
1036     }
1037     catch (Exception)
1038     {
1039     x = 0;
1040     }
1041    
1042     try
1043     {
1044     y = Int32.Parse(txtScreenResY.Text.Trim());
1045     }
1046     catch (Exception)
1047     {
1048     y = 0;
1049     }
1050    
1051     UpdateScreenResolutionControls(x, y);
1052     }
1053    
1054    
1055     private void cboConnection_SelectedIndexChanged(object sender, EventArgs e)
1056     {
1057     SessionTypeChanged();
1058     }
1059    
1060     }
1061     }

  ViewVC Help
Powered by ViewVC 1.1.22