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

Contents of /trunk/TSAdminTool/ImageDesigntimeConfig.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 64 - (show annotations) (download)
Thu Jul 12 18:56:31 2012 UTC (7 years, 7 months ago) by william
File size: 11369 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 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 {
105 string error = "Error: Default record not written (24712)";
106 using (log4net.NDC.Push(string.Format("recordname={0}", DEFAULT_RECORD_NAME)))
107 {
108 Logging.ATSAdminLog.Error(error);
109 }
110 MessageBox.Show(string.Format("{0} -> {1}", error, string.Format("recordname={0}", DEFAULT_RECORD_NAME)));
111 return;
112 }
113 }
114 }
115
116 public void ReadFromDatabase(DataRow row)
117 {
118 UseDHCP = System.Convert.ToBoolean(row["UseDHCP"]);
119 ClientIP = row["ClientIPAddress"].ToString().Length == 0 ? null : IPAddress.Parse(row["ClientIPAddress"].ToString());
120 ClientIPNetmask = row["ClientIPNetmask"].ToString().Length == 0 ? null : IPAddress.Parse(row["ClientIPNetmask"].ToString());
121 ClientIPGateway = row["ClientIPGateway"].ToString().Length == 0 ? null : IPAddress.Parse(row["ClientIPGateway"].ToString());
122 ClientIPDNS1 = row["ClientIPDNS1"].ToString().Length == 0 ? null : IPAddress.Parse(row["ClientIPDNS1"].ToString());
123 ClientIPDNS2 = row["ClientIPDNS2"].ToString().Length == 0 ? null : IPAddress.Parse(row["ClientIPDNS2"].ToString());
124 ClientIPDNSSuffix = row["ClientIPDNSSuffix"].ToString();
125 ClientBootServer = row["ClientBootServer"].ToString();
126 ConfigFile = System.Convert.ToBoolean(row["ConfigFile"]);
127 OnlyUseRDP = System.Convert.ToBoolean(row["OnlyUseRDP"]);
128 BootPicture.Type = (int)row["BootPicture"];
129 NetworkDriver = row["NetworkDriver"].ToString();
130 SoundType = (ATSSoundType)(int)row["SoundType"];
131 SoundDriver = row["SoundDriver"].ToString();
132 GraphicsDriver = row["GraphicsDriver"].ToString();
133
134 Debug = (int)row["Debug"];
135 BootPackage = (int)row["BootPackage"];
136 BootPicture.Width = (int)row["BootPictureWidth"];
137 BootPicture.Height = (int)row["BootPictureHeight"];
138 BootPicture.ProgressBar = (int)row["BootPictureProgressBar"];
139 if (row["BootPicturePng"] != DBNull.Value)
140 {
141 byte[] bootPictureArray = (byte[])row["BootPicturePng"];
142 MemoryStream ms = new MemoryStream(bootPictureArray);
143 BootPicture.CustomPicture = new Bitmap(ms);
144 ms.Close();
145 }
146 }
147
148 public void WriteDefaultsToDatabase()
149 {
150 atsDataSetTableAdapters.ImageTableAdapter imageTableAdapter;
151 atsDataSet datasetImage;
152 DataRow defaultRow;
153
154 imageTableAdapter = new atsDataSetTableAdapters.ImageTableAdapter();
155 datasetImage = new atsDataSet();
156
157 imageTableAdapter.Fill(datasetImage.Image);
158
159 // Loook up the default row
160 defaultRow = datasetImage.Image.Rows.Find(DEFAULT_RECORD_NAME);
161 if (defaultRow != null)
162 {
163 WriteToDatabase(defaultRow);
164 }
165 else
166 {
167 // There is no default record, create one
168 DataRow newRow = datasetImage.Image.NewRow();
169 WriteToDatabase(newRow);
170 newRow["Name"] = DEFAULT_RECORD_NAME;
171 datasetImage.Image.Rows.Add(newRow);
172 }
173
174 // Save default row
175 imageTableAdapter.Update(datasetImage.Image);
176 }
177
178
179 public void WriteToDatabase(DataRow row)
180 {
181 row["UseDHCP"] = UseDHCP;
182 if (ClientIP != null)
183 row["ClientIPAddress"] = ClientIP.ToString();
184 else
185 row["ClientIPAddress"] = null;
186
187 if (ClientIPNetmask != null)
188 row["ClientIPNetmask"] = ClientIPNetmask.ToString();
189 else
190 row["ClientIPNetmask"] = null;
191
192 if (ClientIPGateway != null)
193 row["ClientIPGateway"] = ClientIPGateway.ToString();
194 else
195 row["ClientIPGateway"] = null;
196
197 if (ClientIPDNS1 != null)
198 row["ClientIPDNS1"] = ClientIPDNS1.ToString();
199 else
200 row["ClientIPDNS1"] = null;
201
202 if (ClientIPDNS2 != null)
203 row["ClientIPDNS2"] = ClientIPDNS2.ToString();
204 else
205 row["ClientIPDNS2"] = null;
206
207 row["ClientIPDNSSuffix"] = ClientIPDNSSuffix;
208 row["ClientBootServer"] = ClientBootServer;
209 row["ConfigFile"] = ConfigFile;
210 row["OnlyUseRDP"] = OnlyUseRDP;
211 row["BootPicture"] = BootPicture.Type;
212 row["NetworkDriver"] = NetworkDriver;
213 row["SoundType"] = (int)SoundType;
214 row["SoundDriver"] = SoundDriver;
215 row["GraphicsDriver"] = GraphicsDriver;
216
217
218 row["Debug"] = Debug;
219 row["BootPackage"] = BootPackage;
220 row["BootPictureWidth"] = BootPicture.Width;
221 row["BootPictureHeight"] = BootPicture.Height;
222 row["BootPictureProgressBar"] = BootPicture.ProgressBar;
223
224 MemoryStream ms = new MemoryStream();
225 BootPicture.CustomPicture.Save (ms, ImageFormat.Png);
226 byte[] bootPictureArray = ms.GetBuffer();
227 row["BootPicturePng"] = bootPictureArray;
228 ms.Close();
229 }
230
231 // Write parameters to file. Used only by write config file in this class and in the class ATSImage
232 public void WriteParameters(StreamWriter writer)
233 {
234 writer.WriteLine("AUTOSTART=On");
235 writer.WriteLine("USB_ENABLED=On");
236 writer.WriteLine("MOUSE_RESOLUTION=800");
237 writer.WriteLine("NEW_RDESKTOP=On");
238 writer.WriteLine("ATSPRO=On");
239 writer.WriteLine(@"RECONNECT_PROMPT=MENU"); //tabort
240
241 if (ConfigFile)
242 { //Managed client
243 writer.WriteLine("NET_FILE_ENABLED=ON");
244 writer.WriteLine("NET_FILE_METHOD=tftp");
245 writer.WriteLine("NET_HOSTNAME=ATS*");
246 }
247 else
248 { // Unmanaged client
249
250 writer.WriteLine("NET_FILE_ENABLED=OFF");
251 writer.WriteLine("NET_HOSTNAME=ATS_*");
252 }
253
254 if (UseDHCP)
255 {
256 writer.WriteLine("NET_USE_DHCP=On");
257 }
258 else
259 {
260 writer.WriteLine(@"NET_USE_DHCP=Off");
261 writer.WriteLine(@"NET_IP_ADDRESS=""" + ClientIP.ToString() + @"""");
262 writer.WriteLine(@"NET_MASK=""" + ClientIPNetmask.ToString() + @"""");
263 if (ClientIPGateway != null)
264 writer.WriteLine(@"NET_GATEWAY=""" + ClientIPGateway.ToString() + @"""");
265 if (ClientIPDNS1 != null)
266 writer.WriteLine(@"NET_DNS1=""" + ClientIPDNS1.ToString() + @"""");
267 if (ClientIPDNS2 != null)
268 writer.WriteLine(@"NET_DNS2=""" + ClientIPDNS2.ToString() + @"""");
269 if (ClientBootServer != "")
270 writer.WriteLine(@"NET_FILE_ALTERNATE=""" + ClientBootServer + @"""");
271 if (ClientIPDNSSuffix != "")
272 writer.WriteLine(@"NET_DNS_SEARCH=""" + ClientIPDNSSuffix + @"""");
273 }
274 } // Write Parameters
275
276
277
278 } // class
279 } // namespace

  ViewVC Help
Powered by ViewVC 1.1.22