-
Notifications
You must be signed in to change notification settings - Fork 5
/
Configer.cs
141 lines (116 loc) · 4.33 KB
/
Configer.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
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;
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 ushort[] HazSourceType; //What is the Source so we can display correct subpage/controls in SIMPL. Rout to an equ
public int Count; //Total number of sources found. I'm passing this back to SIMPL+ to make the loop dynamic
/*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 = "";
}
Configuration Obj = JsonConvert.DeserializeObject<Configuration>(DaString); //All the heavy lifting
HazSource = new ushort[25];
HazSourceName = new string[25];
HazSourceType = new ushort[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;
HazSourceType[i] = Obj.Sources[i].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; }
}
/* 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; }
}
}
}