WJC
2020-03-12 c47c3ec2488961b3a006aaebcb03dba582f8b19b
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayReceiveLogic.cs
@@ -51,8 +51,8 @@
        /// <param name="gatewayId">网关ID</param>
        /// <param name="topic">整个主题</param>
        /// <param name="reportTopic">上报数据的主题</param>
        /// <param name="receiveData">接收的数据</param>
        public void GatewayOverallMsgReceive(string gatewayId, string topic, string reportTopic, JObject receiveData)
        /// <param name="msgData">接收的数据</param>
        public void GatewayOverallMsgReceive(string gatewayId, string topic, string reportTopic, string msgData)
        {
            if (topic == "AppNoLogin")
            {
@@ -67,7 +67,7 @@
                });
                return;
            }
            else if (topic == "BeingSqueezedOffline")
            else if (topic == "ZigbeeGateWayToClient/" + Common.Config.Instance.ConnEmqClientId + "/Push/NotifySqueeze")
            {
                HdlThreadLogic.Current.RunMain(() =>
                {
@@ -93,6 +93,23 @@
                });
                return;
            }
            else if (topic == "ZigbeeGateWayToClient/" + Common.Config.Instance.Guid + "/Push/Deleted"
                || topic == "ZigbeeGateWayToClient/" + Common.Config.Instance.Guid + "/Push/DeletedShareData")
            {
                if (UserCenterResourse.UserInfo.AuthorityNo == 3)
                {
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        //分享数据已经变更,请重新登陆
                        string msg = Language.StringByID(R.MyInternationalizationString.uShardDataIsChangedPleaseLoginAgain);
                        var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
                        contr.Show();
                        UserCenterLogic.ReLoginAgain(UserCenterResourse.UserInfo.Account, false);
                    });
                }
                return;
            }
            try
            {
                if (HdlGatewayLogic.Current.IsGatewayExist(gatewayId) == false)
@@ -100,52 +117,56 @@
                    //不是自己绑定的网关,则不处理
                    return;
                }
                //设备属性上报
                if (reportTopic == "DeviceStatusReport")
                {
                    //设备属性上报
                    this.DeviceAttributeReportPush(receiveData);
                    this.DeviceAttributeReportPush(JObject.Parse(msgData));
                }
                //传感器上报
                else if (reportTopic == "IASInfoReport")
                {
                    this.SensorDeviceReportPush(receiveData);
                    this.SensorDeviceReportPush(JObject.Parse(msgData));
                }
                //门锁上报
                else if (topic == gatewayId + "/Alarms/SendAlarmInform")
                {
                    this.DoorLockDeviceReportPush(receiveData);
                    this.DoorLockDeviceReportPush(null);
                }
                //通过外部方式布防撤防成功时报告
                else if (topic == gatewayId + "/Security/EnOrWithdrawSucceedReport")
                {
                    this.SecurityEnOrWithdrawSucceedReport(receiveData);
                    this.SecurityEnOrWithdrawSucceedReport(JObject.Parse(msgData));
                }
                //设备在线状态更新反馈
                else if (reportTopic == "OnlineStatusChange_Respon")
                {
                    this.DeviceOnlineChangePush(receiveData);
                    this.DeviceOnlineChangePush(JObject.Parse(msgData));
                }
                //设备控制状态反馈
                else if (reportTopic == "DeviceDefaultAck")
                {
                    this.DeviceControlResponePush(JObject.Parse(msgData));
                }
                //撤防
                else if (topic == gatewayId + "/Security/WithdrawMode_Respon")
                {
                    this.RemoveSafetyGarrisonPush(receiveData);
                    this.RemoveSafetyGarrisonPush(JObject.Parse(msgData));
                }
                //布防
                else if (topic == gatewayId + "/Security/EnableMode_Respon")
                {
                    this.SetSafetyGarrisonPush(receiveData);
                    this.SetSafetyGarrisonPush(JObject.Parse(msgData));
                }
                //逻辑触发上报
                else if (topic == gatewayId + "/Logic/Execute_Respon")
                {
                    this.LogicExecutePush(receiveData);
                    this.LogicExecutePush(null);
                }
                //场景触发上报
                else if (topic == gatewayId + "/Scene/Exec_Respon")
                {
                    this.SceneExecPush(receiveData);
                    this.SceneExecPush(null);
                }
            }
            catch (Exception ex)
@@ -165,6 +186,11 @@
        /// <param name="receiveData"></param>
        private void DeviceAttributeReportPush(JObject receiveData)
        {
            if (this.dicDeviceEvent.Count == 0)
            {
                //没有添加监听
                return;
            }
            var deviceAddr = receiveData.Value<string>("DeviceAddr");
            var deviceEpoint = receiveData.Value<int>("Epoint");
@@ -211,7 +237,7 @@
        private void DoorLockDeviceReportPush(JObject receiveData)
        {
            //保存门锁信息到本地
            HdlAlarmsLogic.Current.SaveDoorLockAlarmInfo(receiveData);
            //HdlAlarmsLogic.Current.SaveDoorLockAlarmInfo(receiveData);
            //显示有新消息的特效
            this.ShowHadNewMessageAppeal();
@@ -227,10 +253,35 @@
        /// <param name="receiveData"></param>
        private void DeviceOnlineChangePush (JObject receiveData)
        {
            if (this.dicDeviceEvent.Count == 0)
            {
                //没有添加监听
                return;
            }
            var tempDevice = new CommonDevice() { DeviceAddr = receiveData.Value<string>("DeviceAddr"), DeviceEpoint = receiveData.Value<int>("Epoint") };
            tempDevice.IsOnline = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(receiveData["Data"]["IsOnline"].ToString());
            tempDevice.IsOnline = Convert.ToInt32(receiveData["Data"]["IsOnline"].ToString());
            
            this.DeviceReportPush(tempDevice, ReceiveComandDiv.A设备在线上报);
        }
        #endregion
        #region ■ 设备控制状态反馈___________________
        /// <summary>
        /// 设备控制状态反馈
        /// </summary>
        /// <param name="receiveData"></param>
        private void DeviceControlResponePush(JObject receiveData)
        {
            if (this.dicDeviceEvent.Count == 0)
            {
                //没有添加监听
                return;
            }
            var tempDevice = new CommonDevice() { DeviceAddr = receiveData.Value<string>("DeviceAddr"), DeviceEpoint = receiveData.Value<int>("Epoint") };
            this.DeviceReportPush(tempDevice, ReceiveComandDiv.A节点控制反馈);
        }
        #endregion
@@ -391,10 +442,12 @@
        #endregion
        #region ■ 添加设备事件_______________________
        /// <summary>
        /// 添加获取设备属性的事件(推送已经强制指定运行于主线程,属性上报的对象:device.DeviceStatusReport)
        /// 添加获取设备属性的事件(属性上报的对象:device.DeviceStatusReport)
        /// </summary>
        /// <param name="mainKeys">标识事件的主键(可以随便填,主要是针对多个界面一起使用的情况)</param>
        /// <param name="comand">命令区分</param>
@@ -470,14 +523,13 @@
        /// <param name="comand"></param>
        private void DeviceReportPush(CommonDevice common, ReceiveComandDiv comand)
        {
            if (this.dicDeviceEvent.Count == 0)
            {
                //没有添加监听
                return;
            }
            lock (this.dicDeviceEvent)
            {
                if (this.dicDeviceEvent.Count == 0)
                {
                    //没有添加监听
                    return;
                }
                var list = new List<Action<CommonDevice>>();
                foreach (string keys in this.dicDeviceEvent.Keys)
                {
@@ -490,23 +542,19 @@
                    list.Add(this.dicDeviceEvent[keys]);
                }
                //有可能在回调函数中移除了事件,导致报错,所以先收集,再调用
                Application.RunOnMainThread(() =>
                foreach (var action in list)
                {
                    foreach (var action in list)
                    try
                    {
                        try
                        {
                            action?.Invoke(common);
                        }
                        catch (Exception ex)
                        {
                            //Log出力
                            string msg = "当前激活的界面[" + UserCenterResourse.NowActionFormID + "]";
                            HdlLogLogic.Current.WriteLog(-1, msg);
                            HdlLogLogic.Current.WriteLog(ex);
                        }
                        action?.Invoke(common);
                    }
                });
                    catch (Exception ex)
                    {
                        //Log出力
                        string msg = "推送错误! 当前激活的界面[" + UserCenterResourse.NowActionFormID + "]";
                        HdlLogLogic.Current.WriteLog(ex, msg);
                    }
                }
            }
        }
@@ -559,6 +607,10 @@
        /// <summary>
        /// 设备在线上报
        /// </summary>
        A设备在线上报 = 3
        A设备在线上报 = 3,
        /// <summary>
        /// 当客户端发送控制设备指令,如打开或关闭设备、调节亮度、颜色。如果被控制的节点设备在线,节点设备将反馈
        /// </summary>
        A节点控制反馈 = 4
    }
}