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

Annotation of /trunk/TSAdminTool/frmClientProperties.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 190 - (hide annotations) (download)
Mon Jul 16 16:03:22 2012 UTC (8 years, 11 months ago) by william
File size: 50305 byte(s)
+ update non-AnywhereTS client message - add note that the client must be added in ATSAdmin

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

  ViewVC Help
Powered by ViewVC 1.1.22