|
using System.Collections.Generic;
|
using Shared;
|
using System;
|
|
namespace SuperGateWay
|
{
|
[System.Serializable]
|
public class GateWay : SuperCommon
|
{
|
public byte SubnetID;
|
public byte DeviceID;
|
public string Name = "";
|
static GateWay ()
|
{
|
if (GateWays.Count == 0) {
|
Instance = new GateWay { SubnetID = 0, DeviceID = 0 };
|
}
|
}
|
public static GateWay Instance{
|
get;set;
|
}
|
public static List<GateWay> GateWays = new List<GateWay> { };
|
public List<Scene> Scenes = new List<Scene> { };//
|
public List<SuperGateWayCommon> Commons = new List<SuperGateWayCommon> { };
|
public List<Logic> Logics = new List<Logic> { };
|
|
|
|
|
/// <summary>
|
/// 保存高级网关场景数据
|
/// </summary>
|
public void save (string str)
|
{
|
if ("SceneListFilePath" == str) {
|
Shared.IO.FileUtils.WriteFileByBytes ("SceneListFilePath", System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (Scenes)));
|
} else if ("LogicListFilePath" == str) {
|
Shared.IO.FileUtils.WriteFileByBytes ("LogicListFilePath", System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (Logics)));
|
} else if ("DeviceListFilePath" == str) {
|
Shared.IO.FileUtils.WriteFileByBytes ("DeviceListFilePath", System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (Commons)));
|
}
|
}
|
|
public static GateWay gateWay ()
|
{
|
GateWay gateWay1 = null;
|
GateWays.Clear ();
|
var filesList = Shared.IO.FileUtils.ReadFiles ().FindAll ((obj) => {
|
string [] str = obj.Split ('_');
|
return obj.StartsWith ("Equipment_") && str.Length == 4;
|
});
|
|
foreach (var file in filesList) {
|
if (file.Split ('_') [1] != DeviceType.SuperWireless.ToString ()) {
|
continue;
|
}
|
var devicestring = System.Text.Encoding.UTF8.GetString (Shared.IO.FileUtils.ReadFile (file));
|
if (devicestring == null) {
|
continue;
|
}
|
var jObject = Newtonsoft.Json.Linq.JObject.Parse (devicestring);
|
if (jObject == null) {
|
continue;
|
}
|
GateWay gateWay2 = new GateWay ();
|
gateWay2.Name = jObject ["Name"]?.ToString ();
|
gateWay2.SubnetID = jObject.Value<byte> ("SubnetID");
|
gateWay2.DeviceID = jObject.Value<byte> ("DeviceID");
|
GateWays.Add (gateWay2);
|
}
|
if (GateWays.Count == 0) {
|
gateWay1 = new GateWay { SubnetID = 0, DeviceID = 0 };
|
} else {
|
foreach (var gateWay3 in GateWays) {
|
gateWay1 = gateWay3;
|
}
|
}
|
return gateWay1;
|
}
|
|
}
|
}
|