using System; using System.Collections.Generic; using System.Text; namespace HDL_ON.Stan { //应该也不多,就写在这里了 /// /// 云端推送枚举 /// public enum CloudPushEnum { A新设备上报 = 1, } /// /// 全局接收云端推送的的逻辑(为了执行速度,尽可能的别加耗时的操作) /// public class HdlCloudReceiveLogic { #region ■ 变量声明___________________________ /// /// 全局接收云端推送的的逻辑 /// private static HdlCloudReceiveLogic m_Current = null; /// /// 全局接收云端推送的的逻辑 /// public static HdlCloudReceiveLogic Current { get { if (m_Current == null) { m_Current = new HdlCloudReceiveLogic(); } return m_Current; } } /// /// 云端接收事件集合 /// private List ListCloudEvent = new List(); #endregion #region ■ 全局接收___________________________ /// /// 全局接收云端推送的的逻辑(为了执行速度,尽可能的别加耗时的操作) /// /// 整个主题 /// 接收的数据 public void CloudOverallMsgReceive(string topic, string msgData) { //没有任何监听 if (ListCloudEvent.Count == 0) { return; } //设备入网上报主题(目前只有红外宝) if (topic == DriverLayer.CommunicationTopic.ct.AddDevicePush) { for (int i = 0; i < this.ListCloudEvent.Count; i++) { //回调事件 this.ListCloudEvent[i].CloudReceiveEvent(CloudPushEnum.A新设备上报, msgData); } } } #endregion #region ■ 添加云端监听_______________________ /// /// 添加云端接收事件 /// /// 标识事件的主键(可以随便填,主要是针对多个界面一起使用的情况) /// (参数1:枚举 参数2:推送消息) public void AddCloudReceiveEvent(string i_mainKey, Action action) { try { var eventClass = new CloudReceiveEventClass(); eventClass.MainKey = i_mainKey; eventClass.CloudReceiveEvent = action; this.ListCloudEvent.Add(eventClass); } catch { } } #endregion #region ■ 移除云端监听_______________________ /// /// 移除云端接收事件 /// /// 标识事件的主键(可以随便填,主要是针对多个界面一起使用的情况) 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 ■ 结构体_____________________________ /// /// 云端接收事件类 /// private class CloudReceiveEventClass { /// /// 标识事件的主键(可以随便填,主要是针对多个界面一起使用的情况) /// public string MainKey = string.Empty; /// /// 云端接收事件(参数1:枚举 参数2:推送消息) /// public Action CloudReceiveEvent = null; } #endregion } }