From 88ce6b0697ccf6ce467545bb1125aefdf5b7130b Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期一, 18 十一月 2019 11:29:04 +0800
Subject: [PATCH] 合并了全部的代码

---
 ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs |   90 +++++++++++++++++++++++++++++++++------------
 1 files changed, 66 insertions(+), 24 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
index 49cb86e..8856f19 100755
--- a/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
+++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
@@ -221,7 +221,6 @@
         /// <para>绗竴涓弬鏁帮細濡傛灉涓� DDevice/IsGetEpointInfo:鏈夋柊璁惧鍔犲叆zigbee缃戠粶鍙嶉</para>璁惧璇锋眰APP鑾峰彇鍗囩骇鏁版嵁
         /// <para>绗竴涓弬鏁帮細濡傛灉涓� Device/DeviceJoinZbNet:鑾峰彇鏂拌澶囨墍鏈夌鐐逛俊鎭槸鍚︽垚鍔熷弽棣�</para>
         /// <para>绗竴涓弬鏁帮細濡傛灉涓� DeviceRequestAcUpdateData: 璁惧璇锋眰绌鸿皟鍙戝崌绾ф暟鎹�</para>
-        /// "宸茬粡閫氱煡");//宸茬粡閫氱煡");
         /// </summary>
         [Newtonsoft.Json.JsonIgnore]
         public Action<string, object> ReportAction;
@@ -3205,6 +3204,9 @@
             {
                 try
                 {
+                    if (!Shared.Common.Config.Instance.IsLogin) {
+                        return;
+                    }
                     if (remoteMqttIsConnecting || Shared.Common.Config.Instance.HomeId == "")
                     {
                         return;
@@ -3317,7 +3319,10 @@
                         DefaultCommunicationTimeout = new TimeSpan(0, 0, 100),//璁剧疆瓒呮椂鏃堕棿
                     };
                     //杩滅▼閫氳杩炴帴锛岃繛鎺ヤ簯绔湇鍔″櫒 
-                    await RemoteMqttClient.ConnectAsync(connectCloudMqttClientOptions);
+                    if (RemoteMqttClient != null)
+                    {
+                        await RemoteMqttClient.ConnectAsync(connectCloudMqttClientOptions);
+                    }
 
                 }
                 catch (Exception ex)
@@ -3385,13 +3390,6 @@
         /// </summary>
         async System.Threading.Tasks.Task SendRemoteMsg(string topicName, byte[] message, MQTTnet.Core.Protocol.MqttQualityOfServiceLevel qosLevel = MQTTnet.Core.Protocol.MqttQualityOfServiceLevel.ExactlyOnce, bool retain = false)
         {
-            //#region MD5鍔犲瘑 token
-            //var result = System.Text.Encoding.UTF8.GetBytes(Shared.Common.Config.Instance.Password);
-            //var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
-            //var output = md5.ComputeHash(result);
-            //var md5Password = BitConverter.ToString(output).Replace("-", "").ToUpper();
-            //#endregion
-
             //(1)鐢熸垚[鐢ㄦ埛鍚�:瀵嗙爜]
             var userNameAndPwdStr = string.Concat(Shared.Common.Config.Instance.Guid, RemoteOperatorConsts.CAP_NUMBER, Shared.Common.Config.Instance.MD5PWD);
             DebugPrintLog($"userNameAndPwdStr锛歿userNameAndPwdStr} ");
@@ -3402,11 +3400,10 @@
             //(3)灏�(2)缁х画鐢熸垚鏍煎紡[Base64(鐢ㄦ埛鍚�:瀵嗙爜):Timestamp]
             var userNameAndPwdStrBaseSexFourAndTimestamp = string.Concat(userNameAndPwdStrBaseSexFour, RemoteOperatorConsts.CAP_NUMBER, CurrentTimeStamp.ToString());
 
-            ///[Zigbee.Buspro]App/id(甯愬彿Id)/Base64(DES[Base64(鐢ㄦ埛鍚�:瀵嗙爜):Timestamp ]/缃戝叧鍞竴Id/杞彂缁欑綉鍏崇殑涓婚/XX/XX
+            //[Zigbee.Buspro]App/id(甯愬彿Id)/Base64(DES[Base64(鐢ㄦ埛鍚�:瀵嗙爜):Timestamp ]/缃戝叧鍞竴Id/杞彂缁欑綉鍏崇殑涓婚/XX/XX
             //(4)鐢熸垚涓婃姤涓婚锛屼富棰樻ā寮忛渶瑕佷负  /ZigbeeApp/id(涓诲瓙璋冭瘯甯愬彿Id)/Base64(DES[Base64(鐢ㄦ埛鍚�:瀵嗙爜):Timestamp ]/缃戝叧鍞竴Id/topicName "000204022022"   GateWayId  000204022022
             var reportTopic = string.Format("/{0}/{1}/{2}/{3}/{4}", RemoteOperatorConsts.ZIGBEE_APP_STARTS_WITH, Shared.Common.Config.Instance.Guid, userNameAndPwdStrBaseSexFourAndTimestamp, this.getGatewayBaseInfo?.gwID, topicName);
             var aa = System.Text.Encoding.UTF8.GetString(message);
-            DebugPrintLog($"AAAA鍙戦�佸埌浜戠涓婚鏄庢枃锛歿reportTopic}___BBBBB鍙戦�佸埌浜戠鍐呭鏄庢枃锛歿aa}");
 
             string topicEncStr = reportTopic;
             //鏂囦欢娴佷笉鐢ㄥ姞瀵�
@@ -3414,7 +3411,6 @@
             topicEncStr = topicEncStr.Replace("/", "[[$-MQTT_TILT_SYMBOL_REPLACE-$]]").Replace("+", "[[$-MQTT_PLUS_SYMBOL_REPLACE-$]]");
             message = System.Text.Encoding.UTF8.GetBytes(SecuritySet.AesEncrypt(message, Shared.Common.Config.Instance.MqttKey));
             var bb = System.Text.Encoding.UTF8.GetString(message);
-            DebugPrintLog($"CCCC鍙戦�佸埌浜戠涓婚绉樻枃锛歿topicEncStr}___DDDD鍙戦�佸埌浜戠鍐呭绉樻枃锛歿bb}");
 
             //(6)鏋勫缓Mqtt闇�瑕佸彂甯冪殑鏁版嵁鍖�,鍙戝竷缁欎簯绔殑MqttBroker
             await RemoteMqttClient.PublishAsync(new MQTTnet.Core.MqttApplicationMessage(topicEncStr, message, qosLevel, retain));
@@ -3529,7 +3525,7 @@
                     //浜戠涓殑褰撳墠杩炴帴琚尋涓嬬嚎锛岄渶瑕侀�氱煡app
                     //鍏ㄥ眬鎺ユ敹缃戝叧鎺ㄩ�佺殑鐨勯�昏緫(涓轰簡鎵ц閫熷害,灏藉彲鑳界殑鍒姞鑰楁椂鐨勬搷浣�)
                     message = "BeingSqueezedOffline";
-                    Shared.Phone.UserCenter.HdlGatewayReceiveLogic.GatewayOverallMsgReceive("", topic, null);
+                    Shared.Phone.UserCenter.HdlGatewayReceiveLogic.Current.GatewayOverallMsgReceive("", topic, "", null);
                     DebugPrintLog($"琚尋涓嬬嚎閫氱煡:{ topic}_杩滅▼杩斿洖鐨勬暟鎹甠{message}_{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")}");//{System.DateTime.Now.ToString()}");// DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")
                     return;
                 }
@@ -3725,7 +3721,7 @@
                 }
 
                 //鍏ㄥ眬鎺ユ敹缃戝叧鎺ㄩ�佺殑鐨勯�昏緫(涓轰簡鎵ц閫熷害,灏藉彲鑳界殑鍒姞鑰楁椂鐨勬搷浣�)
-                Shared.Phone.UserCenter.HdlGatewayReceiveLogic.GatewayOverallMsgReceive(gatewayID, topic, jobject);
+                Shared.Phone.UserCenter.HdlGatewayReceiveLogic.Current.GatewayOverallMsgReceive(gatewayID, topic, reportStatus, jobject);
 
                 #region 浜戠閫氱煡
                 var cloudMqttResult = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Common.CloudMqttResponsePack>(message);
@@ -3740,7 +3736,7 @@
                                 gwa.CloudErrorAction("AppNoLogin", "鐧诲綍杩囨湡锛岃閲嶆柊鐧诲綍");
                             }
                             //鍏ㄥ眬鎺ユ敹缃戝叧鎺ㄩ�佺殑鐨勯�昏緫(涓轰簡鎵ц閫熷害,灏藉彲鑳界殑鍒姞鑰楁椂鐨勬搷浣�)
-                            Shared.Phone.UserCenter.HdlGatewayReceiveLogic.GatewayOverallMsgReceive(gatewayID, "AppNoLogin", jobject);
+                            Shared.Phone.UserCenter.HdlGatewayReceiveLogic.Current.GatewayOverallMsgReceive(gatewayID, "AppNoLogin", reportStatus, jobject);
                             break;
                         case "AppTimeOut":
                             if (gwa.CloudErrorAction != null)
@@ -3768,17 +3764,15 @@
                         if (gwData != null)
                         {
                             var gwList = GateWayList.FindAll(obj => obj.getGatewayBaseInfo.HomeId == Shared.Common.Config.Instance.HomeId);
-
                             for (int i = 0; i < gwList.Count; i++)
                             {
-                                var gwTemp = gwList[i];
-                                if (gwData.IsDominant == 1)
-                                {
-                                    gwTemp.getGatewayBaseInfo.IsMainGateWay = true;
-                                    for (int j = i + 1; j < gwList.Count; j++)
-                                    {
-                                        gwList[j].getGatewayBaseInfo.IsMainGateWay = false;
-                                    }
+                                if (gwList[i].getGatewayBaseInfo.gwID == gatewayID)
+                                {
+                                    gwList[i].getGatewayBaseInfo.IsMainGateWay = true;
+                                }
+                                else
+                                {
+                                    gwList[i].getGatewayBaseInfo.IsMainGateWay = false;
                                 }
                             }
                         }
@@ -3919,6 +3913,54 @@
                     UpdateDeviceInfo(tempDevice, "DeviceStatusReport");
                 }
                 #endregion
+                #region 闂ㄩ攣鎿嶄綔浜嬩欢閫氱煡
+                else if (topic == gatewayID + "/" + "DoorLock/DoorLockOperatingEventNotificationCommand")
+                {
+                    var deviceID = jobject.Value<int>("Device_ID");
+                    switch ((DeviceType)(deviceID))
+                    {
+                        case DeviceType.DoorLock:
+                            var doorLock = new DoorLock() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
+                            var OperatingEventNotificationDatad = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Device.DoorLock.DoorLockOperatingEventNotificationCommand>(jobject["Data"].ToString());
+                            if (OperatingEventNotificationDatad != null)
+                            {
+                                doorLock.doorLockOperatingEventNotificationCommand = OperatingEventNotificationDatad;
+                            }
+                            if (gwa.ReportAction != null)
+                            {
+                                DebugPrintLog("DoorLockProgrammingEventNotificationCommand宸茬粡閫氱煡");
+                                gwa.ReportAction("DoorLockProgrammingEventNotificationCommand", doorLock);
+                            }
+                            UpdateDeviceStatus(doorLock);
+                            UpdateDeviceInfo(doorLock, "DoorLockProgrammingEventNotificationCommand");
+                            break;
+                    }
+                }
+                #endregion
+                #region 闂ㄩ攣缂栫▼浜嬩欢閫氱煡
+                else if (topic == gatewayID + "/" + "DoorLock/DoorLockProgrammingEventNotificationCommand")
+                {
+                    var deviceID = jobject.Value<int>("Device_ID");
+                    switch ((DeviceType)(deviceID))
+                    {
+                        case DeviceType.DoorLock:
+                            var doorLock = new DoorLock() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = gwa.getGatewayBaseInfo.gwID };
+                            var ProgrammingEventNotificationData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Device.DoorLock.DoorLockProgrammingEventNotificationCommand>(jobject["Data"].ToString());
+                            if (ProgrammingEventNotificationData != null)
+                            {
+                                doorLock.doorLockProgrammingEventNotificationCommand = ProgrammingEventNotificationData;
+                            }
+                            if (gwa.ReportAction != null)
+                            {
+                                DebugPrintLog("DoorLockProgrammingEventNotificationCommand宸茬粡閫氱煡");
+                                gwa.ReportAction("DoorLockProgrammingEventNotificationCommand", doorLock);
+                            }
+                            UpdateDeviceStatus(doorLock);
+                            UpdateDeviceInfo(doorLock, "DoorLockProgrammingEventNotificationCommand");
+                            break;
+                    }
+                }
+                #endregion
                 #region IAS瀹夐槻淇℃伅涓婃姤
                 else if (topic == gatewayID + "/" + "IASInfoReport")
                 {

--
Gitblit v1.8.0