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

Annotation of /trunk/TSAdminTool/frmClientProperties.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 116 - (hide annotations) (download)
Sat Jul 14 08:03:33 2012 UTC (8 years, 11 months ago) by william
File size: 50277 byte(s)
+ more logging work

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

  ViewVC Help
Powered by ViewVC 1.1.22