-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCDeviceSettings.cs
296 lines (262 loc) · 12 KB
/
CDeviceSettings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.IO;
namespace Ground_Floor
{
class CDevices
{
public CDevices()
{
lstPrm = new List<string>();
}
public int iTag;
public int iType;
public bool bVisible;
public string sDescription;
public int iValue;
public List<string> lstPrm;
public CTwinCatInterface TCInterface;
}
class CZones
{
public int iZoneTag;
public List<string> lstServerZones;
public int iFloor;
public string sZoneDescription;
public List<CDevices> lstDevices;
public List<string> lstAcPrm;
public CTwinCatInterface ACTCinterface;
public int iAVZoneID;
public CZones()
{
lstDevices = new List<CDevices>();
lstAcPrm = new List<string>();
lstServerZones = new List<string>();
iAVZoneID = -1;
}
}
class CDeviceSettings
{
private bool _bFileMissing;
private string _sFileName;
public List<string> lstSources;
public List<int> lstSourceID;
public int iDefaultFloorNo;
public int iHeight;
public int iSlideWidth;
public int iToggleWidth;
public int iSceneWidth;
public int iBlindWidth;
public int iMarginText;
public int iMarginSymbol;
public int iInitialMarginTopText;
public int iInitialMarginTopSymbol;
public int iMarginColumn;
public int iFontSize;
public int iFontColor;
public int iTextWidth;
// Motion Sensor Default Settings :: Begin
public int iMsensorDefaultDelay;
public int iMsensorDefaultFromHour;
public int iMsensorDefaultFromMinute;
public int iMsensorDefaultToHour;
public int iMsensorDefaultToMinute;
// Motion Sensor Default Settings :: End
public List<CZones> lstZones;
public List<string> lstControllerPrm;
public string sServerAddress;
public int iServerPort;
// Global :: Begin
public string sGlobalLightsDescription;
public string sGlobalBlindsDescription;
public string sGlobalACDescription;
public string sGlobalFAHUDescription;
public string sGlobalMSensorDescription;
// Global :: End
public CDeviceSettings(string sFileName)
{
lstZones = new List<CZones>();
lstControllerPrm = new List<string>();
lstSources = new List<string>();
lstSourceID = new List<int>();
_sFileName = sFileName;
try
{
if (File.Exists(_sFileName))
{
_bFileMissing = false;
}
else
{
System.Windows.Forms.MessageBox.Show("XML settings file is missing.");
_bFileMissing = true;
}
}
catch
{
System.Windows.Forms.MessageBox.Show("Exception caught while creating instance of XML reader. Check presence of xml settings file.");
_bFileMissing = true;
}
}
public bool GetDeviceSettings()
{
bool bRet = false;
if (!_bFileMissing)
{
XmlTextReader XMLReader;
string sValue;
string sElemtName = "";
CZones locZone = new CZones();
CDevices locDevice = new CDevices();
string[] myLstPrm;
int iCptString;
XMLReader = new XmlTextReader(_sFileName);
while (XMLReader.Read())
{
switch (XMLReader.NodeType)
{
case XmlNodeType.Element:
sElemtName = XMLReader.Name;
break;
case XmlNodeType.Text:
sValue = XMLReader.Value;
if (sElemtName == "CONTROLLER_PRM")
lstControllerPrm.Add(sValue);
if (sElemtName == "DEFAULT_FLOOR")
iDefaultFloorNo = Convert.ToInt32(sValue);
if (sElemtName == "HEIGHT")
iHeight = Convert.ToInt32(sValue);
if (sElemtName == "SLIDE_WIDTH")
iSlideWidth = Convert.ToInt32(sValue);
if (sElemtName == "TOGGLE_WIDTH")
iToggleWidth = Convert.ToInt32(sValue);
if (sElemtName == "SCENE_WIDTH")
iSceneWidth = Convert.ToInt32(sValue);
if (sElemtName == "BLIND_WIDTH")
iBlindWidth = Convert.ToInt32(sValue);
if (sElemtName == "MARGIN_TEXT")
iMarginText = Convert.ToInt32(sValue);
if (sElemtName == "MARGIN_SYMBOL")
iMarginSymbol = Convert.ToInt32(sValue);
if (sElemtName == "INITIAL_MARGIN_TOP_TEXT")
iInitialMarginTopText = Convert.ToInt32(sValue);
if (sElemtName == "INITIAL_MARGIN_TOP_SYMBOL")
iInitialMarginTopSymbol = Convert.ToInt32(sValue);
if (sElemtName == "MARGIN_COLUMN")
iMarginColumn = Convert.ToInt32(sValue);
if (sElemtName == "FONT_SIZE")
iFontSize = Convert.ToInt32(sValue);
if (sElemtName == "FONT_COLOR")
iFontColor = Convert.ToInt32(sValue);
if (sElemtName == "TEXT_WIDTH")
iTextWidth = Convert.ToInt32(sValue);
// Motion SensorDefault Settings :: Begin
if (sElemtName == "MSENSOR_DEFAULT_DELAY")
iMsensorDefaultDelay = Convert.ToInt32(sValue);
if (sElemtName == "MSENSOR_DEFAULT_FROM_HOUR")
iMsensorDefaultFromHour = Convert.ToInt32(sValue);
if (sElemtName == "MSENSOR_DEFAULT_FROM_MINUTE")
iMsensorDefaultFromMinute = Convert.ToInt32(sValue);
if (sElemtName == "MSENSOR_DEFAULT_TO_HOUR")
iMsensorDefaultToHour = Convert.ToInt32(sValue);
if (sElemtName == "MSENSOR_DEFAULT_TO_MINUTE")
iMsensorDefaultToMinute = Convert.ToInt32(sValue);
// Motion SensorDefault Settings :: End
if (sElemtName == "AV_SOURCE_ID")
{
myLstPrm = sValue.Split(';');
lstSources.Add(myLstPrm[1]);
lstSourceID.Add(Convert.ToInt32(myLstPrm[0]));
}
if (sElemtName == "LCS_SERVER")
{
myLstPrm = sValue.Split(';');
this.sServerAddress = myLstPrm[0];
this.iServerPort = Convert.ToInt32(myLstPrm[1]);
}
// Global :: Begin
if (sElemtName == "GLOBAL_LIGHTS_DESCRIPTION")
sGlobalLightsDescription = sValue;
if (sElemtName == "GLOBAL_BLINDS_DESCRIPTION")
sGlobalBlindsDescription = sValue;
if (sElemtName == "GLOBAL_AC_DESCRIPTION")
sGlobalACDescription = sValue;
if (sElemtName == "GLOBAL_FAHU_DESCRIPTION")
sGlobalFAHUDescription = sValue;
if (sElemtName == "GLOBAL_MSENSOR_DESCRIPTION")
sGlobalMSensorDescription = sValue;
// Global :: End
if (sElemtName == "ZONE_TAG")
{
locZone = new CZones();
locZone.iZoneTag = Convert.ToInt32(sValue);
}
if (sElemtName == "ZONE_SERVER")
{
myLstPrm = sValue.Split(';');
for (iCptString = 0; iCptString < myLstPrm.Length; iCptString++)
locZone.lstServerZones.Add(myLstPrm[iCptString]);
}
if (sElemtName == "ZONE_AC_PRM")
{
myLstPrm = sValue.Split(';');
for (iCptString = 0; iCptString < myLstPrm.Length; iCptString++)
locZone.lstAcPrm.Add(myLstPrm[iCptString]);
locZone.ACTCinterface = new CTwinCatInterface(locZone.lstAcPrm[0], Convert.ToInt32(locZone.lstAcPrm[1]));
}
if (sElemtName == "FLOOR")
{
locZone.iFloor = Convert.ToInt32(sValue);
}
if (sElemtName == "AUDIO_ZONE_ID")
{
locZone.iAVZoneID = Convert.ToInt32(sValue);
}
if (sElemtName == "TAG")
{
locDevice = new CDevices();
locDevice.iTag = Convert.ToInt32(sValue);
}
if (sElemtName == "PARAMETERS")
{
myLstPrm = sValue.Split(';');
locDevice.lstPrm.Clear();
for (iCptString = 0; iCptString < myLstPrm.Length; iCptString++)
locDevice.lstPrm.Add(myLstPrm[iCptString]);
int iControllerIdx = Convert.ToInt32(locDevice.lstPrm[0]);
myLstPrm = lstControllerPrm[iControllerIdx].Split(';');
locDevice.TCInterface = new CTwinCatInterface(myLstPrm[0], Convert.ToInt32(myLstPrm[1]));
}
if (sElemtName == "TYPE")
{
locDevice.iType = Convert.ToInt32(sValue);
}
if (sElemtName == "VISIBLE")
{
locDevice.bVisible = Convert.ToBoolean(sValue);
}
if (sElemtName == "DESCRIPTION")
{
locDevice.sDescription = sValue;
}
if (sElemtName == "VALUE")
{
locDevice.iValue = Convert.ToInt32(sValue);
locZone.lstDevices.Add(locDevice);
}
if (sElemtName == "ZONE_DESCRIPTION")
{
locZone.sZoneDescription = sValue;
lstZones.Add(locZone);
bRet = true;
}
break;
}
}
}
return bRet;
}
}
}