From 74a9ba8e9a2df9c39f9c2eb212a5ac889a055cd4 Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期二, 03 十二月 2019 10:47:51 +0800
Subject: [PATCH] 优化UI细节(请合并最新代码)

---
 ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs |   37 ++++++++++++++++---------------------
 1 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
old mode 100755
new mode 100644
index 8c1ef41..53dfd8c
--- a/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
+++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/ZbGateway.cs
@@ -3177,7 +3177,7 @@
                        .WithTcpServer(brokerName, 1883)
                        .WithKeepAlivePeriod(TimeSpan.FromSeconds(20))
                        .WithCleanSession()
-                        .WithCommunicationTimeout(TimeSpan.FromSeconds(4))
+                        //.WithCommunicationTimeout(TimeSpan.FromSeconds(10))
                        .WithCredentials("", "")
                        .Build();
                                     await localMqttClient.ConnectAsync(options, CancellationToken.None);
@@ -3358,7 +3358,7 @@
                             {
                                 DebugPrintLog($"杩滅▼杩炴帴鏂紑");
                                 await DisConnectRemoteMqttClient("StartRemoteMqtt.DisconnectedHandler");
-                                await StartRemoteMqtt();
+                                //await StartRemoteMqtt();
                             });
                         }
                         if (RemoteMqttClient.ConnectedHandler == null)
@@ -3447,7 +3447,7 @@
            .WithCredentials(connEmqUserName, connEmqPwd)
            .WithKeepAlivePeriod(TimeSpan.FromSeconds(20))
            .WithCleanSession()
-           .WithCommunicationTimeout(TimeSpan.FromSeconds(6))
+           //.WithCommunicationTimeout(TimeSpan.FromSeconds(10))
            .Build();
                                 await DisConnectRemoteMqttClient("StartRemoteMqtt");
                                 await RemoteMqttClient.ConnectAsync(options, CancellationToken.None);
@@ -3601,9 +3601,7 @@
                         //鏂囦欢娴佷笉鐢ㄥ姞瀵�
                         if (topic != "FileTransfer/SendFile")
                         {
-                            topic = ZigBee.Common.SecuritySet.AesEncrypt(System.Text.Encoding.UTF8.GetBytes(topic), Password);
-                            topic = topic.Replace("/", "[[$-MQTT_TILT_SYMBOL_REPLACE-$]]").Replace("+", "[[$-MQTT_PLUS_SYMBOL_REPLACE-$]]");
-                            message = System.Text.Encoding.UTF8.GetBytes(SecuritySet.AesEncrypt(message, password));
+                            message = SecuritySet.AesEncryptBytes(message, password);
                         }
                     }
                     if (localIsConnected)
@@ -3614,6 +3612,7 @@
                         }
                         catch(Exception e)
                         {
+                            DebugPrintLog($"Local涓诲姩鏂紑_{e.Message}");
                             await DisConnectLocalMqttClient(e.Message);
                             await StartLocalMqtt("ReConnect");
                             if (localIsConnected)
@@ -3664,8 +3663,7 @@
         {
             try
             {
-                var topic = e.ApplicationMessage.Topic.TrimStart('/');
-                topic = topic.Replace("[[$-MQTT_TILT_SYMBOL_REPLACE-$]]", "/").Replace("[[$-MQTT_PLUS_SYMBOL_REPLACE-$]]", "+");
+                var topic = e.ApplicationMessage.Topic.TrimStart('/');
                 var payload = e.ApplicationMessage.Payload;
 
                 var message = string.Empty;
@@ -3727,39 +3725,36 @@
         {
             try
             {
-                var topic = e.ApplicationMessage.Topic;
-                topic = topic.Replace("[[$-MQTT_TILT_SYMBOL_REPLACE-$]]", "/").Replace("[[$-MQTT_PLUS_SYMBOL_REPLACE-$]]", "+");
-                var message = System.Text.Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
+                var topic = e.ApplicationMessage.Topic;
+                string payloadString = "";
 
                 if (IsEncry)
                 {
                     //涓婚
-                    topic = Common.SecuritySet.AesDecrypt(System.Text.Encoding.UTF8.GetBytes(topic), Password);
                     //涓嬭浇鐨勫瓧鑺傛祦涓嶉渶瑕佽В瀵�
                     if (topic.Split('/')[0] + "/" + topic.Split('/')[1] == topic.Split('/')[0] + "/" + "FileTransfer")
                     {
                         if (topic.Split('/')[2] != "DownloadFile")
                         {
-                            message = Common.SecuritySet.AesDecrypt(e.ApplicationMessage.Payload, Password);
+                            payloadString = System.Text.Encoding.UTF8.GetString(Common.SecuritySet.AesDecryptBytes(e.ApplicationMessage.Payload, Password));
                         }
                     }
                     else if (topic == topic.Split('/')[0] + "/" + "SendAESKey_Respon") { }//鍥炲涓婚鏄鏂囷紝鏁版嵁鏄槑鏂�
                     else
                     {
-                        message = Common.SecuritySet.AesDecrypt(e.ApplicationMessage.Payload, Password);
+                        payloadString = System.Text.Encoding.UTF8.GetString(Common.SecuritySet.AesDecryptBytes(e.ApplicationMessage.Payload, Password));
                     }
                 }
-
-#if DEBUG
-                DebugPrintLog($"缃戝叧杩斿洖鐨勪富棰�:{topic}_缃戝叧杩斿洖鐨勮礋杞�:{message}_{System.DateTime.Now.ToString()}");
-#endif
-                ReceiveMessage(topic, message, e.ApplicationMessage.Payload);
+                else
+                {
+                    payloadString = System.Text.Encoding.UTF8.GetString(e.ApplicationMessage.Payload);
+                }
+                DebugPrintLog($"缃戝叧杩斿洖鐨勪富棰�:{topic}_缃戝叧杩斿洖鐨勮礋杞�:{payloadString}");
+                ReceiveMessage(topic, payloadString, e.ApplicationMessage.Payload);
             }
             catch (Exception ex)
             {
-#if DEBUG
                 DebugPrintLog($"鎺ユ敹缃戝叧鏁版嵁寮傚父:{ex.Message}");
-#endif
             }
         }
 

--
Gitblit v1.8.0