From d2666457d16f6171785596a8a9cb2fb9fb35f84b Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期五, 16 四月 2021 18:03:54 +0800
Subject: [PATCH] 2021-4-16-1
---
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