From a4d0a03f3f87fcb5e4485e98a1f7b1a119c26eab Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期三, 28 四月 2021 11:27:55 +0800
Subject: [PATCH] 121-04-28-2

---
 HDL_ON/UI/UI0-Stan/Logic/HdlCloudReceiveLogic.cs |  164 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 164 insertions(+), 0 deletions(-)

diff --git a/HDL_ON/UI/UI0-Stan/Logic/HdlCloudReceiveLogic.cs b/HDL_ON/UI/UI0-Stan/Logic/HdlCloudReceiveLogic.cs
new file mode 100644
index 0000000..81c4959
--- /dev/null
+++ b/HDL_ON/UI/UI0-Stan/Logic/HdlCloudReceiveLogic.cs
@@ -0,0 +1,164 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace HDL_ON.Stan
+{
+    //搴旇涔熶笉澶�,灏卞啓鍦ㄨ繖閲屼簡
+
+    /// <summary>
+    /// 浜戠鎺ㄩ�佹灇涓�
+    /// </summary>
+    public enum CloudPushEnum
+    {
+        A鏂拌澶囦笂鎶� = 1,
+    }
+
+    /// <summary>
+    /// 鍏ㄥ眬鎺ユ敹浜戠鎺ㄩ�佺殑鐨勯�昏緫(涓轰簡鎵ц閫熷害,灏藉彲鑳界殑鍒姞鑰楁椂鐨勬搷浣�)
+    /// </summary>
+    public class HdlCloudReceiveLogic
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        /// <summary>
+        /// 鍏ㄥ眬鎺ユ敹浜戠鎺ㄩ�佺殑鐨勯�昏緫
+        /// </summary>
+        private static HdlCloudReceiveLogic m_Current = null;
+        /// <summary>
+        /// 鍏ㄥ眬鎺ユ敹浜戠鎺ㄩ�佺殑鐨勯�昏緫
+        /// </summary>
+        public static HdlCloudReceiveLogic Current
+        {
+            get
+            {
+                if (m_Current == null)
+                {
+                    m_Current = new HdlCloudReceiveLogic();
+                }
+                return m_Current;
+            }
+        }
+
+        /// <summary>
+        /// 浜戠鎺ユ敹浜嬩欢闆嗗悎
+        /// </summary>
+        private List<CloudReceiveEventClass> ListCloudEvent = new List<CloudReceiveEventClass>();
+
+        #endregion
+
+        #region 鈻� 鍏ㄥ眬鎺ユ敹___________________________
+
+        /// <summary>
+        /// 鐗规畩鍏ㄥ眬鎺ユ敹浜戠鎺ㄩ�佺殑鐨勯�昏緫(涓轰簡鎵ц閫熷害,灏藉彲鑳界殑鍒姞鑰楁椂鐨勬搷浣� true:鎵ц浜嗙壒娈婂鐞� false:娌℃湁鎵ц鐗规畩澶勭悊)
+        /// </summary>
+        /// <param name="topic">鏁翠釜涓婚</param>
+        /// <param name="byteData">鎺ユ敹鐨勬暟鎹�</param>
+        /// <param name="mqttEncryptKey">Mqtt鐨勮В瀵嗗瘑閽�</param>
+        /// <param name="homeIdEncryptKey">浣忓畢鍊掑簭鐨勮В瀵嗗瘑閽�</param>
+        public bool CloudOverallMsgReceiveEx(string topic, byte[] byteData, string mqttEncryptKey, string homeIdEncryptKey)
+        {
+            //璁惧鍏ョ綉涓婃姤涓婚
+            if (topic == $"/user/{Entity.DB_ResidenceData.Instance.CurrentRegion.RegionID}/app/thing/topo/found")
+            {
+                if (string.IsNullOrEmpty(homeIdEncryptKey) == false)
+                {
+                    //瑙e瘑
+                    byteData = Securitys.EncryptionService.AesDecryptPayload(byteData, homeIdEncryptKey);
+                }
+                string msgData = Encoding.UTF8.GetString(byteData);
+                //杩欓噷鐗规畩,鍒�ョ潃杞瓧绗︿覆,鍏堝垽鏂富棰樺啀杞�
+                return this.CloudOverallMsgReceiveEx(topic, msgData);
+            }
+            return false;
+        }
+
+        /// <summary>
+        /// 鐗规畩鍏ㄥ眬鎺ユ敹浜戠鎺ㄩ�佺殑鐨勯�昏緫(涓轰簡鎵ц閫熷害,灏藉彲鑳界殑鍒姞鑰楁椂鐨勬搷浣� true:鎵ц浜嗙壒娈婂鐞� false:娌℃湁鎵ц鐗规畩澶勭悊)
+        /// </summary>
+        /// <param name="topic">鏁翠釜涓婚</param>
+        /// <param name="msgData">鎺ユ敹鐨勬暟鎹�</param>
+        public bool CloudOverallMsgReceiveEx(string topic, string msgData)
+        {
+            //娌℃湁浠讳綍鐩戝惉
+            if (ListCloudEvent.Count == 0) { return false; }
+
+            //璁惧鍏ョ綉涓婃姤涓婚(鐩墠鍙湁绾㈠瀹�)
+            if (topic == $"/user/{Entity.DB_ResidenceData.Instance.CurrentRegion.RegionID}/app/thing/topo/found")
+            {
+                for (int i = 0; i < this.ListCloudEvent.Count; i++)
+                {
+                    //鍥炶皟浜嬩欢
+                    this.ListCloudEvent[i].CloudReceiveEvent(CloudPushEnum.A鏂拌澶囦笂鎶�, msgData);
+                }
+                return true;
+            }
+            return false;
+        }
+
+        #endregion
+
+        #region 鈻� 娣诲姞浜戠鐩戝惉_______________________
+
+        /// <summary>
+        /// 娣诲姞浜戠鎺ユ敹浜嬩欢
+        /// </summary>
+        /// <param name="i_mainKey">鏍囪瘑浜嬩欢鐨勪富閿�(鍙互闅忎究濉�,涓昏鏄拡瀵瑰涓晫闈竴璧蜂娇鐢ㄧ殑鎯呭喌)</param>
+        /// <param name="action">(鍙傛暟1:鏋氫妇 鍙傛暟2:鎺ㄩ�佹秷鎭�)</param>
+        public void AddCloudReceiveEvent(string i_mainKey, Action<CloudPushEnum, string> action)
+        {
+            try
+            {
+                var eventClass = new CloudReceiveEventClass();
+                eventClass.MainKey = i_mainKey;
+                eventClass.CloudReceiveEvent = action;
+                this.ListCloudEvent.Add(eventClass);
+            }
+            catch { }
+        }
+        #endregion
+
+        #region 鈻� 绉婚櫎浜戠鐩戝惉_______________________
+
+        /// <summary>
+        /// 绉婚櫎浜戠鎺ユ敹浜嬩欢
+        /// </summary>
+        /// <param name="i_mainKey">鏍囪瘑浜嬩欢鐨勪富閿�(鍙互闅忎究濉�,涓昏鏄拡瀵瑰涓晫闈竴璧蜂娇鐢ㄧ殑鎯呭喌)</param>
+        public void RemoveCloudReceiveEvent(string i_mainKey)
+        {
+            try
+            {
+                for (int i = 0; i < this.ListCloudEvent.Count; i++)
+                {
+                    if (this.ListCloudEvent[i].MainKey == i_mainKey)
+                    {
+                        this.ListCloudEvent.RemoveAt(i);
+                        i--;
+                    }
+                }
+            }
+            catch { }
+        }
+
+        #endregion
+
+        #region 鈻� 缁撴瀯浣揰____________________________
+
+        /// <summary>
+        /// 浜戠鎺ユ敹浜嬩欢绫�
+        /// </summary>
+        private class CloudReceiveEventClass
+        {
+            /// <summary>
+            /// 鏍囪瘑浜嬩欢鐨勪富閿�(鍙互闅忎究濉�,涓昏鏄拡瀵瑰涓晫闈竴璧蜂娇鐢ㄧ殑鎯呭喌)
+            /// </summary>
+            public string MainKey = string.Empty;
+            /// <summary>
+            /// 浜戠鎺ユ敹浜嬩欢(鍙傛暟1:鏋氫妇 鍙傛暟2:鎺ㄩ�佹秷鎭�)
+            /// </summary>
+            public Action<CloudPushEnum, string> CloudReceiveEvent = null;
+        }
+
+        #endregion
+    }
+}

--
Gitblit v1.8.0