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 GateWays = new List { }; public List Scenes = new List { };// public List Commons = new List { }; public List Logics = new List { }; /// /// 保存高级网关场景数据 /// 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 ("SubnetID"); gateWay2.DeviceID = jObject.Value ("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; } } }