forked from TheCynic315/JSONConfig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Configer v05.cs
294 lines (264 loc) · 9.79 KB
/
Configer v05.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
using System.Collections.Generic;
using Crestron.SimplSharp; // For Basic SIMPL# Classes
using Crestron.SimplSharp.CrestronIO;
using Newtonsoft.Json; //Thanks to Neil Colvin. Full Library @ http://www.nivloc.com/downloads/crestron/SSharp/
namespace Config
{
public class MyConfig
{
public string RmName; //Name of the Room
public ushort RoomID; //Control ID or other ID
public ushort AudioEquipID;
public ushort VideoEquipID;
public ushort SubAudio; //Has Audio
public ushort SubVideo; //Has Video
public ushort SubLights; //Has Lights
public ushort SubShades; //Has Shades
public ushort SubHVAC; //Has HVAC
public ushort[] HazSource; //Which Sources are avaiable?
public string[] HazSourceName; //What are the Source's names?
public ushort[] HazHVACID;
public ushort[] HazLightID;
public ushort[] HazShadeID;
public string[] HazRoomName; //Hvac or Light or shade Zone Name & ID
private string DaString;
private Configuration Obj;
private SourceList MysList;
/*Pass the FilePath from SIMPL+ then read in the file.
Create the JSON Object and use the library to deserialize it into
our classes.*/
#region Functions
public void Reader(string FilePath)
{
if (File.Exists(FilePath)) //Ok make sure the file is there
{
StreamReader daFile = new StreamReader(FilePath);
DaString = daFile.ReadToEnd();
daFile.Close();
//debug
//CrestronConsole.PrintLine(DaString);
}
else
{
CrestronConsole.PrintLine("File Not found\n\r"); //Generate error
DaString = "";
}
}
public void Builder(ushort ConnectTo)
{
HazSource = new ushort[25];
HazSourceName = new string[25];
HazRoomName = new string[31];
Obj = JsonConvert.DeserializeObject<Configuration>(DaString);
//debug
//CrestronConsole.PrintLine("Deserialized");
RmName = Obj.Rooms[ConnectTo].RoomName;
RoomID = Obj.Rooms[ConnectTo].ControlID;
AudioEquipID = Obj.Rooms[ConnectTo].Audio.AudioEquipID;
VideoEquipID = Obj.Rooms[ConnectTo].Video.VideoEquipID;
SubAudio = Obj.Rooms[ConnectTo].Audio.isUsing;
SubVideo = Obj.Rooms[ConnectTo].Video.isUsing;
SubLights = Obj.Rooms[ConnectTo].Lights.isUsing;
SubShades = Obj.Rooms[ConnectTo].Shades.isUsing;
SubHVAC = Obj.Rooms[ConnectTo].HVAC.isUsing;
//debug
//CrestronConsole.PrintLine("Assigned to all Variables");
try
{
for (int i = 0; i < Obj.Rooms[ConnectTo].Sources.Count; i++) //fill in the arrays
{
HazSourceName[i] = Obj.Rooms[ConnectTo].Sources[i].Name;
HazSource[i] = Obj.Rooms[ConnectTo].Sources[i].isUsing;
}
}
catch
{
CrestronConsole.PrintLine("Failed to fill in Source Names and HazSource");
}
try
{
for (int i = 0; i < Obj.Rooms.Count; i++)
{
HazRoomName[i] = Obj.Rooms[i].RoomName;
}
}
catch
{
CrestronConsole.PrintLine("Failed to fill in room names");
}
}
public void RoomList(ushort LSorH)
{
//debug
//CrestronConsole.PrintLine("Looking for room list value: {0}", LSorH);
switch (LSorH)
{
case 0:
{
try
{
for (int i = 0; i < Obj.Rooms.Count; i++)
{
HazLightID[i] = Obj.Rooms[i].Lights.LightEquipmentID;
}
}
catch
{
CrestronConsole.PrintLine("Failed to set up Light/HVAC/Shades");
}
break;
}
case 1:
{
try
{
for (int i = 0; i < Obj.Rooms.Count; i++)
{
HazShadeID[i] = Obj.Rooms[i].Shades.ShadeEquipmentID;
}
}
catch
{
CrestronConsole.PrintLine("Failed to set up Light/HVAC/Shades");
}
break;
}
case 2:
{
try
{
for (int i = 0; i < Obj.Rooms.Count; i++)
{
HazHVACID[i] = Obj.Rooms[i].HVAC.HVACEquipmentID;
}
}
catch
{
CrestronConsole.PrintLine("Failed to set up Light/HVAC/Shades");
}
break;
}
default:
{
CrestronConsole.PrintLine("Got to End Nothing");
break;
}
}
}
#endregion
#region BuildSource
//v2 Get info about Source X then send data
public void SourceInfo()
{
MysList = JsonConvert.DeserializeObject<SourceList>(DaString);
}
public string SourceName(ushort ConnectTo)
{
return MysList.ListOfSources[ConnectTo].Name;
}
public ushort SourceEquipID(ushort ConnectTo)
{
return MysList.ListOfSources[ConnectTo].EquipID;
}
public ushort SourceSubPageType(ushort ConnectTo)
{
return MysList.ListOfSources[ConnectTo].Type;
}
public ushort SourceAudioInput(ushort ConnectTo)
{
return MysList.ListOfSources[ConnectTo].Ainput;
}
public ushort SourceVideoInput(ushort ConnectTo)
{
return MysList.ListOfSources[ConnectTo].Vinput;
}
#endregion
#region Source_Classes
public class ListOfSource : Source
{
[JsonProperty("Type")]
public ushort Type { get; set; }
[JsonProperty("EquipID")]
public ushort EquipID { get; set; }
[JsonProperty("Ainput")]
public ushort Ainput { get; set; }
[JsonProperty("Vinput")]
public ushort Vinput { get; set; }
}
public class SourceList
{
[JsonProperty("ListOfSources")]
public IList<ListOfSource> ListOfSources { get; set; }
}
#endregion
#region Main_Classes
//Classes built from http://jsonutils.com/
public class Audio
{
[JsonProperty("isUsing")]
public ushort isUsing { get; set; }
[JsonProperty("AudioEquipID")]
public ushort AudioEquipID { get; set; }
}
public class Video
{
[JsonProperty("isUsing")]
public ushort isUsing { get; set; }
[JsonProperty("VideoEquipID")]
public ushort VideoEquipID { get; set; }
}
public class Lights
{
[JsonProperty("isUsing")]
public ushort isUsing { get; set; }
[JsonProperty("LightEquipmentID")]
public ushort LightEquipmentID { get; set; }
}
public class Shades
{
[JsonProperty("isUsing")]
public ushort isUsing { get; set; }
[JsonProperty("ShadeEquipmentID")]
public ushort ShadeEquipmentID { get; set; }
}
public class HVAC
{
[JsonProperty("isUsing")]
public ushort isUsing { get; set; }
[JsonProperty("HVACEquipmentID")]
public ushort HVACEquipmentID { get; set; }
}
public class Source
{
[JsonProperty("Name")]
public string Name { get; set; }
[JsonProperty("isUsing")]
public ushort isUsing { get; set; }
}
public class Room
{
[JsonProperty("RoomName")]
public string RoomName { get; set; }
[JsonProperty("ControlID")]
public ushort ControlID { get; set; }
[JsonProperty("Audio")]
public Audio Audio { get; set; }
[JsonProperty("Video")]
public Video Video { get; set; }
[JsonProperty("Lights")]
public Lights Lights { get; set; }
[JsonProperty("Shades")]
public Shades Shades { get; set; }
[JsonProperty("HVAC")]
public HVAC HVAC { get; set; }
[JsonProperty("Sources")]
public IList<Source> Sources { get; set; }
}
public class Configuration
{
[JsonProperty("Rooms")]
public IList<Room> Rooms { get; set; }
}
#endregion
}
}