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

Contents of /trunk/TSAdminTool/ImageRuntimeConfig.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 375 - (show annotations) (download)
Tue Aug 28 07:12:59 2012 UTC (7 years, 10 months ago) by william
File size: 38057 byte(s)
+ fix RDP ServerDomain (possibly lead to an unquoted string error on client)

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,
19 ATS24Bit
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=""" + ScreenResolutionX.ToString() + @"x" + ScreenResolutionY.ToString() + @"""");
502
503 writer.Write("SCREEN_COLOR_DEPTH=");
504 if (ScreenColorDepth == ATSScreenColorDepth.ATS16Bit)
505 writer.WriteLine("16");
506 else if (ScreenColorDepth == ATSScreenColorDepth.ATS24Bit)
507 writer.WriteLine("24");
508 else
509 {
510 string error = "Error: Unknown color depth (63342)";
511 using (log4net.NDC.Push(string.Format("ScreenColorDepth={0}", ScreenColorDepth)))
512 {
513 Logging.ATSAdminLog.Error(error);
514 }
515 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("ScreenColorDepth={0}", ScreenColorDepth)));
516 return;
517 }
518 if (UsbDrive == ATSUsbDrive.One)
519 writer.WriteLine(@"USB_STORAGE_MULTI=OFF");
520 if (UsbDrive == ATSUsbDrive.Many)
521 writer.WriteLine(@"USB_STORAGE_MULTI=On");
522 if (MouseResolution < 51)
523 { // Create a fraction 1/11 to 1 from MouseResolution values 0-49
524 // MouseResolution 1 -> MOUSE_ACCELERATION = 1/11
525 // MouseResolution 49 -> MOUSE_ACCELERATION = 1
526 writer.WriteLine(@"MOUSE_ACCELERATION=""" + ((MouseResolution / 5) + 1).ToString() + @"/11""");
527 }
528 else
529 { // Create a fraction 10/10 to 100/10 from MouseResolution values 50-100
530 // MouseResolution 50 -> MOUSE_ACCELERATION = 1
531 // MouseResolution 100 -> MOUSE_ACCELERATION = 10
532 writer.WriteLine(@"MOUSE_ACCELERATION=""" + ((MouseResolution*9/5)-80).ToString() + @"/10""");
533 }
534
535 writer.WriteLine(@"NET_BASE_NAME=""anywhereTS""");
536 writer.WriteLine(@"TIME_ZONE=""" + TimeZone + @"""");
537 writer.WriteLine("AUDIO_LEVEL=" + AudioLevel.ToString());
538 //writer.WriteLine(@"USB_STORAGE_BASENAME=""USBFOO""");
539 //writer.WriteLine("USB_STORAGE_SYNC=ON");
540 //writer.WriteLine("USB_STORAGE_MULTI=OFF");
541
542 if (DailyReboot)
543 writer.WriteLine("DAILY_REBOOT=On");
544 else
545 writer.WriteLine("DAILY_REBOOT=Off");
546
547 writer.Write("RECONNECT_PROMPT=");
548 if (ReconnectPrompt)
549 writer.WriteLine("On");
550 else
551 writer.WriteLine("Off");
552
553
554 writer.WriteLine(@"SCREEN=0"); //Could be removed and put in default file
555 writer.WriteLine(@"WORKSPACE=1"); //Could be removed and put in default file
556 writer.WriteLine(@"#SCREEN_HORIZSYNC=""30-64 | *"""); //Could be removed
557
558 if (DigitalMonitor)
559 {
560 writer.WriteLine(@"SCREEN_VERTREFRESH=60");
561 }
562 else
563 writer.WriteLine(@"#SCREEN_VERTREFRESH=""56-87 | 60 | 56 | 70 | 72 | 75"""); //Could be removed and put in default file
564
565 writer.WriteLine("SESSION_0_SCREEN=0"); //Could be removed and put in default file
566
567 writer.Write("SESSION_0_TYPE=");
568 if (SessionType == ATSSessionType.ATSRDP)
569 writer.WriteLine("rdesktop");
570 else if (SessionType == ATSSessionType.ATSICA)
571 {
572 writer.WriteLine("ICA"); //Ica 9
573 }
574 else if (SessionType == ATSSessionType.ATSPNA)
575 {
576 writer.WriteLine("pnabrowse");
577 }
578 else
579 {
580 string error = "Error: Unknown SessionType (61132)";
581 using (log4net.NDC.Push(string.Format("SessionType={0}", SessionType)))
582 {
583 Logging.ATSAdminLog.Error(error);
584 }
585 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("SessionType={0}", SessionType)));
586 return;
587 }
588
589 // Server
590 writer.WriteLine("SESSION_0_RDESKTOP_SERVER={0}", ServerPort == -1 ? ServerName : ServerName + ":" + ServerPort.ToString());
591
592 // RDP OPTIONS:
593 writer.Write("SESSION_0_RDESKTOP_OPTIONS=");
594
595 // RDP User name
596 writer.Write(" -u '{0}'", UserName);
597
598 // RDP domain
599 writer.Write(" -d '{0}'", ServerDomain);
600
601 // RDP password
602 writer.Write(" -p {0}", Password);
603
604 // RDP keyboard (no need to define this, uses a format different from keyboard map, so needs conversion)
605 // writer.Write(" -k "+ KeyboardMap);
606
607 // RDP Resolution
608 writer.Write(" -g {0}x{1}", ScreenResolutionX, ScreenResolutionY);
609
610 // RDP color depth
611 if (ServerVersion == ATSServerVersion.ATSWin2000)
612 writer.Write(" -a 8");
613 else
614 {
615 if (ScreenColorDepth == ATSScreenColorDepth.ATS16Bit)
616 writer.Write(" -a 16"); //Test 32bit
617 else if (ScreenColorDepth == ATSScreenColorDepth.ATS24Bit)
618 writer.Write(" -a 24");
619 else
620 {
621 string error = "Error: Unknown ScreenColorDepth depth (63342)";
622 using (log4net.NDC.Push(string.Format("ScreenColorDepth={0}", ScreenColorDepth)))
623 {
624 Logging.ATSAdminLog.Error(error);
625 }
626 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("ScreenColorDepth={0}", ScreenColorDepth)));
627 return;
628 }
629 }
630
631 // RDP sound
632 if (RedirectSound)
633 writer.Write(" -r sound");
634
635 // RDP Floppy if is 2003 server or later and redirect floppy
636 if (RedirectFloppy && !ServerIsWin2000())
637 writer.Write(" -r disk:floppy=/mnt/floppy");
638
639 // RDP CD if is 2003 server or later and redirect CD
640 if (RedirectCD && !ServerIsWin2000())
641 writer.Write(" -r disk:cdrom=/mnt/cdrom");
642 // RDP USB if is 2003 server or later and redirect USB Memmory
643 if (UsbDrive!=ATSUsbDrive.None)
644 writer.Write(" -r disk:" + UsbDriveName + "=/mnt/usbdevice");
645
646 // RDP COM if is 2003 server or later and redirect Comport
647 if ((MiscRedirectCom1 || MiscRedirectCom2) && !ServerIsWin2000())
648 // RDP com1 if is 2003 server or later and redirect com1
649 if (MiscRedirectCom1 && MiscRedirectCom2)
650 writer.Write(" -r comport:COM1=/dev/ttyS0,COM2=/dev/ttyS1");
651 else
652 if (MiscRedirectCom1)
653 writer.Write(" -r comport:COM1=/dev/ttyS0");
654 else
655 writer.Write(" -r comport:COM2=/dev/ttyS1");
656
657 writer.Write(" -B -C -z -x l"); // Misc swithces
658
659
660
661 writer.WriteLine(@" -N"""); //Finalise the RDESKTOP_OPTIONS line
662
663 if (ServerIsWin2000() && (RedirectCD || RedirectFloppy ))
664 { // We have a win 2000 server with redirected local drives, we need to enable samba
665 writer.WriteLine("SAMBA_ENABLED=On");
666 writer.WriteLine("SAMBA_WORKGROUP=thinclient");
667 writer.WriteLine("SAMBA_SECURITY=USER");
668 writer.WriteLine("SAMBA_SERVER=ts*");
669 writer.WriteLine("SAMBA_HARDDISK=Off");
670 writer.WriteLine("SAMBA_USB=Off");
671 writer.WriteLine("SAMBA_PRINTER=Off");
672
673 if(RedirectFloppy)
674 writer.WriteLine("SAMBA_FLOPPY=On");
675 else
676 writer.WriteLine("SAMBA_FLOPPY=Off");
677
678 if(RedirectCD)
679 writer.WriteLine("SAMBA_CDROM=On");
680 else
681 writer.WriteLine("SAMBA_CDROM=Off");
682 }
683
684 if (SessionType == ATSSessionType.ATSICA)
685 {
686 writer.WriteLine(@"SESSION_0_ICA_APPLICATION_SET=""" + ICAApplicationSet + @"""");
687 }
688 else if (SessionType == ATSSessionType.ATSPNA)
689 {
690 writer.WriteLine(@"PNABROWSE_URL=""" + ICAServerURL + @"""");
691 writer.WriteLine(@"PNABROWSE_RESOURCE=""" + ICAResource + @"""");
692 writer.WriteLine(@"PNABROWSE_LOGIN=""" + UserName + @"""");
693 writer.WriteLine(@"PNABROWSE_PASSWORD=""" + Password + @"""");
694 writer.WriteLine(@"PNABROWSE_DOMAIN=""" + ServerDomain + @"""");
695 }
696
697 if (SessionType == ATSSessionType.ATSICA || SessionType == ATSSessionType.ATSPNA)
698 {
699 writer.WriteLine("SESSION_0_ICA_APPSRV_USEFULLSCREEN=Yes"); //tabort
700 writer.WriteLine("SESSION_0_SCREEN=0"); //tabort
701 writer.WriteLine("SESSION_0_TITLE=ATS*"); //tabort
702 writer.WriteLine("SESSION_0_AUTOSTART=ON"); //tabort
703 writer.WriteLine("SESSION_0_CUSTOM_CONFIG=OFF"); //tabort
704 writer.WriteLine("ICA_USE_SERVER_KEYBOARD=ON"); //tabort
705 // ICA Desktop Citrix 10
706
707 if (ICAProtocol == ATSIcaProtocol.ATSUDP)
708 writer.WriteLine("ICA_BROWSER_PROTOCOL=UDP");
709 else if (ICAProtocol == ATSIcaProtocol.ATSHTTPOnTCP)
710 writer.WriteLine("ICA_BROWSER_PROTOCOL=HTTPonTCP");
711 else
712 {
713 string error = "Error: Unknown ICA protocol Error: (34211)";
714 using (log4net.NDC.Push(string.Format("ICAProtocol={0}", ICAProtocol)))
715 {
716 Logging.ATSAdminLog.Error(error);
717 }
718 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("ICAProtocol={0}", ICAProtocol)));
719 return;
720 }
721
722 writer.WriteLine("SESSION_0_ICA_SERVER=" + ServerName);
723 writer.WriteLine(@"ICA_ENCRYPTION=""" + ICAEncryption + @"""");
724
725 if (ICACompression)
726 writer.WriteLine("ICA_COMPRESS=On");
727 else
728 writer.WriteLine("ICA_COMPRESS=Off");
729
730 if (RedirectSound)
731 writer.WriteLine("ICA_AUDIO=On");
732 else
733 writer.WriteLine("ICA_AUDIO=Off");
734
735 if (IcaAudioQuality == ATSIcaAudioQuality.Low)
736 writer.WriteLine("ICA_AUDIO_QUALITY=Low");
737 else if (IcaAudioQuality == ATSIcaAudioQuality.Medium)
738 writer.WriteLine("ICA_AUDIO_QUALITY=Medium");
739 else if (IcaAudioQuality == ATSIcaAudioQuality.High)
740 writer.WriteLine("ICA_AUDIO_QUALITY=High");
741 else
742 {
743 string error = "Error: ICA audio quality. Error (23165)";
744 using (log4net.NDC.Push(string.Format("IcaAudioQuality={0}", IcaAudioQuality)))
745 {
746 Logging.ATSAdminLog.Error(error);
747 }
748 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("IcaAudioQuality={0}", IcaAudioQuality)));
749 return;
750 }
751
752 writer.WriteLine("ICA_PRINTER=OFF"); //tabort
753 writer.WriteLine("ICA_SEAMLESS_WINDOW=OFF"); //tabort
754
755 // ICA OPTIONS:
756 writer.Write(@"SESSION_0_ICA_OPTIONS=""");
757
758 // ICA User name
759 if (UserName.Length > 0)
760 writer.Write("-username " + UserName);
761
762 // ICA password
763 if (Password.Length > 0)
764 writer.Write(" -clearpassword " + Password);
765 // ICA domain
766 if (ServerDomain.Length != 0)
767 writer.Write(" -domain " + ServerDomain);
768
769 writer.WriteLine(@""""); // Finalise the ICA_OPTIONS line
770 } // end ICA parameters
771
772 if (GraphicsAdapter.Length != 0)
773 writer.WriteLine(@"X_DRIVER_NAME=""" + GraphicsAdapter + @"""");
774
775 if (MiscFlippedFix )
776 writer.WriteLine(@"X_DRIVER_OPTION1=""XaaNoMono8x8PatternFillRect On""");
777
778 if (MiscMousefix)
779 writer.WriteLine(@"X_DRIVER_OPTION2=""SWCursor On""");
780
781 if (MiscNoAcceleration)
782 writer.WriteLine(@"X_DRIVER_OPTION3=""NoAccel On""");
783 }
784
785 // Write a config file to disk based upon the data in this class.
786 // The config is written to the file pathfile.
787 public bool WriteConfigFile(string pathfile)
788 {
789 bool result = false; // Assume we have a problem.
790 // 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.
791 try
792 {
793
794 if (System.IO.File.Exists(pathfile))
795 {
796 System.IO.File.Delete(pathfile);
797 }
798 }
799 catch (Exception e)
800 {
801 MessageBox.Show("Error cannot delete old config file (24573). Path: '" + pathfile + "'. Error: " + e.Message);
802 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
803 {
804 using (log4net.NDC.Push(string.Format("file={0}", pathfile)))
805 {
806 Logging.ATSAdminLog.Error("Cannot delete old config file");
807 }
808 }
809 return result;
810 }
811
812 System.IO.StreamWriter writer = null;
813
814 // Write a runtime new client config file.
815 try
816 {
817 writer = new StreamWriter(pathfile);
818 writer.NewLine = "\n"; // Unix style line terminators
819 writer.WriteLine("# This is a client file generated by AnywhereTS. Do not change.");
820 writer.WriteLine("# This file will be overwritten.");
821 WriteParameters(writer);
822 result = true; // It went ok.
823 }
824 catch (System.IO.IOException e)
825 {
826 // (Could be improved with auto-retry)
827 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);
828 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
829 {
830 using (log4net.NDC.Push(string.Format("file={0}", pathfile)))
831 {
832 Logging.ATSAdminLog.Error("Could not write configuration data to disk");
833 }
834 }
835 }
836 finally
837 {
838 if (writer != null)
839 writer.Close();
840 }
841
842 return result;
843 }
844
845 // True if the client is connecting to a Windows 2000 server
846 public bool ServerIsWin2000()
847 {
848 return (ServerName == Environment.MachineName && Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 0) || (Environment.MachineName != ServerName && ServerVersion == ATSServerVersion.ATSWin2000);
849 }
850
851 // Reset all properties that to the state they should have in a non-licensed version of ATS.
852 // This is useful when switching from the Pro version to a free version image, to make
853 // sure no pro features remain enabled.
854 public void ResetProProperties()
855 {
856 NumLock = true;
857 MiscRedirectCom1 = false;
858 MiscRedirectCom2 = false;
859 UsbDrive = ATSUsbDrive.None; // One is default if Pro version
860 ServerPort = -1; // -1 = Not defined
861 if
862 (!(
863 (ScreenResolutionX == 640 && ScreenResolutionY == 480) ||
864 (ScreenResolutionX == 800 && ScreenResolutionY == 600) ||
865 (ScreenResolutionX == 1024 && ScreenResolutionY == 768) ||
866 (ScreenResolutionX == 1280 && ScreenResolutionY == 1024)
867 ))
868 {
869 // Screen resolution is not a standard resoltion available in the free version
870 // Reset screen res to a resolution that is available in the free version.
871 ScreenResolutionX = 1024;
872 ScreenResolutionY = 768;
873 }
874 }
875
876 // Extract the x and y screen resolution from a string
877 // twointegers: String with resolution in the format '1024X768'
878 // x: (out) The x resolution from the string
879 // y: (out) The y resolution from the string
880 private void ExtractResolution(string resolution, out int x, out int y)
881 {
882 x = -1;
883 y = -1;
884 int[] parsed = new int[0];
885 ATSGlobals.ExtractIntegers(resolution, 'x', out parsed);
886 x = parsed.First();
887 y = parsed.Last();
888 }
889
890 } // class
891 } // namespace

  ViewVC Help
Powered by ViewVC 1.1.22