JLChen
2020-05-28 04bd96cbf5d12a4e4b116d2b05fd0d05ea81ee23
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
 
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;
        }
 
    }
}