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

Contents of /trunk/TSAdminTool/ImageRuntimeConfig.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 405 - (show annotations) (download)
Tue Aug 28 09:38:56 2012 UTC (7 years, 5 months ago) by william
File size: 37234 byte(s)
+ Allow X-SERVER to detect Vertical Refresh rate (removed the overriding #define and made it permanent)
+ Image wizard will use VESA for the auto-detect gfx driver (removed the overriding #define and made it permanent)

1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Data;
5 using System.IO;
6 using System.Net;
7 using System.Windows.Forms;
8 using log4net;
9 using System.Linq;
10 namespace AnywhereTS
11 {
12 // An image config set for an ATSImage, AnywhereTS Image
13 public class ATSImageRuntimeConfig
14 {
15
16 public enum ATSScreenColorDepth
17 {
18 ATS16Bit =16,
19 ATS24Bit =24,
20 }
21
22 public enum ATSSessionType
23 {
24 ATSRDP,
25 ATSICA,
26 ATSPNA
27 }
28
29 public enum ATSServerVersion
30 {
31 ATSWin2000,
32 ATSWin2003 // 2003 or later
33 }
34
35 public enum ATSIcaProtocol
36 {
37 ATSUDP,
38 ATSHTTPOnTCP
39 }
40
41 public enum ATSIcaAudioQuality
42 {
43 Low,
44 Medium,
45 High
46 }
47
48 public enum ATSUsbDrive
49 {
50 None,
51 One,
52 Many
53 }
54
55
56 // Client options with defined defaults
57 public int ScreenResolutionX = 1024;
58 public int ScreenResolutionY = 768;
59
60 public ATSScreenColorDepth ScreenColorDepth = ATSScreenColorDepth.ATS16Bit;
61
62 public string ServerName ="";
63 public string ServerDomain = "";
64 public ATSServerVersion ServerVersion = ATSServerVersion.ATSWin2003; // Meta option, used to control other options. Only used if the server is another computer than the one running AnywhereTS
65 public ATSSessionType SessionType = ATSSessionType.ATSRDP;
66
67 public bool NumLock = true; // true = numlook on at boot time
68 public bool ReconnectPrompt = true;
69 public bool RedirectFloppy = true;
70 public bool RedirectCD = true;
71 public bool RedirectSound = true;
72 public int AudioLevel = 100;
73 public int MouseResolution = 50;
74 public string UserName = "";
75 public string Password = "";
76
77 public bool DailyReboot = true;
78
79 public string KeyboardMap = ATSKeyboard.DefaultKeyboardMap();
80 public string TimeZone = ATSTimeZone.DefaultTimeZone();
81
82 public bool DigitalMonitor = true; // Will force 60 Hz for digital monitors
83
84 public ATSIcaProtocol ICAProtocol = ATSIcaProtocol.ATSUDP;
85 public string ICAEncryption = "Basic";
86 public bool ICACompression = true;
87 public ATSIcaAudioQuality IcaAudioQuality = ATSIcaAudioQuality.High;
88 public string ICAServer = "";
89 public string ICAApplicationSet = "";
90 public string ICAServerURL = "";
91 public string ICAResource = "XenDesktop";
92
93 public string GraphicsAdapter = ""; // "" = Autodetect
94
95 public bool MiscFlippedFix = false;
96 public bool MiscMousefix = false;
97 public bool MiscNoAcceleration = false;
98 public bool MiscRedirectCom1 = false;
99 public bool MiscRedirectCom2 = false;
100 public ATSUsbDrive UsbDrive = ATSUsbDrive.None; // One is default if Pro version
101 public string UsbDriveName = "USB-Memory";
102 public int ServerPort = -1; // -1 = Not defined
103
104 // Constructor
105 public ATSImageRuntimeConfig()
106 {
107 // Set defaults
108 UsbDrive = ATSUsbDrive.One;
109 }
110
111 public void ReadDefaultFromDatabase()
112 {
113 atsDataSetTableAdapters.ClientTableAdapter clientTableAdapter;
114 atsDataSet datasetClient;
115 DataRow row;
116 clientTableAdapter = new atsDataSetTableAdapters.ClientTableAdapter();
117 datasetClient = new atsDataSet();
118
119 clientTableAdapter.Fill(datasetClient.Client);
120
121 // Loook up the row
122 row = datasetClient.Client.Rows.Find(ProSupport.DEFAULT_RECORD_MAC);
123 if (row != null)
124 {
125 // Read from database
126 ReadFromDatabase(row);
127 }
128 else
129 { // Row could not be found
130 // Create a default row
131 DataRow newRow = datasetClient.Client.NewRow();
132
133 ATSImageRuntimeConfig defaultConfig = new ATSImageRuntimeConfig();
134 defaultConfig.WriteDefaultsToDatabase();
135
136 clientTableAdapter.Fill(datasetClient.Client); // Refresh with the new default record.
137
138 // Look up the row
139 row = datasetClient.Client.Rows.Find(ProSupport.DEFAULT_RECORD_MAC);
140 if (row != null)
141 {
142 // Read from database
143 ReadFromDatabase(row);
144 }
145 else
146 {
147 string error = "Error: Default record not written (27773)";
148 using (log4net.NDC.Push(string.Format("recordname={0}", ProSupport.DEFAULT_RECORD_MAC)))
149 {
150 Logging.ATSAdminLog.Error(error);
151 }
152 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("recordname={0}", ProSupport.DEFAULT_RECORD_MAC)));
153 return;
154 }
155 }
156 }
157
158 public void ReadFromDatabase(DataRow row)
159 {
160 ExtractResolution(row["ScreenResolution"].ToString(), out ScreenResolutionX, out ScreenResolutionY);
161
162 switch (row["ScreenColorDepth"].ToString())
163 {
164 case "16":
165 ScreenColorDepth = ATSScreenColorDepth.ATS16Bit;
166 break;
167 case "24":
168 ScreenColorDepth = ATSScreenColorDepth.ATS24Bit;
169 break;
170 default:
171 string error = "Error: Invalid color depth";
172 using (log4net.NDC.Push(string.Format("ScreenColorDepth={0}", row["ScreenColorDepth"].ToString())))
173 {
174 Logging.ATSAdminLog.Error(error);
175 }
176 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("ScreenColorDepth={0}", row["ScreenColorDepth"].ToString())));
177 return;
178 }
179
180 ServerName = row["ServerName"].ToString();
181 ServerDomain = row["ServerDomain"].ToString();
182
183 if (row["ServerVersion"].ToString() == "Win2000")
184 ServerVersion = ATSServerVersion.ATSWin2000;
185 else
186 ServerVersion = ATSServerVersion.ATSWin2003; // Meta option, used to control other options. Only used if the server is another computer than the one running AnywhereTS
187
188 if (row["SessionType"].ToString() == "rdesktop")
189 SessionType = ATSSessionType.ATSRDP;
190 else if (row["SessionType"].ToString() == "ICA")
191 SessionType = ATSSessionType.ATSICA;
192 else if (row["SessionType"].ToString() == "PNA")
193 SessionType = ATSSessionType.ATSPNA;
194 else
195 {
196 string error = "Error: Data conversion error (44539)";
197 using (log4net.NDC.Push(string.Format("RawSessionType={0}", row["SessionType"].ToString())))
198 {
199 Logging.ATSAdminLog.Error(error);
200 }
201 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("RawSessionType={0}", row["SessionType"].ToString())));
202 return;
203 }
204
205 ReconnectPrompt = (bool)row["ReconnectPrompt"];
206 RedirectFloppy = (bool)row["RedirectFloppy"];
207 RedirectCD = (bool)row["RedirectCD"];
208 RedirectSound = (bool)row["RedirectSound"];
209
210 AudioLevel = (int)row["AudioLevel"];
211 MouseResolution = (int)row["MouseResolution"];
212 UserName = row["Username"].ToString();
213 Password = row["Password"].ToString();
214
215 DailyReboot = (bool)row["DailyReboot"];
216 KeyboardMap = row["KeyboardMap"].ToString();
217 TimeZone = row["TimeZone"].ToString();
218 DigitalMonitor = (bool)row["DigitalMonitor"]; // Will force 60 Hz for digital monitors
219
220 if (row["IcaProtocol"].ToString() == "UDP")
221 ICAProtocol = ATSIcaProtocol.ATSUDP;
222 else if (row["IcaProtocol"].ToString() == "HTTPonTCP")
223 ICAProtocol = ATSIcaProtocol.ATSHTTPOnTCP;
224 else
225 {
226 string error = "Error: Unknown ICA protocol. Error (19732)";
227 using (log4net.NDC.Push(string.Format("RawIcaProtocol={0}", row["IcaProtocol"].ToString())))
228 {
229 Logging.ATSAdminLog.Error(error);
230 }
231 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("RawIcaProtocol={0}", row["IcaProtocol"].ToString())));
232 return;
233 }
234 ICAEncryption = row["IcaEncryption"].ToString();
235
236 ICACompression = (bool)row["IcaCompression"];
237
238 if (row["IcaAudioQuality"].ToString() == "Low")
239 IcaAudioQuality = ATSIcaAudioQuality.Low;
240 else if (row["IcaAudioQuality"].ToString() == "Medium")
241 IcaAudioQuality = ATSIcaAudioQuality.Medium;
242 else if (row["IcaAudioQuality"].ToString() == "High")
243 IcaAudioQuality = ATSIcaAudioQuality.High;
244 else
245 {
246 string error = "Error: Unknown ICA audio quality. Error (34732)";
247 using (log4net.NDC.Push(string.Format("RawIcaAudioQuality={0}", row["IcaAudioQuality"].ToString())))
248 {
249 Logging.ATSAdminLog.Error(error);
250 }
251 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("RawIcaAudioQuality={0}", row["IcaAudioQuality"].ToString())));
252 return;
253 }
254
255 ICAServer = row["IcaServer"].ToString();
256 ICAApplicationSet = row["IcaApplicationSet"].ToString();
257 if (row["TempString"].ToString().Length == 0) // Not yet implemented into new version of database
258 {
259 ICAServerURL = @"http://"; // Not yet implemented into new version of database
260 }
261 else
262 {
263 ICAServerURL = row["TempString"].ToString(); // Not yet implemented into new version of database
264 }
265
266
267 MiscFlippedFix = (bool)row["MiscFlippedFix"];
268 MiscMousefix = (bool)row["MiscMousefix"];
269 MiscNoAcceleration = (bool)row["MiscNoAcceleration"];
270 MiscRedirectCom1 = (bool)row["RedirectCom1"];
271 MiscRedirectCom2 = (bool)row["RedirectCom2"];
272
273 if (row["UsbDrive"] != DBNull.Value)
274 {
275 switch ((int) row["UsbDrive"])
276 {
277 case 0:
278 UsbDrive = ATSUsbDrive.None;
279 break;
280 case 1:
281 UsbDrive = ATSUsbDrive.One;
282 break;
283 case 2:
284 UsbDrive = ATSUsbDrive.Many;
285 break;
286 default:
287 string error = "Error: Invalid USB Drive config";
288 using (log4net.NDC.Push(string.Format("UsbDrive={0}", row["UsbDrive"].ToString())))
289 {
290 Logging.ATSAdminLog.Error(error);
291 }
292 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("UsbDrive={0}", row["UsbDrive"].ToString())));
293 return;
294 }
295 }
296 else
297 {
298 UsbDrive = ATSUsbDrive.None;
299 }
300
301 if (row["UsbDriveName"] != DBNull.Value)
302 UsbDriveName = row["UsbDriveName"].ToString();
303 else
304 UsbDriveName = "USB";
305
306 NumLock = (bool)row["NumLock"];
307 if (row["ServerPort"] != DBNull.Value)
308 ServerPort = (int) row["ServerPort"];
309 else
310 ServerPort = -1;
311 MouseResolution = (int)row["MouseResolution"];
312
313 }
314
315
316 public void WriteDefaultsToDatabase()
317 {
318 atsDataSetTableAdapters.ClientTableAdapter clientTableAdapter;
319 atsDataSet datasetClient;
320 DataRow defaultRow;
321
322 clientTableAdapter = new atsDataSetTableAdapters.ClientTableAdapter();
323 datasetClient = new atsDataSet();
324
325 clientTableAdapter.Fill(datasetClient.Client);
326
327 // Loook up the default row
328 defaultRow = datasetClient.Client.Rows.Find(ProSupport.DEFAULT_RECORD_MAC);
329 if (defaultRow != null)
330 {
331 WriteToDatabase(defaultRow);
332 }
333 else
334 {
335 // There is no default record, create one
336 DataRow newRow = datasetClient.Client.NewRow();
337 WriteToDatabase(newRow);
338 newRow["macAddress"] = ProSupport.DEFAULT_RECORD_MAC;
339 datasetClient.Client.Rows.Add(newRow);
340 }
341
342 // Save default row
343 clientTableAdapter.Update(datasetClient.Client);
344 }
345
346
347 public void WriteToDatabase(DataRow row)
348 {
349 row["ScreenResolution"] = ScreenResolutionX.ToString() + "x" + ScreenResolutionY.ToString();
350
351 switch (ScreenColorDepth)
352 {
353 case ATSImageRuntimeConfig.ATSScreenColorDepth.ATS16Bit:
354 row["ScreenColorDepth"] = "16";
355 break;
356 case ATSImageRuntimeConfig.ATSScreenColorDepth.ATS24Bit:
357 row["ScreenColorDepth"] = "24";
358 break;
359 default:
360 string error = "Error: Data conversion error (76532)";
361 using (log4net.NDC.Push(string.Format("ScreenColorDepth={0}", ScreenColorDepth)))
362 {
363 Logging.ATSAdminLog.Error(error);
364 }
365 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("ScreenColorDepth={0}", ScreenColorDepth)));
366 return;
367 }
368 row["ServerName"] = ServerName;
369 row["ServerDomain"] = ServerDomain;
370
371 if (ServerVersion == ATSServerVersion.ATSWin2000)
372 row["ServerVersion"] = "Win2000";
373 else
374 row["ServerVersion"] = "Win2003";
375
376 switch (SessionType)
377 {
378 case ATSImageRuntimeConfig.ATSSessionType.ATSRDP:
379 row["SessionType"] = "rdesktop";
380 break;
381 case ATSImageRuntimeConfig.ATSSessionType.ATSICA:
382 row["SessionType"] = "ICA";
383 break;
384 case ATSImageRuntimeConfig.ATSSessionType.ATSPNA:
385 row["SessionType"] = "PNA";
386 break;
387 default:
388 string error = "Error: Data conversion error (44532)";
389 using (log4net.NDC.Push(string.Format("SessionType={0}", SessionType)))
390 {
391 Logging.ATSAdminLog.Error(error);
392 }
393 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("SessionType={0}", SessionType)));
394 return;
395 }
396 row["ReconnectPrompt"] = ReconnectPrompt;
397 row["RedirectFloppy"] = RedirectFloppy;
398 row["RedirectCD"] = RedirectCD;
399 row["RedirectSound"] = RedirectSound;
400
401 row["AudioLevel"] = AudioLevel;
402 row["MouseResolution"]= MouseResolution;
403 row["Username"] = UserName;
404 row["Password"] = Password;
405
406 row["DailyReboot"] = DailyReboot;
407 row["KeyboardMap"] = KeyboardMap;
408 row["TimeZone"] = TimeZone;
409
410 row["DigitalMonitor"] = DigitalMonitor;
411
412 if (ICAProtocol == ATSIcaProtocol.ATSUDP)
413 row["IcaProtocol"]= "UDP";
414 else if (ICAProtocol == ATSIcaProtocol.ATSHTTPOnTCP)
415 row["IcaProtocol"] = "HTTPonTCP";
416 else
417 {
418 string error = "Error: Unknown ICA protocol. Error (19732)";
419 using (log4net.NDC.Push(string.Format("IcaProtocol={0}", ICAProtocol)))
420 {
421 Logging.ATSAdminLog.Error(error);
422 }
423 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("IcaProtocol={0}", ICAProtocol)));
424 return;
425 }
426
427 row["IcaEncryption"] = ICAEncryption;
428 row["IcaCompression"] = ICACompression;
429
430 if (IcaAudioQuality == ATSIcaAudioQuality.Low)
431 row["IcaAudioQuality"] = "Low";
432 else if (IcaAudioQuality == ATSIcaAudioQuality.Medium)
433 row["IcaAudioQuality"]= "Medium";
434 else if (IcaAudioQuality == ATSIcaAudioQuality.High)
435 row["IcaAudioQuality"] = "High";
436 else
437 {
438 string error = "Error: Unknown ICA audio quality. Error (39702)";
439 using (log4net.NDC.Push(string.Format("IcaAudioQuality={0}", IcaAudioQuality)))
440 {
441 Logging.ATSAdminLog.Error(error);
442 }
443 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("IcaAudioQuality={0}", IcaAudioQuality)));
444 return;
445 }
446
447 row["IcaServer"] = ICAServer;
448 row["IcaApplicationSet"] = ICAApplicationSet;
449 row["TempString"] = ICAServerURL; // Test!
450
451
452 row["MiscFlippedFix"] = MiscFlippedFix;
453 row["MiscMousefix"] = MiscMousefix;
454 row["MiscNoAcceleration"] = MiscNoAcceleration;
455 row["RedirectCom1"] = MiscRedirectCom1;
456 row["RedirectCom2"] = MiscRedirectCom2;
457
458 switch (UsbDrive)
459 {
460 case ATSUsbDrive.None:
461 row["UsbDrive"] = 0;
462 break;
463 case ATSUsbDrive.One:
464 row["UsbDrive"] = 1;
465 break;
466 case ATSUsbDrive.Many:
467 row["UsbDrive"] = 2;
468 break;
469 default:
470 string error = "Error: Data conversion error (32244)";
471 using (log4net.NDC.Push(string.Format("UsbDrive={0}", UsbDrive)))
472 {
473 Logging.ATSAdminLog.Error(error);
474 }
475 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("UsbDrive={0}", UsbDrive)));
476 return;
477 }
478 row["UsbDrivename"] = UsbDriveName;
479
480 row["NumLock"] = NumLock;
481 row["ServerPort"] = ServerPort;
482 if (row["Created"] == DBNull.Value)
483 { // This is a new client, save creation date
484 row["Created"] = DateTime.Now;
485 }
486 row["Modified"] = DateTime.Now;
487 }
488
489
490
491 // Write parameters to file. Used only by write config file in this class and in the class ATSImage
492 public void WriteParameters(StreamWriter writer)
493 {
494 writer.WriteLine("KEYBOARD_MAP=" + KeyboardMap);
495
496 if (NumLock)
497 writer.WriteLine("X_NUMLOCK=On");
498 else
499 writer.WriteLine("X_NUMLOCK=Off");
500
501 writer.WriteLine("SCREEN_RESOLUTION=\"{0}x{1}\"", ScreenResolutionX, ScreenResolutionY);
502 writer.WriteLine("SCREEN_COLOR_DEPTH=\"{0}\"", (int)ScreenColorDepth);
503
504 if (UsbDrive == ATSUsbDrive.One)
505 writer.WriteLine(@"USB_STORAGE_MULTI=OFF");
506 if (UsbDrive == ATSUsbDrive.Many)
507 writer.WriteLine(@"USB_STORAGE_MULTI=On");
508 if (MouseResolution < 51)
509 { // Create a fraction 1/11 to 1 from MouseResolution values 0-49
510 // MouseResolution 1 -> MOUSE_ACCELERATION = 1/11
511 // MouseResolution 49 -> MOUSE_ACCELERATION = 1
512 writer.WriteLine(@"MOUSE_ACCELERATION=""" + ((MouseResolution / 5) + 1).ToString() + @"/11""");
513 }
514 else
515 { // Create a fraction 10/10 to 100/10 from MouseResolution values 50-100
516 // MouseResolution 50 -> MOUSE_ACCELERATION = 1
517 // MouseResolution 100 -> MOUSE_ACCELERATION = 10
518 writer.WriteLine(@"MOUSE_ACCELERATION=""" + ((MouseResolution*9/5)-80).ToString() + @"/10""");
519 }
520
521 writer.WriteLine(@"NET_BASE_NAME=""anywhereTS""");
522 writer.WriteLine(@"TIME_ZONE=""" + TimeZone + @"""");
523 writer.WriteLine("AUDIO_LEVEL=" + AudioLevel.ToString());
524 //writer.WriteLine(@"USB_STORAGE_BASENAME=""USBFOO""");
525 //writer.WriteLine("USB_STORAGE_SYNC=ON");
526 //writer.WriteLine("USB_STORAGE_MULTI=OFF");
527
528 if (DailyReboot)
529 writer.WriteLine("DAILY_REBOOT=On");
530 else
531 writer.WriteLine("DAILY_REBOOT=Off");
532
533 writer.Write("RECONNECT_PROMPT=");
534 if (ReconnectPrompt)
535 writer.WriteLine("On");
536 else
537 writer.WriteLine("Off");
538
539
540 writer.WriteLine(@"SCREEN=0"); //Could be removed and put in default file
541 writer.WriteLine(@"WORKSPACE=1"); //Could be removed and put in default file
542 writer.WriteLine(@"#SCREEN_HORIZSYNC=""30-64 | *"""); //Could be removed
543 writer.WriteLine(@"#SCREEN_VERTREFRESH=""56-87 | 60 | 56 | 70 | 72 | 75"""); //Could be removed and put in default file
544
545 writer.WriteLine("SESSION_0_SCREEN=0"); //Could be removed and put in default file
546
547 writer.Write("SESSION_0_TYPE=");
548 if (SessionType == ATSSessionType.ATSRDP)
549 writer.WriteLine("rdesktop");
550 else if (SessionType == ATSSessionType.ATSICA)
551 {
552 writer.WriteLine("ICA"); //Ica 9
553 }
554 else if (SessionType == ATSSessionType.ATSPNA)
555 {
556 writer.WriteLine("pnabrowse");
557 }
558 else
559 {
560 string error = "Error: Unknown SessionType (61132)";
561 using (log4net.NDC.Push(string.Format("SessionType={0}", SessionType)))
562 {
563 Logging.ATSAdminLog.Error(error);
564 }
565 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("SessionType={0}", SessionType)));
566 return;
567 }
568
569 // Server
570 writer.WriteLine("SESSION_0_RDESKTOP_SERVER={0}", ServerPort == -1 ? ServerName : ServerName + ":" + ServerPort.ToString());
571
572 // RDP OPTIONS:
573 writer.Write("SESSION_0_RDESKTOP_OPTIONS=\"");
574
575 // RDP User name
576 writer.Write(" -u '{0}'", UserName);
577
578 // RDP domain
579 writer.Write(" -d '{0}'", ServerDomain);
580
581 // RDP password
582 writer.Write(" -p '{0}'", Password);
583
584 // RDP keyboard (no need to define this, uses a format different from keyboard map, so needs conversion)
585 // writer.Write(" -k "+ KeyboardMap);
586
587 // RDP Resolution
588 writer.Write(" -g {0}x{1}", ScreenResolutionX, ScreenResolutionY);
589
590 // RDP color depth
591 if (ServerVersion == ATSServerVersion.ATSWin2000)
592 writer.Write(" -a 8");
593 else
594 {
595 if (ScreenColorDepth == ATSScreenColorDepth.ATS16Bit)
596 writer.Write(" -a 16"); //Test 32bit
597 else if (ScreenColorDepth == ATSScreenColorDepth.ATS24Bit)
598 writer.Write(" -a 24");
599 else
600 {
601 string error = "Error: Unknown ScreenColorDepth depth (63342)";
602 using (log4net.NDC.Push(string.Format("ScreenColorDepth={0}", ScreenColorDepth)))
603 {
604 Logging.ATSAdminLog.Error(error);
605 }
606 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("ScreenColorDepth={0}", ScreenColorDepth)));
607 return;
608 }
609 }
610
611 // RDP sound
612 if (RedirectSound)
613 writer.Write(" -r sound");
614
615 // RDP Floppy if is 2003 server or later and redirect floppy
616 if (RedirectFloppy && !ServerIsWin2000())
617 writer.Write(" -r disk:floppy=/mnt/floppy");
618
619 // RDP CD if is 2003 server or later and redirect CD
620 if (RedirectCD && !ServerIsWin2000())
621 writer.Write(" -r disk:cdrom=/mnt/cdrom");
622 // RDP USB if is 2003 server or later and redirect USB Memmory
623 if (UsbDrive!=ATSUsbDrive.None)
624 writer.Write(" -r disk:" + UsbDriveName + "=/mnt/usbdevice");
625
626 // RDP COM if is 2003 server or later and redirect Comport
627 if ((MiscRedirectCom1 || MiscRedirectCom2) && !ServerIsWin2000())
628 // RDP com1 if is 2003 server or later and redirect com1
629 if (MiscRedirectCom1 && MiscRedirectCom2)
630 writer.Write(" -r comport:COM1=/dev/ttyS0,COM2=/dev/ttyS1");
631 else
632 if (MiscRedirectCom1)
633 writer.Write(" -r comport:COM1=/dev/ttyS0");
634 else
635 writer.Write(" -r comport:COM2=/dev/ttyS1");
636
637 writer.Write(" -B -C -z -x l"); // Misc swithces
638
639
640
641 writer.WriteLine(@" -N"""); //Finalise the RDESKTOP_OPTIONS line
642
643 if (ServerIsWin2000() && (RedirectCD || RedirectFloppy ))
644 { // We have a win 2000 server with redirected local drives, we need to enable samba
645 writer.WriteLine("SAMBA_ENABLED=On");
646 writer.WriteLine("SAMBA_WORKGROUP=thinclient");
647 writer.WriteLine("SAMBA_SECURITY=USER");
648 writer.WriteLine("SAMBA_SERVER=ts*");
649 writer.WriteLine("SAMBA_HARDDISK=Off");
650 writer.WriteLine("SAMBA_USB=Off");
651 writer.WriteLine("SAMBA_PRINTER=Off");
652
653 if(RedirectFloppy)
654 writer.WriteLine("SAMBA_FLOPPY=On");
655 else
656 writer.WriteLine("SAMBA_FLOPPY=Off");
657
658 if(RedirectCD)
659 writer.WriteLine("SAMBA_CDROM=On");
660 else
661 writer.WriteLine("SAMBA_CDROM=Off");
662 }
663
664 if (SessionType == ATSSessionType.ATSICA)
665 {
666 writer.WriteLine(@"SESSION_0_ICA_APPLICATION_SET=""" + ICAApplicationSet + @"""");
667 }
668 else if (SessionType == ATSSessionType.ATSPNA)
669 {
670 writer.WriteLine(@"PNABROWSE_URL=""" + ICAServerURL + @"""");
671 writer.WriteLine(@"PNABROWSE_RESOURCE=""" + ICAResource + @"""");
672 writer.WriteLine(@"PNABROWSE_LOGIN=""" + UserName + @"""");
673 writer.WriteLine(@"PNABROWSE_PASSWORD=""" + Password + @"""");
674 writer.WriteLine(@"PNABROWSE_DOMAIN=""" + ServerDomain + @"""");
675 }
676
677 if (SessionType == ATSSessionType.ATSICA || SessionType == ATSSessionType.ATSPNA)
678 {
679 writer.WriteLine("SESSION_0_ICA_APPSRV_USEFULLSCREEN=Yes"); //tabort
680 writer.WriteLine("SESSION_0_SCREEN=0"); //tabort
681 writer.WriteLine("SESSION_0_TITLE=ATS*"); //tabort
682 writer.WriteLine("SESSION_0_AUTOSTART=ON"); //tabort
683 writer.WriteLine("SESSION_0_CUSTOM_CONFIG=OFF"); //tabort
684 writer.WriteLine("ICA_USE_SERVER_KEYBOARD=ON"); //tabort
685 // ICA Desktop Citrix 10
686
687 if (ICAProtocol == ATSIcaProtocol.ATSUDP)
688 writer.WriteLine("ICA_BROWSER_PROTOCOL=UDP");
689 else if (ICAProtocol == ATSIcaProtocol.ATSHTTPOnTCP)
690 writer.WriteLine("ICA_BROWSER_PROTOCOL=HTTPonTCP");
691 else
692 {
693 string error = "Error: Unknown ICA protocol Error: (34211)";
694 using (log4net.NDC.Push(string.Format("ICAProtocol={0}", ICAProtocol)))
695 {
696 Logging.ATSAdminLog.Error(error);
697 }
698 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("ICAProtocol={0}", ICAProtocol)));
699 return;
700 }
701
702 writer.WriteLine("SESSION_0_ICA_SERVER=" + ServerName);
703 writer.WriteLine(@"ICA_ENCRYPTION=""" + ICAEncryption + @"""");
704
705 if (ICACompression)
706 writer.WriteLine("ICA_COMPRESS=On");
707 else
708 writer.WriteLine("ICA_COMPRESS=Off");
709
710 if (RedirectSound)
711 writer.WriteLine("ICA_AUDIO=On");
712 else
713 writer.WriteLine("ICA_AUDIO=Off");
714
715 if (IcaAudioQuality == ATSIcaAudioQuality.Low)
716 writer.WriteLine("ICA_AUDIO_QUALITY=Low");
717 else if (IcaAudioQuality == ATSIcaAudioQuality.Medium)
718 writer.WriteLine("ICA_AUDIO_QUALITY=Medium");
719 else if (IcaAudioQuality == ATSIcaAudioQuality.High)
720 writer.WriteLine("ICA_AUDIO_QUALITY=High");
721 else
722 {
723 string error = "Error: ICA audio quality. Error (23165)";
724 using (log4net.NDC.Push(string.Format("IcaAudioQuality={0}", IcaAudioQuality)))
725 {
726 Logging.ATSAdminLog.Error(error);
727 }
728 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("IcaAudioQuality={0}", IcaAudioQuality)));
729 return;
730 }
731
732 writer.WriteLine("ICA_PRINTER=OFF"); //tabort
733 writer.WriteLine("ICA_SEAMLESS_WINDOW=OFF"); //tabort
734
735 // ICA OPTIONS:
736 writer.Write(@"SESSION_0_ICA_OPTIONS=""");
737
738 // ICA User name
739 if (UserName.Length > 0)
740 writer.Write("-username " + UserName);
741
742 // ICA password
743 if (Password.Length > 0)
744 writer.Write(" -clearpassword " + Password);
745 // ICA domain
746 if (ServerDomain.Length != 0)
747 writer.Write(" -domain " + ServerDomain);
748
749 writer.WriteLine(@""""); // Finalise the ICA_OPTIONS line
750 } // end ICA parameters
751
752 if (GraphicsAdapter.Length != 0)
753 writer.WriteLine(@"X_DRIVER_NAME=""" + GraphicsAdapter + @"""");
754
755 if (MiscFlippedFix )
756 writer.WriteLine(@"X_DRIVER_OPTION1=""XaaNoMono8x8PatternFillRect On""");
757
758 if (MiscMousefix)
759 writer.WriteLine(@"X_DRIVER_OPTION2=""SWCursor On""");
760
761 if (MiscNoAcceleration)
762 writer.WriteLine(@"X_DRIVER_OPTION3=""NoAccel On""");
763 }
764
765 // Write a config file to disk based upon the data in this class.
766 // The config is written to the file pathfile.
767 public bool WriteConfigFile(string pathfile)
768 {
769 bool result = false; // Assume we have a problem.
770 // Delete old backup, so that a new file will always be created and the current user owner. This enables the user to set rights on the file.
771 try
772 {
773
774 if (System.IO.File.Exists(pathfile))
775 {
776 System.IO.File.Delete(pathfile);
777 }
778 }
779 catch (Exception e)
780 {
781 MessageBox.Show("Error cannot delete old config file (24573). Path: '" + pathfile + "'. Error: " + e.Message);
782 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
783 {
784 using (log4net.NDC.Push(string.Format("file={0}", pathfile)))
785 {
786 Logging.ATSAdminLog.Error("Cannot delete old config file");
787 }
788 }
789 return result;
790 }
791
792 System.IO.StreamWriter writer = null;
793
794 // Write a runtime new client config file.
795 try
796 {
797 writer = new StreamWriter(pathfile);
798 writer.NewLine = "\n"; // Unix style line terminators
799 writer.WriteLine("# This is a client file generated by AnywhereTS. Do not change.");
800 writer.WriteLine("# This file will be overwritten.");
801 WriteParameters(writer);
802 result = true; // It went ok.
803 }
804 catch (System.IO.IOException e)
805 {
806 // (Could be improved with auto-retry)
807 MessageBox.Show("Error: Could not write configuration data to disk. Possibly the data is being accessed by another component right now or you do not have the sufficient rights. Please retry this operation a little later. Error details: "+ e.Message);
808 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
809 {
810 using (log4net.NDC.Push(string.Format("file={0}", pathfile)))
811 {
812 Logging.ATSAdminLog.Error("Could not write configuration data to disk");
813 }
814 }
815 }
816 finally
817 {
818 if (writer != null)
819 writer.Close();
820 }
821
822 return result;
823 }
824
825 // True if the client is connecting to a Windows 2000 server
826 public bool ServerIsWin2000()
827 {
828 return (ServerName == Environment.MachineName && Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 0) || (Environment.MachineName != ServerName && ServerVersion == ATSServerVersion.ATSWin2000);
829 }
830
831 // Reset all properties that to the state they should have in a non-licensed version of ATS.
832 // This is useful when switching from the Pro version to a free version image, to make
833 // sure no pro features remain enabled.
834 public void ResetProProperties()
835 {
836 NumLock = true;
837 MiscRedirectCom1 = false;
838 MiscRedirectCom2 = false;
839 UsbDrive = ATSUsbDrive.None; // One is default if Pro version
840 ServerPort = -1; // -1 = Not defined
841 if
842 (!(
843 (ScreenResolutionX == 640 && ScreenResolutionY == 480) ||
844 (ScreenResolutionX == 800 && ScreenResolutionY == 600) ||
845 (ScreenResolutionX == 1024 && ScreenResolutionY == 768) ||
846 (ScreenResolutionX == 1280 && ScreenResolutionY == 1024)
847 ))
848 {
849 // Screen resolution is not a standard resoltion available in the free version
850 // Reset screen res to a resolution that is available in the free version.
851 ScreenResolutionX = 1024;
852 ScreenResolutionY = 768;
853 }
854 }
855
856 // Extract the x and y screen resolution from a string
857 // twointegers: String with resolution in the format '1024X768'
858 // x: (out) The x resolution from the string
859 // y: (out) The y resolution from the string
860 private void ExtractResolution(string resolution, out int x, out int y)
861 {
862 x = -1;
863 y = -1;
864 int[] parsed = new int[0];
865 ATSGlobals.ExtractIntegers(resolution, 'x', out parsed);
866 x = parsed.First();
867 y = parsed.Last();
868 }
869
870 } // class
871 } // namespace

  ViewVC Help
Powered by ViewVC 1.1.22