黄学彪
2020-09-22 ade5917841b0fdcb1df7353ef7c56b1a1bdc9282
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
using System;
using System.Collections.Generic;
using Shared;
using ZigBee.Device;
 
namespace Shared.Phone.Device.Logic
{
    public class LogicIfon
    {
        #region ----逻辑条件输入----
        /// <summary>
        /// 添加设备条件的方法
        /// </summary>
        /// <param name="common">Common.</param>
        /// <param name="objecttype">Objecttype.</param>
        public static void AddDeviceconditions(CommonDevice common, Dictionary<string, string> objecttype) 
        {
            for (int i = 0; i < Common.Logic.CurrentLogic.Conditions.Count; i++)
            {
                if (Common.Logic.CurrentLogic.Conditions[i]["Type"] == "1")
                {
                    if ((Common.Logic.CurrentLogic.Conditions[i]["MacAddr"] == common.DeviceAddr) && (Common.Logic.CurrentLogic.Conditions[i]["Epoint"] == common.DeviceEpoint.ToString()))
                    {
                        if (common.Type == DeviceType.TemperatureSensor)//设备温度传感器有点特别
                        {
                            var dev = common as TemperatureSensor;
                            string str = "";
                            if (dev.SensorDiv == 1)
                            {
                                str = "1026";
                            }
                            else
                            {
                                str = "1029";
                            }
                            if (Common.Logic.CurrentLogic.Conditions[i]["Cluster_ID"] == str)
                            {
                                Common.Logic.CurrentLogic.Conditions.RemoveAt(i);
                                Common.Logic.CurrentLogic.Conditions.Insert(i, objecttype);
                                return;
                            }
 
                        }
                        else if (common.Type == DeviceType.IASZone)
                        {
                            var iASZonedevice = common as IASZone;
                            if (iASZonedevice.IasDeviceType == 541)
                            {//球形移动传感器
                                if (Common.Logic.CurrentLogic.Conditions[i]["Cluster_ID"] == objecttype["Cluster_ID"])
                                {
                                    Common.Logic.CurrentLogic.Conditions.RemoveAt(i);
                                    Common.Logic.CurrentLogic.Conditions.Insert(i, objecttype);
                                    return;
                                }
                                continue;
                            }
 
                            Common.Logic.CurrentLogic.Conditions.RemoveAt(i);
                            Common.Logic.CurrentLogic.Conditions.Insert(i, objecttype);
                            return;
 
                        }
                        else
                        {
                            Common.Logic.CurrentLogic.Conditions.RemoveAt(i);
                            Common.Logic.CurrentLogic.Conditions.Insert(i, objecttype);
                            return;
                        }
                    }
 
                }
            }
            Common.Logic.CurrentLogic.Conditions.Add(objecttype);
        }
        /// <summary>
        /// 添加Logic条件的方法
        /// </summary>
        /// <param name="common">Common.</param>
        /// <param name="objecttype">Objecttype.</param>
        public static void AddLogicconditions(Common.Logic logic, Dictionary<string, string> objecttype)
        {
            for (int i = 0; i < Common.Logic.CurrentLogic.Conditions.Count; i++)
            {
                if (Common.Logic.CurrentLogic.Conditions[i]["Type"] == "2")
                {
 
                    if (Common.Logic.CurrentLogic.Conditions[i]["Condition_LogicId"] == logic.LogicId.ToString())
                    {
                        Common.Logic.CurrentLogic.Conditions.RemoveAt(i);
                        Common.Logic.CurrentLogic.Conditions.Insert(i, objecttype);
                        return;
                    }
 
                }
 
            }
            Common.Logic.CurrentLogic.Conditions.Add(objecttype);
        }
        /// <summary>
        /// 添加安防条件的方法
        /// </summary>
        /// <param name="objecttype">Objecttype.</param>
        public static void AddSecurityconditions(Dictionary<string, string> objecttype)
        {
            for (int i = 0; i < Common.Logic.CurrentLogic.Conditions.Count; i++)
            {
                if (Common.Logic.CurrentLogic.Conditions[i]["Type"] == "6")
                {
 
                    Common.Logic.CurrentLogic.Conditions.RemoveAt(i);
                    Common.Logic.CurrentLogic.Conditions.Insert(i, objecttype);
                    return;
 
                }
 
            }
            Common.Logic.CurrentLogic.Conditions.Add(objecttype);
        }
 
        /// <summary>
        /// 添加地理位置条件的方法
        /// </summary>
        /// <param name="objecttype">Objecttype.</param>
        public static void AddLocationconditions(Dictionary<string, string> objecttype)
        {
            for (int i = 0; i < Common.Logic.CurrentLogic.Conditions.Count; i++)
            {
                if (Common.Logic.CurrentLogic.Conditions[i]["Type"] == objecttype["Type"])
                {
 
                    Common.Logic.CurrentLogic.Conditions.RemoveAt(i);
                    Common.Logic.CurrentLogic.Conditions.Insert(i, objecttype);
                    return;
 
                }
 
            }
            Common.Logic.CurrentLogic.Conditions.Add(objecttype);
        }
        #endregion
        #region ----逻辑输出目标----
 
        /// <summary>
        /// 添加设备输出的方法
        /// </summary>
        /// <param name="common">Common.</param>
        /// <param name="actionsInfo">Objecttype.</param>
        public static void AddDeviceActions(ZigBee.Device.CommonDevice common, Dictionary<string, object> actionsInfo)
        {
            for (int i = 0; i < Common.Logic.CurrentLogic.Actions.Count; i++)
            {
                if (Common.Logic.CurrentLogic.Actions[i]["LinkType"].ToString() == "0")
                {
                    if (Common.Logic.CurrentLogic.Actions[i]["DeviceAddr"].ToString() == common.DeviceAddr && Common.Logic.CurrentLogic.Actions[i]["Epoint"].ToString() == common.DeviceEpoint.ToString())
                    {
                        Common.Logic.CurrentLogic.Actions.RemoveAt(i);
                        Common.Logic.CurrentLogic.Actions.Insert(i, actionsInfo);
                        return;
                    }
                }
            }
            Common.Logic.CurrentLogic.Actions.Add(actionsInfo);
        }
        /// <summary>
        /// 添加门锁设备输出的方法
        /// </summary>
        /// <param name="common">Common.</param>
        /// <param name="actionsInfo">Objecttype.</param>
        public static void AddDoorLockActions(ZigBee.Device.CommonDevice common, Dictionary<string, object> actionsInfo)
        {
            for (int i = 0; i < Common.Logic.CurrentLogic.Actions.Count; i++)
            {
                if (Common.Logic.CurrentLogic.Actions[i]["LinkType"].ToString() == "8")
                {
                    if (Common.Logic.CurrentLogic.Actions[i]["DeviceAddr"].ToString() == common.DeviceAddr && Common.Logic.CurrentLogic.Actions[i]["Epoint"].ToString() =="200")
                    {
                        Common.Logic.CurrentLogic.Actions.RemoveAt(i);
                        Common.Logic.CurrentLogic.Actions.Insert(i, actionsInfo);
                        return;
                    }
                }
            }
            Common.Logic.CurrentLogic.Actions.Add(actionsInfo);
        }
        /// <summary>
        /// 添加Scene输出的方法
        /// </summary>
        /// <param name="Scene">Common.</param>
        /// <param name="actionsInfo">Objecttype.</param>
        public static void AddSceneactions(Shared.Common.SceneUI Scene, Dictionary<string, object> actionsInfo)
        {
            for (int i = 0; i < Common.Logic.CurrentLogic.Actions.Count; i++)
            {
                if (Common.Logic.CurrentLogic.Actions[i]["LinkType"].ToString() == "2")
                {
                    if (Common.Logic.CurrentLogic.Actions[i]["DeviceAddr"].ToString() == Scene.Id.ToString())
                    {
                        Common.Logic.CurrentLogic.Actions.RemoveAt(i);
                        Common.Logic.CurrentLogic.Actions.Insert(i, actionsInfo);
                        return;
                    }
                }
            }
            Common.Logic.CurrentLogic.Actions.Add(actionsInfo);
        }
        /// <summary>
        /// 添加安防输出的方法
        /// </summary>
        /// <param name="actionsInfo">actionsInfo.</param>
        public static void AddSecurityactions(Dictionary<string, object> actionsInfo)
        {
            for (int i = 0; i < Common.Logic.CurrentLogic.Actions.Count; i++)
            {
                if (Common.Logic.CurrentLogic.Actions[i]["LinkType"].ToString() == "6")
                {
                    Common.Logic.CurrentLogic.Actions.RemoveAt(i);
                    Common.Logic.CurrentLogic.Actions.Insert(i, actionsInfo);
                    return;
                }
            }
            Common.Logic.CurrentLogic.Actions.Add(actionsInfo);
        }
 
        /// <summary>
        /// 添加自动化输出的方法
        /// </summary>
        /// <param name="actionsInfo">Objecttype.</param>
        /// <param name="logic">logic</param>
        public static void AddLogicactions(Common.Logic logic, Dictionary<string, object> actionsInfo)
        {
 
            for (int i = 0; i < Common.Logic.CurrentLogic.Actions.Count; i++)
            {
                if (Common.Logic.CurrentLogic.Actions[i]["LinkType"].ToString() == "4")
                {
                    if (Common.Logic.CurrentLogic.Actions[i]["DeviceAddr"].ToString() == logic.LogicId.ToString())
                    {
                        Common.Logic.CurrentLogic.Actions.RemoveAt(i);
                        Common.Logic.CurrentLogic.Actions.Insert(i, actionsInfo);
                        return;
                    }
                }
            }
            Common.Logic.CurrentLogic.Actions.Add(actionsInfo);
 
        }
        #endregion
        #region ----关联app账号----
        /// <summary>
        /// 关联app账号
        /// </summary>
        /// <param name="accountsInfo"></param>
        public static void Addaccounts(Dictionary<string, string> accountsInfo)
        {
            for (int i = 0; i < Common.Logic.CurrentLogic.Accounts.Count; i++)
            {
                if (Common.Logic.CurrentLogic.Accounts[i]["Type"] == accountsInfo["Type"])
                {
                    Common.Logic.CurrentLogic.Accounts.RemoveAt(i);
                    Common.Logic.CurrentLogic.Accounts.Insert(i, accountsInfo);
                    return;
                }
            }
            Common.Logic.CurrentLogic.Accounts.Add(accountsInfo);
        }
        #endregion
    }
 
 
}