BruceLee
2019-09-24 a9f88790c31c8b61d9b90241c4df258a980f1c00
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
using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json.Linq;
 
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 全局接收网关推送的的逻辑(为了执行速度,尽可能的别加耗时的操作)
    /// </summary>
    public class HdlGatewayReceiveLogic
    {
        #region ■ 全局接收___________________________
 
        /// <summary>
        /// 全局接收网关推送的的逻辑(为了执行速度,尽可能的别加耗时的操作)
        /// </summary>
        /// <param name="gatewayId">网关ID</param>
        /// <param name="topic">主题</param>
        /// <param name="receiveData">接收的数据</param>
        public static void GatewayOverallMsgReceive(string gatewayId, string topic, JObject receiveData)
        {
            if (topic == "AppNoLogin")
            {
                Application.RunOnMainThread(() =>
                {
                    //登录密匙已经过期,请重新登录
                    string msg = Language.StringByID(R.MyInternationalizationString.uTokenIsOldAndLoginAgain);
                    var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
                    contr.Show();
 
                    UserCenterLogic.ReLoginAgain(UserCenterResourse.UserInfo.Account, false);
                });
            }
            else if (topic == "BeingSqueezedOffline")
            {
                Application.RunOnMainThread(() =>
                {
                    //此帐号已在别处登录,您被迫下线
                    string msg = Language.StringByID(R.MyInternationalizationString.uHadBeenLoginAndOffLine);
                    var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
                    contr.Show();
 
                    UserCenterLogic.ReLoginAgain(UserCenterResourse.UserInfo.Account, false);
                });
            }
 
            if (HdlGatewayLogic.Current.IsGatewayExist(gatewayId) == false)
            {
                //不是自己绑定的网关,则不处理
                return;
            }
            //门锁上报
            if (topic == gatewayId + "/Alarms/SendAlarmInform")
            {
                //保存门锁报警信息到本地
                HdlAlarmsLogic.Current.SaveDoorLockAlarmInfo(receiveData);
                
            }
            //通过外部方式布防撤防成功时报告
            else if (topic == gatewayId + "/Security/EnOrWithdrawSucceedReport")
            {
                SecurityEnOrWithdrawSucceedReport(receiveData);
            }
        }
 
        #endregion
 
        #region ■ 通过外部方式布防撤防_______________
 
        /// <summary>
        /// 通过外部方式布防撤防
        /// </summary>
        /// <param name="receiveData">接收的数据</param>
        private static void SecurityEnOrWithdrawSucceedReport(JObject receiveData)
        {
            var data = Newtonsoft.Json.JsonConvert.DeserializeObject<SecurityEnOrWithdrawResult>(receiveData["Data"].ToString());
            if (data.EnOrWithdraw == -1 || data.ModeId == -1 || data.OperationWay == -1)
            {
                return;
            }
            var garrison = GarrisonMode.None;
            if (data.EnOrWithdraw == 0)
            {
                //在家布防
                if (data.ModeId == 1) { garrison = GarrisonMode.AtHome; }
                //离家布防
                else if (data.ModeId == 2) { garrison = GarrisonMode.RemoveHome; }
            }
            else if (data.EnOrWithdraw == 1)
            {
                //撤防
                garrison = GarrisonMode.RemoveGarrison;
            }
            string appendText = string.Empty;
            //自动化
            if (data.OperationWay == 0) { appendText = "(" + Language.StringByID(R.MyInternationalizationString.uLogicOperation) + ")"; }
            //按键操作
            else if (data.OperationWay == 1) { appendText = "(" + Language.StringByID(R.MyInternationalizationString.uPanelOperation) + ")"; }
 
            //保存报警信息然后推送到界面上
            HdlAlarmsLogic.Current.SaveSafeguardAlarmInfo(garrison, appendText, true);
        }
 
        /// <summary>
        /// 通过外部方式布防撤防的接收结果
        /// </summary>
        private class SecurityEnOrWithdrawResult
        {
            /// <summary>
            /// 0:布防成功  1:撤防成功
            /// </summary>
            public int EnOrWithdraw = -1;
            /// <summary>
            /// 安防模式id
            /// </summary>
            public int ModeId = -1;
            /// <summary>
            /// 外部布撤防方式-> 0:执行逻辑动作  1:按键操作
            /// </summary>
            public int OperationWay = -1;
        }
 
        #endregion
    }
}