You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.1 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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);
}
}
}