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

Annotation of /trunk/TSAdminTool/ImageRuntimeConfig.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 93 - (hide annotations) (download)
Sat Jul 14 02:35:50 2012 UTC (9 years ago) by william
File size: 38313 byte(s)
+ update to .net 3.5 (so we have linq and extension support)

1 william 4 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 william 47 using log4net;
9 william 93 using System.Linq;
10 william 4 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 william 64 {
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 william 4 }
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 william 64 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 william 4 }
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 william 64 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 william 4
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 william 64 {
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 william 4 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 william 64 {
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 william 4
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 william 64 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 william 4 }
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 william 64 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 william 4 }
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 william 64 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 william 4 }
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 william 64 {
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 william 4
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 william 64 row["IcaAudioQuality"] = "High";
436 william 4 else
437 william 64 {
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 william 4
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 william 64 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 william 4 }
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 william 64 {
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 william 4 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 william 64 {
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 william 4
589     // Server
590     if (ServerPort == -1)
591     { // No RDP port specified, use default
592     writer.WriteLine("SESSION_0_RDESKTOP_SERVER=" + ServerName);
593     }
594     else
595     { // RDP port specified, add it.
596     writer.WriteLine("SESSION_0_RDESKTOP_SERVER=" + ServerName + ":" + ServerPort.ToString());
597     }
598    
599     // RDP OPTIONS:
600     writer.Write(@"SESSION_0_RDESKTOP_OPTIONS=""-u '");
601    
602     // RDP User name
603     if (UserName.Length > 0)
604     writer.Write(UserName);
605     writer.Write("'");
606    
607     // RDP keyboard (no need to define this, uses a format different from keyboard map, so needs conversion)
608     // writer.Write(" -k "+ KeyboardMap);
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 william 64 {
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 william 4 }
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     // RDP domain
660     if (ServerDomain.Length != 0)
661     writer.Write(" -d " + ServerDomain);
662    
663     // RDP password
664     if (Password.Length > 0)
665     writer.Write(" -p " + Password);
666    
667     writer.WriteLine(@" -N"""); //Finalise the RDESKTOP_OPTIONS line
668    
669     if (ServerIsWin2000() && (RedirectCD || RedirectFloppy ))
670     { // We have a win 2000 server with redirected local drives, we need to enable samba
671     writer.WriteLine("SAMBA_ENABLED=On");
672     writer.WriteLine("SAMBA_WORKGROUP=thinclient");
673     writer.WriteLine("SAMBA_SECURITY=USER");
674     writer.WriteLine("SAMBA_SERVER=ts*");
675     writer.WriteLine("SAMBA_HARDDISK=Off");
676     writer.WriteLine("SAMBA_USB=Off");
677     writer.WriteLine("SAMBA_PRINTER=Off");
678    
679     if(RedirectFloppy)
680     writer.WriteLine("SAMBA_FLOPPY=On");
681     else
682     writer.WriteLine("SAMBA_FLOPPY=Off");
683    
684     if(RedirectCD)
685     writer.WriteLine("SAMBA_CDROM=On");
686     else
687     writer.WriteLine("SAMBA_CDROM=Off");
688     }
689    
690     if (SessionType == ATSSessionType.ATSICA)
691     {
692     writer.WriteLine(@"SESSION_0_ICA_APPLICATION_SET=""" + ICAApplicationSet + @"""");
693     }
694     else if (SessionType == ATSSessionType.ATSPNA)
695     {
696     writer.WriteLine(@"PNABROWSE_URL=""" + ICAServerURL + @"""");
697     writer.WriteLine(@"PNABROWSE_RESOURCE=""" + ICAResource + @"""");
698     writer.WriteLine(@"PNABROWSE_LOGIN=""" + UserName + @"""");
699     writer.WriteLine(@"PNABROWSE_PASSWORD=""" + Password + @"""");
700     writer.WriteLine(@"PNABROWSE_DOMAIN=""" + ServerDomain + @"""");
701     }
702    
703     if (SessionType == ATSSessionType.ATSICA || SessionType == ATSSessionType.ATSPNA)
704     {
705     writer.WriteLine("SESSION_0_ICA_APPSRV_USEFULLSCREEN=Yes"); //tabort
706     writer.WriteLine("SESSION_0_SCREEN=0"); //tabort
707     writer.WriteLine("SESSION_0_TITLE=ATS*"); //tabort
708     writer.WriteLine("SESSION_0_AUTOSTART=ON"); //tabort
709     writer.WriteLine("SESSION_0_CUSTOM_CONFIG=OFF"); //tabort
710     writer.WriteLine("ICA_USE_SERVER_KEYBOARD=ON"); //tabort
711     // ICA Desktop Citrix 10
712    
713     if (ICAProtocol == ATSIcaProtocol.ATSUDP)
714     writer.WriteLine("ICA_BROWSER_PROTOCOL=UDP");
715     else if (ICAProtocol == ATSIcaProtocol.ATSHTTPOnTCP)
716     writer.WriteLine("ICA_BROWSER_PROTOCOL=HTTPonTCP");
717     else
718 william 64 {
719     string error = "Error: Unknown ICA protocol Error: (34211)";
720     using (log4net.NDC.Push(string.Format("ICAProtocol={0}", ICAProtocol)))
721     {
722     Logging.ATSAdminLog.Error(error);
723     }
724     MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("ICAProtocol={0}", ICAProtocol)));
725     return;
726     }
727 william 4
728     writer.WriteLine("SESSION_0_ICA_SERVER=" + ServerName);
729     writer.WriteLine(@"ICA_ENCRYPTION=""" + ICAEncryption + @"""");
730    
731     if (ICACompression)
732     writer.WriteLine("ICA_COMPRESS=On");
733     else
734     writer.WriteLine("ICA_COMPRESS=Off");
735    
736     if (RedirectSound)
737     writer.WriteLine("ICA_AUDIO=On");
738     else
739     writer.WriteLine("ICA_AUDIO=Off");
740    
741     if (IcaAudioQuality == ATSIcaAudioQuality.Low)
742     writer.WriteLine("ICA_AUDIO_QUALITY=Low");
743     else if (IcaAudioQuality == ATSIcaAudioQuality.Medium)
744     writer.WriteLine("ICA_AUDIO_QUALITY=Medium");
745     else if (IcaAudioQuality == ATSIcaAudioQuality.High)
746     writer.WriteLine("ICA_AUDIO_QUALITY=High");
747     else
748 william 64 {
749     string error = "Error: ICA audio quality. Error (23165)";
750     using (log4net.NDC.Push(string.Format("IcaAudioQuality={0}", IcaAudioQuality)))
751     {
752     Logging.ATSAdminLog.Error(error);
753     }
754     MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("IcaAudioQuality={0}", IcaAudioQuality)));
755     return;
756     }
757 william 4
758     writer.WriteLine("ICA_PRINTER=OFF"); //tabort
759     writer.WriteLine("ICA_SEAMLESS_WINDOW=OFF"); //tabort
760    
761     // ICA OPTIONS:
762     writer.Write(@"SESSION_0_ICA_OPTIONS=""");
763    
764     // ICA User name
765     if (UserName.Length > 0)
766     writer.Write("-username " + UserName);
767    
768     // ICA password
769     if (Password.Length > 0)
770     writer.Write(" -clearpassword " + Password);
771     // ICA domain
772     if (ServerDomain.Length != 0)
773     writer.Write(" -domain " + ServerDomain);
774    
775     writer.WriteLine(@""""); // Finalise the ICA_OPTIONS line
776     } // end ICA parameters
777    
778     if (GraphicsAdapter.Length != 0)
779     writer.WriteLine(@"X_DRIVER_NAME=""" + GraphicsAdapter + @"""");
780    
781     if (MiscFlippedFix )
782     writer.WriteLine(@"X_DRIVER_OPTION1=""XaaNoMono8x8PatternFillRect On""");
783    
784     if (MiscMousefix)
785     writer.WriteLine(@"X_DRIVER_OPTION2=""SWCursor On""");
786    
787     if (MiscNoAcceleration)
788     writer.WriteLine(@"X_DRIVER_OPTION3=""NoAccel On""");
789     }
790    
791     // Write a config file to disk based upon the data in this class.
792     // The config is written to the file pathfile.
793     public bool WriteConfigFile(string pathfile)
794     {
795     bool result = false; // Assume we have a problem.
796     // 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.
797     try
798     {
799    
800     if (System.IO.File.Exists(pathfile))
801     {
802     System.IO.File.Delete(pathfile);
803     }
804     }
805     catch (Exception e)
806     {
807     MessageBox.Show("Error cannot delete old config file (24573). Path: '" + pathfile + "'. Error: " + e.Message);
808 william 46 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("Cannot delete old config file");
813     }
814     }
815 william 4 return result;
816     }
817    
818     System.IO.StreamWriter writer = null;
819    
820     // Write a runtime new client config file.
821     try
822     {
823     writer = new StreamWriter(pathfile);
824     writer.NewLine = "\n"; // Unix style line terminators
825     writer.WriteLine("# This is a client file generated by AnywhereTS. Do not change.");
826     writer.WriteLine("# This file will be overwritten.");
827     WriteParameters(writer);
828     result = true; // It went ok.
829     }
830     catch (System.IO.IOException e)
831     {
832     // (Could be improved with auto-retry)
833     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);
834 william 46 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", e.Message, System.Environment.NewLine, e.ToString())))
835     {
836     using (log4net.NDC.Push(string.Format("file={0}", pathfile)))
837     {
838     Logging.ATSAdminLog.Error("Could not write configuration data to disk");
839     }
840     }
841 william 4 }
842     finally
843     {
844     if (writer != null)
845     writer.Close();
846     }
847    
848     return result;
849     }
850    
851     // True if the client is connecting to a Windows 2000 server
852     public bool ServerIsWin2000()
853     {
854     return (ServerName == Environment.MachineName && Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 0) || (Environment.MachineName != ServerName && ServerVersion == ATSServerVersion.ATSWin2000);
855     }
856    
857     // Reset all properties that to the state they should have in a non-licensed version of ATS.
858     // This is useful when switching from the Pro version to a free version image, to make
859     // sure no pro features remain enabled.
860     public void ResetProProperties()
861     {
862     NumLock = true;
863     MiscRedirectCom1 = false;
864     MiscRedirectCom2 = false;
865     UsbDrive = ATSUsbDrive.None; // One is default if Pro version
866     ServerPort = -1; // -1 = Not defined
867     if
868     (!(
869     (ScreenResolutionX == 640 && ScreenResolutionY == 480) ||
870     (ScreenResolutionX == 800 && ScreenResolutionY == 600) ||
871     (ScreenResolutionX == 1024 && ScreenResolutionY == 768) ||
872     (ScreenResolutionX == 1280 && ScreenResolutionY == 1024)
873     ))
874     {
875     // Screen resolution is not a standard resoltion available in the free version
876     // Reset screen res to a resolution that is available in the free version.
877     ScreenResolutionX = 1024;
878     ScreenResolutionY = 768;
879     }
880     }
881    
882     // Extract the x and y screen resolution from a string
883     // twointegers: String with resolution in the format '1024X768'
884     // x: (out) The x resolution from the string
885     // y: (out) The y resolution from the string
886 william 93 private void ExtractResolution(string resolution, out int x, out int y)
887 william 4 {
888 william 93 x = -1;
889     y = -1;
890     int[] parsed = new int[0];
891     ATSGlobals.ExtractIntegers(resolution, 'x', out parsed);
892     x = parsed.First();
893     y = parsed.Last();
894 william 4 }
895    
896     } // class
897     } // namespace

  ViewVC Help
Powered by ViewVC 1.1.22