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.
|
|
|
|
using DSWeb.Common.Model;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using StackExchange.Redis;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace DSWeb.EventBus
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 事件消息处理抽象父类
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract class EventProcessor
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 处理消息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="paraObj"></param>
|
|
|
|
|
public abstract void Process(JObject paraObj);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否可以处理此类型的消息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="type"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public abstract bool CanProcess(EventMessageType type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 时间消息处理器链
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class EventProcessChain
|
|
|
|
|
{
|
|
|
|
|
public static void ProcessEvent(EventMessageType type, JObject paraObj)
|
|
|
|
|
{
|
|
|
|
|
var types = Assembly.GetExecutingAssembly().GetTypes();
|
|
|
|
|
var aType = typeof(EventProcessor);
|
|
|
|
|
foreach (var tp in types)
|
|
|
|
|
{
|
|
|
|
|
if (tp.IsSubclassOf(aType))
|
|
|
|
|
{
|
|
|
|
|
var proc = Activator.CreateInstance(tp) as EventProcessor;
|
|
|
|
|
if (proc.CanProcess(type))
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
proc.Process(paraObj);
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|