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