forked from TheCynic315/JSONConfig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Configer v01.cs
182 lines (141 loc) · 5.1 KB
/
Configer v01.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
using System;
using System.Text;
using Crestron.SimplSharp; // For Basic SIMPL# Classes
using Newtonsoft.Json; //Thanks to Neil Colvin. Full Library @ http://www.nivloc.com/downloads/crestron/SSharp/
using Crestron.SimplSharp.CrestronIO;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
namespace Config
{
public class MyConfig
{
public string RmName; //Name of the Room
public ushort RoomID; //Control ID or other ID
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 int Count; //Total number of sources found. I'm passing this back to SIMPL+ to make the loop dynamic
private string DaString;
private Configuration Obj;
/*Pass the FilePath from SIMPL+ then read in the file.
Create the JSON Object and use the library to deserialize it into
our classes.
*/
public void Reader(string FilePath)
{
//string DaString;
if (File.Exists(FilePath)) //Ok make sure the file is there
{
StreamReader daFile = new StreamReader(FilePath);
DaString = daFile.ReadToEnd();
daFile.Close();
}
else
{
CrestronConsole.PrintLine("File Not found\n\r"); //Generate error
DaString = "";
}
Obj = JsonConvert.DeserializeObject<Configuration>(DaString); //All the heavy lifting
}
public void Builder()
{
HazSource = new ushort[25];
HazSourceName = new string[25];
this.RmName = Obj.RoomName;
this.RoomID = Obj.ID;
this.SubAudio = Obj.Audio;
this.SubVideo = Obj.Video;
this.SubLights = Obj.Lights;
this.SubShades = Obj.Shades;
this.SubHVAC = Obj.HVAC;
Count = Obj.Sources.Count;
for (int i = 0; i < Count; i++) //fill in the arrays
{
HazSourceName[i] = Obj.Sources[i].Name;
HazSource[i] = Obj.Sources[i].isUsing;
}
}
public ushort LookUpEquipID(ushort daKey)
{
return Obj.Sources[daKey].EquipID;
}
public ushort LookUpAinput(ushort daKey)
{
return Obj.Sources[daKey].Ainput;
}
public ushort LookUpVinput(ushort daKey)
{
return Obj.Sources[daKey].Vinput;
}
public ushort LookUpSubPageType(ushort daKey)
{
return Obj.Sources[daKey].SourceType;
}
/*Classes built from http://jsonutils.com/
Sources is an array of 24 entries. Can add properties here
example:
"Sources": [
{
"Name": "Cable 1",
"isUsing": 1,
"Type": 1
},{
"Name": "Cable 2",
"isUsing": 1,
"Type": 1
},{
"Name": "Cable 3",
"isUsing": 0,
"Type": 1
},{
"Name": "Cable 4",
"isUsing": 0,
"Type": 1
},{
"Name": "Apple TV 1",
"isUsing": 1,
"Type": 3
*/
public class Source
{
[JsonProperty("Name")]
public string Name { get; set; }
[JsonProperty("isUsing")]
public ushort isUsing { get; set; }
[JsonProperty("Type")]
public ushort SourceType { get; set; }
[JsonProperty("EquipID")]
public ushort EquipID { get; set; }
[JsonProperty("Ainput")]
public ushort Ainput { get; set; }
[JsonProperty("Vinput")]
public ushort Vinput { get; set; }
}
/* This is the main object
This tells the JsonConvert where to put everything
*/
public class Configuration
{
[JsonProperty("RoomName")]
public string RoomName { get; set; }
[JsonProperty("ID")]
public ushort ID { get; set; }
[JsonProperty("Audio")]
public ushort Audio { get; set; }
[JsonProperty("Video")]
public ushort Video { get; set; }
[JsonProperty("Lights")]
public ushort Lights { get; set; }
[JsonProperty("Shades")]
public ushort Shades { get; set; }
[JsonProperty("HVAC")]
public ushort HVAC { get; set; }
[JsonProperty("Sources")]
public IList<Source> Sources { get; set; }
}
}
}