From 94e4e5b9fd3da964c44b7b14227d6fe2bbb426d7 Mon Sep 17 00:00:00 2001
From: WJC <wjc@hdlchina.com.cn>
Date: 星期四, 02 四月 2020 13:56:39 +0800
Subject: [PATCH] 2020-04-02-2

---
 ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs |  147 ++++++++++++++++++++++++------------------------
 1 files changed, 74 insertions(+), 73 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
index 0b5fc0d..990a261 100755
--- a/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
+++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
@@ -162,12 +162,6 @@
         public List<Scene.GetSceneDeviceListInfo> SceneDeviceList = new List<Scene.GetSceneDeviceListInfo>();
 
         /// <summary>
-        /// 缃戝叧涓�昏緫鍒楄〃
-        /// </summary>
-        [Newtonsoft.Json.JsonIgnore]
-        public static List<Logic.GetLogicInfoResponseData> LogicList = new List<Logic.GetLogicInfoResponseData>();
-
-        /// <summary>
         /// 缃戝叧涓環dl绉佹湁鎸夐敭缁戝畾鍒楄〃
         /// </summary>
         [Newtonsoft.Json.JsonIgnore]
@@ -3054,22 +3048,6 @@
         public static readonly System.Collections.Generic.List<IStatus> StatusList = new System.Collections.Generic.List<IStatus>();
 
         /// <summary>
-        /// 璁惧鐘舵�佹洿鏂�
-        /// </summary>
-        /// <param name="commonDevice">Common device.</param>
-        public static void UpdateDeviceStatus(CommonDevice commonDevice)
-        {
-            if (commonDevice == null)
-            {
-                return;
-            }
-            for (int i = 0; i < StatusList.Count; i++)
-            {
-                StatusList[i].Changed(commonDevice);
-            }
-        }
-
-        /// <summary>
         /// 璁惧淇℃伅鍙樺寲
         /// <para>type锛氬鏋滀负 DeviceInComingRespon:璁惧鏂颁笂鎶�</para>
         /// <para>type锛氬鏋滀负 IASInfoReport:RemoveDeviceRespon</para>
@@ -3362,7 +3340,21 @@
                             {
                                 if (!RemoteMqttClient.IsConnected || !IsRemote)
                                 {
-                                    return;
+                                    if (e.ApplicationMessage.Topic != "/ZigbeeGateWayToClient/" + Config.Instance.ConnEmqClientId + "/Push/NotifySqueeze")
+                                    {
+                                        return;
+                                    }
+                                }
+                                //濡傛灉褰撳墠浣跨敤鐨勬槸鍐呯綉妯″紡
+                                if (IsRemote == false)
+                                {
+                                    if (e.ApplicationMessage.Topic == "/ZigbeeGateWayToClient/" + Config.Instance.ConnEmqClientId + "/Push/NotifySqueeze"//韪汉涓嬬嚎
+                                      || e.ApplicationMessage.Topic == "/ZigbeeGateWayToClient/" + Config.Instance.Guid + "/Push/Deleted"//鍒嗕韩鍒犻櫎
+                                      || e.ApplicationMessage.Topic == "/ZigbeeGateWayToClient/" + Config.Instance.Guid + "/Push/DeletedShareData")
+                                    {
+                                        mqttRemoteClient_MqttMsgPublishReceived(e);
+                                    }
+                                    return;
                                 }
                                 mqttRemoteClient_MqttMsgPublishReceived(e);
                             });
@@ -3382,6 +3374,18 @@
                             RemoteMqttClient.UseConnectedHandler(async (e) =>
                             {
                                 DebugPrintLog($"杩滅▼杩炴帴鎴愬姛");
+
+                                if (Config.Instance.Home.IsOthreShare == true)
+                                {
+                                    //璁㈤槄涓�涓垚鍛樿鍒犻櫎鐨勪富棰�
+                                    string myGuid = Config.Instance.Guid;
+                                    await RemoteMqttClient.SubscribeAsync("/ZigbeeGateWayToClient/" + myGuid + "/Push/Deleted");
+                                    //璁㈤槄涓�涓垎浜暟鎹凡缁忓彉鏇寸殑涓婚
+                                    await RemoteMqttClient.SubscribeAsync("/ZigbeeGateWayToClient/" + myGuid + "/Push/DeletedShareData");
+                                }
+                                //璁㈤槄涓�涓尋涓嬬嚎鐨勪富棰�
+                                await RemoteMqttClient.SubscribeAsync("/ZigbeeGateWayToClient/" + Config.Instance.ConnEmqClientId + "/Push/NotifySqueeze");
+
                                 await initGateWayBaseInfomation();
                                 Shared.Phone.UserCenter.HdlGatewayLogic.Current.CheckGatewayByConnectChanged(Shared.Phone.UserCenter.GatewayConnectMode.Remote);
                                 //娌℃湁涓荤綉鍏虫椂涓诲姩璇诲彇锛岃幏鍙栦富缃戝叧淇℃伅
@@ -3436,7 +3440,9 @@
                                 ["RequestVersion"] = CommonPage.RequestVersion,
                                 ["RequestSource"] = 0,
                                 ["LoginAccessToken"] = Config.Instance.Token,
-                                ["RequestProtocolType"] = 0
+                                ["RequestProtocolType"] = 0,
+                                ["PlatformStr"] = "h",//杩欎袱涓�煎鏋滀笉璁剧疆,鍒欎簯绔笉鍙戝竷涓婚
+                                ["PublishPayloadJsonStr"] = "1"
                             };
                             var bytes = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(jsonData));
                             result = await CommonPage.Instance.DoRequestZigbeeHttpsInterface("https://global.hdlcontrol.com/HangZhouHdlCloudApi/EmqMqtt/GetConnMqttInfo", bytes, Config.Instance.Token);
@@ -3451,7 +3457,9 @@
                                 ["LoginAccessToken"] = Config.Instance.Token,
                                 ["RequestProtocolType"] = 0,
                                 ["MainUserDistributedMark"] = Config.Instance.Home.MainUserDistributedMark,
-                                ["HomeId"] = Config.Instance.Home.Id
+                                ["HomeId"] = Config.Instance.Home.Id,
+                                ["PlatformStr"] = "h",//杩欎袱涓�煎鏋滀笉璁剧疆,鍒欎簯绔笉鍙戝竷涓婚
+                                ["PublishPayloadJsonStr"] = "1"
                             };
                             var bytes = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(jsonData));
                             result = await CommonPage.Instance.DoRequestZigbeeHttpsInterface("https://global.hdlcontrol.com/HangZhouHdlCloudApi/EmqMqtt/ShareMemberConnMqttInfo", bytes, Config.Instance.Token);
@@ -3465,6 +3473,9 @@
                                 AllowRemoteCtrl = false;
                                 return;
                             }
+                            //铏界劧涓嶇煡閬撳鎸や笅绾块偅涓�鍧楁湁娌℃湁鐢�,涓嶈繃鍏堣繖涔堝紕
+                            await System.Threading.Tasks.Task.Delay(1500);
+
                             var responseData = jobject["ResponseData"];
                             if (responseData != null)
                             {
@@ -3472,6 +3483,8 @@
                                 var connEmqClientId = responseData["ConnEmqClientId"]?.ToString();
                                 var connEmqUserName = responseData["ConnEmqUserName"]?.ToString();
                                 var connEmqPwd = responseData["ConnEmqPwd"]?.ToString();
+                                //璁板綍璧峰綋鍓嶇殑瀹㈡埛绔疘D
+                                Config.Instance.ConnEmqClientId = connEmqClientId;
 
                                 var connEmqDomainPorts = connEmqDomainPort.Replace("//", "").Split(':');
                                 var domain = connEmqDomainPorts[1];
@@ -3874,7 +3887,10 @@
                     epoint = topic.Split('/')[3];
                     cluID = topic.Split('/')[4];
                     attrId = topic.Split('/')[5];
-                }
+                }
+
+                //鍏ㄥ眬鎺ユ敹缃戝叧鎺ㄩ�佺殑鐨勯�昏緫(涓轰簡鎵ц閫熷害,灏藉彲鑳界殑鍒姞鑰楁椂鐨勬搷浣�)
+                Shared.Phone.UserCenter.HdlGatewayReceiveLogic.Current.GatewayOverallMsgReceive(gatewayID, topic, reportStatus, message);
 
                 var gwa = GateWayList.Find(obj => obj.getGatewayBaseInfo.gwID == gatewayID);
                 if (gwa == null)
@@ -3906,9 +3922,6 @@
                 {
                     jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
                 }
-
-                //鍏ㄥ眬鎺ユ敹缃戝叧鎺ㄩ�佺殑鐨勯�昏緫(涓轰簡鎵ц閫熷害,灏藉彲鑳界殑鍒姞鑰楁椂鐨勬搷浣�)
-                Shared.Phone.UserCenter.HdlGatewayReceiveLogic.Current.GatewayOverallMsgReceive(gatewayID, topic, reportStatus, jobject);
 
                 #region 杩滅▼,涓荤綉鍏充笂鎶ラ�氱煡
                 if (IsRemote)
@@ -3981,8 +3994,7 @@
                         DebugPrintLog("DeviceInComingRespon宸茬粡閫氱煡");
                         gwa.ReportAction("DeviceInComingRespon", tempDevice.getNewDeviceInfo);
                     }
-                    UpdateDeviceInfo(tempDevice, "DeviceInComingRespon");
-                    UpdateDeviceStatus(gwa);
+                    UpdateDeviceInfo(tempDevice, "DeviceInComingRespon");
                 }
                 #endregion
                 #region 璁惧鍦ㄧ嚎鐘舵�佹洿鏂板弽棣�
@@ -4000,7 +4012,6 @@
                     if (infoTempDevice == null)
                     {
                         gwa.DeviceList.Add(tempDevice);
-                        UpdateDeviceStatus(tempDevice);
                         UpdateDeviceInfo(tempDevice, "OnlineStatusChange");
                     }
                     else
@@ -4010,7 +4021,6 @@
                             infoTempDevice.DeviceInfo.IsOnline = infoTempDevice.IsOnline;
                         }
                         UpdateDeviceInfo(infoTempDevice, "OnlineStatusChange");
-                        UpdateDeviceStatus(infoTempDevice);
                     }
                 }
                 #endregion
@@ -4036,7 +4046,6 @@
                                     }
                                     else
                                     {
-                                        UpdateDeviceStatus(tempDevice);
                                         UpdateDeviceInfo(tempDevice, "RemoveDeviceRespon");
                                         if (tempDevice.removeDeviceResponseData.Result == 0)
                                         {
@@ -4064,7 +4073,6 @@
 
                     var tempDevice = new CommonDevice { DeviceID = deviceID, DeviceAddr = deviceAddr, DeviceEpoint = tempEpoint, DataID = dataId };
                     tempDevice.DeviceStatusReport = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceStatusReportData>(jobject["Data"].ToString());
-                    UpdateDeviceStatus(tempDevice);
                     UpdateDeviceInfo(tempDevice, "DeviceStatusReport");
                 }
                 #endregion
@@ -4086,7 +4094,6 @@
                                 DebugPrintLog("DoorLockProgrammingEventNotificationCommand宸茬粡閫氱煡");
                                 gwa.ReportAction("DoorLockProgrammingEventNotificationCommand", doorLock);
                             }
-                            UpdateDeviceStatus(doorLock);
                             UpdateDeviceInfo(doorLock, "DoorLockProgrammingEventNotificationCommand");
                             break;
                     }
@@ -4110,7 +4117,6 @@
                                 DebugPrintLog("DoorLockProgrammingEventNotificationCommand宸茬粡閫氱煡");
                                 gwa.ReportAction("DoorLockProgrammingEventNotificationCommand", doorLock);
                             }
-                            UpdateDeviceStatus(doorLock);
                             UpdateDeviceInfo(doorLock, "DoorLockProgrammingEventNotificationCommand");
                             break;
                     }
@@ -4132,8 +4138,6 @@
                                 //ias.Save();
                                 gwa.ReportAction("IASInfoReport", ias.iASInfo);
                             }
-
-                            UpdateDeviceStatus(ias);
                             UpdateDeviceInfo(ias, "IASInfoReport");
                             break;
                     }
@@ -4248,37 +4252,37 @@
                 #region 閫昏緫琚皟鐢ㄥ弽棣�
                 else if (topic == gatewayID + "/" + "Logic/Execute_Respon")
                 {
-                    var logic = new Logic() { DataID = jobject.Value<int>("Data_ID"), GateWayId = gwa.getGatewayBaseInfo.gwID };
-                    logic.logicExecuteRespo = Newtonsoft.Json.JsonConvert.DeserializeObject<Logic.ExecuteResponse>(jobject["Data"].ToString());
+                    //var logic = new Logic() { DataID = jobject.Value<int>("Data_ID"), GateWayId = gwa.getGatewayBaseInfo.gwID };
+                    //logic.logicExecuteRespo = Newtonsoft.Json.JsonConvert.DeserializeObject<Logic.ExecuteResponse>(jobject["Data"].ToString());
 
-                    if (logic.logicExecuteRespo == null)
-                    {
-                        return;
-                    }
-                    //涓婃姤绫诲瀷閫氱煡
-                    if (gwa.ReportAction != null)
-                    {
-                        DebugPrintLog("LogicExecuteReport宸茬粡閫氱煡");
-                        gwa.ReportAction("LogicExecuteReport", logic.logicExecuteRespo);
-                    }
+                    //if (logic.logicExecuteRespo == null)
+                    //{
+                    //    return;
+                    //}
+                    ////涓婃姤绫诲瀷閫氱煡
+                    //if (gwa.ReportAction != null)
+                    //{
+                    //    DebugPrintLog("LogicExecuteReport宸茬粡閫氱煡");
+                    //    gwa.ReportAction("LogicExecuteReport", logic.logicExecuteRespo);
+                    //}
                 }
                 #endregion
                 #region 鏃堕棿鐐规潯浠舵帹杩熸墽琛�
                 else if (topic == gatewayID + "/" + "Logic/TimingWillArrive")
                 {
-                    var logic = new Logic() { DataID = jobject.Value<int>("Data_ID"), GateWayId = gwa.getGatewayBaseInfo.gwID };
-                    logic.timingWillArriveData = Newtonsoft.Json.JsonConvert.DeserializeObject<Logic.TimingWillArriveData>(jobject["Data"].ToString());
+                    //var logic = new Logic() { DataID = jobject.Value<int>("Data_ID"), GateWayId = gwa.getGatewayBaseInfo.gwID };
+                    //logic.timingWillArriveData = Newtonsoft.Json.JsonConvert.DeserializeObject<Logic.TimingWillArriveData>(jobject["Data"].ToString());
 
-                    if (logic.timingWillArriveData == null)
-                    {
-                        return;
-                    }
-                    //涓婃姤绫诲瀷閫氱煡
-                    if (gwa.ReportAction != null)
-                    {
-                        DebugPrintLog("TimingWillArrive宸茬粡閫氱煡");
-                        gwa.ReportAction("TimingWillArrive", logic.timingWillArriveData);
-                    }
+                    //if (logic.timingWillArriveData == null)
+                    //{
+                    //    return;
+                    //}
+                    ////涓婃姤绫诲瀷閫氱煡
+                    //if (gwa.ReportAction != null)
+                    //{
+                    //    DebugPrintLog("TimingWillArrive宸茬粡閫氱煡");
+                    //    gwa.ReportAction("TimingWillArrive", logic.timingWillArriveData);
+                    //}
                 }
                 #endregion
                 #region 妯″紡瀹夐槻鍔ㄤ綔琚渶缁堟縺娲绘椂鍙戦�佹姤璀︿俊鎭�
@@ -4352,18 +4356,15 @@
                 #region 璁惧璇锋眰APP鑾峰彇鍗囩骇鏁版嵁
                 else if (topic == gatewayID + "/" + "ZbDataPassthrough")
                 {
-                    var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
-                    gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
-                    if (gatewayTemp.clientDataPassthroughResponseData == null)
-                    {
-                        return;
-                    }
-
                     //涓婃姤绫诲瀷閫氱煡
                     if (gwa.ReportAction != null)
-                    {
-                        DebugPrintLog("DeviceRequestAcUpdateData");
-                        gwa.ReportAction("DeviceRequestAcUpdateData", gatewayTemp.clientDataPassthroughResponseData);
+                    {
+                        var clientDataPassthrough = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
+                        if (clientDataPassthrough != null)
+                        {
+                            DebugPrintLog("DeviceRequestAcUpdateData");
+                            gwa.ReportAction("DeviceRequestAcUpdateData", clientDataPassthrough);
+                        }
                     }
                 }
                 #endregion

--
Gitblit v1.8.0