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 System.Drawing; |
9 |
using System.Drawing.Imaging; |
10 |
|
11 |
|
12 |
|
13 |
namespace AnywhereTS |
14 |
{ |
15 |
// An image config set for an ATSImage |
16 |
public class ATSImageDesigntimeConfig |
17 |
{ |
18 |
public enum ATSBootMedia |
19 |
{ |
20 |
PXE, |
21 |
CD_ISO, |
22 |
USB, |
23 |
HD_via_CD, |
24 |
HD_via_USB |
25 |
} |
26 |
|
27 |
public enum ATSSoundType |
28 |
{ |
29 |
ATSNoSound, |
30 |
ATSAutodetect, |
31 |
ATSSelectedDriver |
32 |
} |
33 |
const string DEFAULT_RECORD_NAME = "Default"; // The default record in the database. |
34 |
|
35 |
public string DataDirectory; // The directory with the data files |
36 |
|
37 |
public ATSBootMedia BootMedia = ATSBootMedia.PXE; |
38 |
|
39 |
public ATSBootPicture BootPicture; |
40 |
|
41 |
// Image design time options with defined defaults |
42 |
public bool ConfigFile = false; // False = Disable config file |
43 |
public int Debug = 0; // 1= this is an debug client with debug messages. Currently not implemented. |
44 |
public int BootPackage = 1; // This is the boot package used for network boot. 0 = ATS standard etherboot, 1 = PXE Linux |
45 |
public bool UseDHCP = true; |
46 |
public IPAddress ClientIP = null; |
47 |
public IPAddress ClientIPNetmask = null; |
48 |
public IPAddress ClientIPGateway = null; |
49 |
public IPAddress ClientIPDNS1 = null; |
50 |
public IPAddress ClientIPDNS2 = null; |
51 |
public string ClientIPDNSSuffix = ""; |
52 |
public string ClientBootServer = ""; |
53 |
public bool OnlyUseRDP = false; // True = build a (smaller) client with support for RDP only, not Citrix |
54 |
|
55 |
public string NetworkDriver = ""; // "" = Autodetect, otherwise, NIC name. |
56 |
|
57 |
public ATSSoundType SoundType = ATSSoundType.ATSAutodetect; |
58 |
public string SoundDriver = ""; // Sound driver name, if specified above. |
59 |
public string GraphicsDriver = ""; // "" = Autodetect, otherwise, driver name. |
60 |
|
61 |
// Constructor |
62 |
public ATSImageDesigntimeConfig() |
63 |
{ // Create a boot picture object |
64 |
BootPicture = new ATSBootPicture(); |
65 |
} |
66 |
|
67 |
// Read design time options from database. |
68 |
public void ReadDefaultFromDatabase() |
69 |
{ |
70 |
atsDataSetTableAdapters.ImageTableAdapter imageTableAdapter; |
71 |
atsDataSet datasetImage; |
72 |
DataRow row; |
73 |
imageTableAdapter = new atsDataSetTableAdapters.ImageTableAdapter(); |
74 |
datasetImage = new atsDataSet(); |
75 |
|
76 |
imageTableAdapter.Fill(datasetImage.Image); |
77 |
|
78 |
// Loook up the row |
79 |
row = datasetImage.Image.Rows.Find(DEFAULT_RECORD_NAME); |
80 |
if (row != null) |
81 |
{ |
82 |
// Read from database |
83 |
ReadFromDatabase(row); |
84 |
} |
85 |
else |
86 |
{ // Row could not be found |
87 |
// Create a default row |
88 |
DataRow newRow = datasetImage.Image.NewRow(); |
89 |
|
90 |
ATSImageDesigntimeConfig defaultConfig = new ATSImageDesigntimeConfig(); |
91 |
defaultConfig.ConfigFile = true; // This is only run in the pro version |
92 |
defaultConfig.WriteDefaultsToDatabase(); |
93 |
|
94 |
imageTableAdapter.Fill(datasetImage.Image); // Refresh with the new default record. |
95 |
|
96 |
// Loook up the row |
97 |
row = datasetImage.Image.Rows.Find(DEFAULT_RECORD_NAME); |
98 |
if (row != null) |
99 |
{ |
100 |
// Read from database |
101 |
ReadFromDatabase(row); |
102 |
} |
103 |
else |
104 |
throw new Exception("Error: Default record not written (24712)."); |
105 |
} |
106 |
} |
107 |
|
108 |
public void ReadFromDatabase(DataRow row) |
109 |
{ |
110 |
UseDHCP = System.Convert.ToBoolean(row["UseDHCP"]); |
111 |
ClientIP = row["ClientIPAddress"].ToString().Length == 0 ? null : IPAddress.Parse(row["ClientIPAddress"].ToString()); |
112 |
ClientIPNetmask = row["ClientIPNetmask"].ToString().Length == 0 ? null : IPAddress.Parse(row["ClientIPNetmask"].ToString()); |
113 |
ClientIPGateway = row["ClientIPGateway"].ToString().Length == 0 ? null : IPAddress.Parse(row["ClientIPGateway"].ToString()); |
114 |
ClientIPDNS1 = row["ClientIPDNS1"].ToString().Length == 0 ? null : IPAddress.Parse(row["ClientIPDNS1"].ToString()); |
115 |
ClientIPDNS2 = row["ClientIPDNS2"].ToString().Length == 0 ? null : IPAddress.Parse(row["ClientIPDNS2"].ToString()); |
116 |
ClientIPDNSSuffix = row["ClientIPDNSSuffix"].ToString(); |
117 |
ClientBootServer = row["ClientBootServer"].ToString(); |
118 |
ConfigFile = System.Convert.ToBoolean(row["ConfigFile"]); |
119 |
OnlyUseRDP = System.Convert.ToBoolean(row["OnlyUseRDP"]); |
120 |
BootPicture.Type = (int)row["BootPicture"]; |
121 |
NetworkDriver = row["NetworkDriver"].ToString(); |
122 |
SoundType = (ATSSoundType)(int)row["SoundType"]; |
123 |
SoundDriver = row["SoundDriver"].ToString(); |
124 |
GraphicsDriver = row["GraphicsDriver"].ToString(); |
125 |
|
126 |
Debug = (int)row["Debug"]; |
127 |
BootPackage = (int)row["BootPackage"]; |
128 |
BootPicture.Width = (int)row["BootPictureWidth"]; |
129 |
BootPicture.Height = (int)row["BootPictureHeight"]; |
130 |
BootPicture.ProgressBar = (int)row["BootPictureProgressBar"]; |
131 |
if (row["BootPicturePng"] != DBNull.Value) |
132 |
{ |
133 |
byte[] bootPictureArray = (byte[])row["BootPicturePng"]; |
134 |
MemoryStream ms = new MemoryStream(bootPictureArray); |
135 |
BootPicture.CustomPicture = new Bitmap(ms); |
136 |
ms.Close(); |
137 |
} |
138 |
} |
139 |
|
140 |
public void WriteDefaultsToDatabase() |
141 |
{ |
142 |
atsDataSetTableAdapters.ImageTableAdapter imageTableAdapter; |
143 |
atsDataSet datasetImage; |
144 |
DataRow defaultRow; |
145 |
|
146 |
imageTableAdapter = new atsDataSetTableAdapters.ImageTableAdapter(); |
147 |
datasetImage = new atsDataSet(); |
148 |
|
149 |
imageTableAdapter.Fill(datasetImage.Image); |
150 |
|
151 |
// Loook up the default row |
152 |
defaultRow = datasetImage.Image.Rows.Find(DEFAULT_RECORD_NAME); |
153 |
if (defaultRow != null) |
154 |
{ |
155 |
WriteToDatabase(defaultRow); |
156 |
} |
157 |
else |
158 |
{ |
159 |
// There is no default record, create one |
160 |
DataRow newRow = datasetImage.Image.NewRow(); |
161 |
WriteToDatabase(newRow); |
162 |
newRow["Name"] = DEFAULT_RECORD_NAME; |
163 |
datasetImage.Image.Rows.Add(newRow); |
164 |
} |
165 |
|
166 |
// Save default row |
167 |
imageTableAdapter.Update(datasetImage.Image); |
168 |
} |
169 |
|
170 |
|
171 |
public void WriteToDatabase(DataRow row) |
172 |
{ |
173 |
row["UseDHCP"] = UseDHCP; |
174 |
if (ClientIP != null) |
175 |
row["ClientIPAddress"] = ClientIP.ToString(); |
176 |
else |
177 |
row["ClientIPAddress"] = null; |
178 |
|
179 |
if (ClientIPNetmask != null) |
180 |
row["ClientIPNetmask"] = ClientIPNetmask.ToString(); |
181 |
else |
182 |
row["ClientIPNetmask"] = null; |
183 |
|
184 |
if (ClientIPGateway != null) |
185 |
row["ClientIPGateway"] = ClientIPGateway.ToString(); |
186 |
else |
187 |
row["ClientIPGateway"] = null; |
188 |
|
189 |
if (ClientIPDNS1 != null) |
190 |
row["ClientIPDNS1"] = ClientIPDNS1.ToString(); |
191 |
else |
192 |
row["ClientIPDNS1"] = null; |
193 |
|
194 |
if (ClientIPDNS2 != null) |
195 |
row["ClientIPDNS2"] = ClientIPDNS2.ToString(); |
196 |
else |
197 |
row["ClientIPDNS2"] = null; |
198 |
|
199 |
row["ClientIPDNSSuffix"] = ClientIPDNSSuffix; |
200 |
row["ClientBootServer"] = ClientBootServer; |
201 |
row["ConfigFile"] = ConfigFile; |
202 |
row["OnlyUseRDP"] = OnlyUseRDP; |
203 |
row["BootPicture"] = BootPicture.Type; |
204 |
row["NetworkDriver"] = NetworkDriver; |
205 |
row["SoundType"] = (int)SoundType; |
206 |
row["SoundDriver"] = SoundDriver; |
207 |
row["GraphicsDriver"] = GraphicsDriver; |
208 |
|
209 |
|
210 |
row["Debug"] = Debug; |
211 |
row["BootPackage"] = BootPackage; |
212 |
row["BootPictureWidth"] = BootPicture.Width; |
213 |
row["BootPictureHeight"] = BootPicture.Height; |
214 |
row["BootPictureProgressBar"] = BootPicture.ProgressBar; |
215 |
|
216 |
MemoryStream ms = new MemoryStream(); |
217 |
BootPicture.CustomPicture.Save (ms, ImageFormat.Png); |
218 |
byte[] bootPictureArray = ms.GetBuffer(); |
219 |
row["BootPicturePng"] = bootPictureArray; |
220 |
ms.Close(); |
221 |
} |
222 |
|
223 |
// Write parameters to file. Used only by write config file in this class and in the class ATSImage |
224 |
public void WriteParameters(StreamWriter writer) |
225 |
{ |
226 |
writer.WriteLine("AUTOSTART=On"); |
227 |
writer.WriteLine("USB_ENABLED=On"); |
228 |
writer.WriteLine("MOUSE_RESOLUTION=800"); |
229 |
writer.WriteLine("NEW_RDESKTOP=On"); |
230 |
writer.WriteLine("ATSPRO=On"); |
231 |
writer.WriteLine(@"RECONNECT_PROMPT=MENU"); //tabort |
232 |
|
233 |
if (ConfigFile) |
234 |
{ //Managed client |
235 |
writer.WriteLine("NET_FILE_ENABLED=ON"); |
236 |
writer.WriteLine("NET_FILE_METHOD=tftp"); |
237 |
writer.WriteLine("NET_HOSTNAME=ATS*"); |
238 |
} |
239 |
else |
240 |
{ // Unmanaged client |
241 |
|
242 |
writer.WriteLine("NET_FILE_ENABLED=OFF"); |
243 |
writer.WriteLine("NET_HOSTNAME=ATS_*"); |
244 |
} |
245 |
|
246 |
if (UseDHCP) |
247 |
{ |
248 |
writer.WriteLine("NET_USE_DHCP=On"); |
249 |
} |
250 |
else |
251 |
{ |
252 |
writer.WriteLine(@"NET_USE_DHCP=Off"); |
253 |
writer.WriteLine(@"NET_IP_ADDRESS=""" + ClientIP.ToString() + @""""); |
254 |
writer.WriteLine(@"NET_MASK=""" + ClientIPNetmask.ToString() + @""""); |
255 |
if (ClientIPGateway != null) |
256 |
writer.WriteLine(@"NET_GATEWAY=""" + ClientIPGateway.ToString() + @""""); |
257 |
if (ClientIPDNS1 != null) |
258 |
writer.WriteLine(@"NET_DNS1=""" + ClientIPDNS1.ToString() + @""""); |
259 |
if (ClientIPDNS2 != null) |
260 |
writer.WriteLine(@"NET_DNS2=""" + ClientIPDNS2.ToString() + @""""); |
261 |
if (ClientBootServer != "") |
262 |
writer.WriteLine(@"NET_FILE_ALTERNATE=""" + ClientBootServer + @""""); |
263 |
if (ClientIPDNSSuffix != "") |
264 |
writer.WriteLine(@"NET_DNS_SEARCH=""" + ClientIPDNSSuffix + @""""); |
265 |
} |
266 |
} // Write Parameters |
267 |
|
268 |
|
269 |
|
270 |
} // class |
271 |
} // namespace |