|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace JwKdsV.Core.MessageEvent
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 消息订阅-发布的操作类
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class MsgEvent
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 发送消息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="args">消息体对象</param>
|
|
|
|
|
/// <param name="sender">发送者对象</param>
|
|
|
|
|
public static void Send(MsgEventArgs args , object sender = null)
|
|
|
|
|
{
|
|
|
|
|
MsgEventFactory.EventsContainer.Run(sender , args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 发送消息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="msgType">信道ID</param>
|
|
|
|
|
/// <param name="data">消息数据</param>
|
|
|
|
|
/// <param name="sender">发送者对象</param>
|
|
|
|
|
public static void Send(string msgType , object data , object sender = null)
|
|
|
|
|
{
|
|
|
|
|
MsgEventArgs args = new MsgEventArgs(msgType);
|
|
|
|
|
args.Data = data;
|
|
|
|
|
MsgEventFactory.EventsContainer.Run(sender , args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 订阅消息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="msgType">信道ID</param>
|
|
|
|
|
/// <param name="func">用于处理接收到消息的方法</param>
|
|
|
|
|
/// <param name="receiver">订阅者对象,默认为null</param>
|
|
|
|
|
/// <param name="isOnce">是否接收方法只处理一次,默认为false</param>
|
|
|
|
|
public static void Receive(string msgType , EventHandler<MsgEventArgs> func , object receiver = null , bool isOnce = false)
|
|
|
|
|
{
|
|
|
|
|
MsgEventFactory.EventsContainer.AddListener(msgType , func , receiver , isOnce);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 移除消息的订阅
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="msgType">信道ID</param>
|
|
|
|
|
/// <param name="func">需要移除的接收消息处理方法</param>
|
|
|
|
|
/// <param name="receiver">订阅者对象,默认为null</param>
|
|
|
|
|
public static void RemoveListener(string msgType , EventHandler<MsgEventArgs> func , object receiver = null)
|
|
|
|
|
{
|
|
|
|
|
MsgEventFactory.EventsContainer.RemoveListener(msgType , func , receiver);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|