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

Contents of /trunk/TSAdminTool/ImageRuntimeConfig.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 64 - (show annotations) (download)
Thu Jul 12 18:56:31 2012 UTC (8 years, 1 month ago) by william
File size: 38152 byte(s)
+ more exception logging

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

  ViewVC Help
Powered by ViewVC 1.1.22