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
{
///
/// 事件消息处理抽象父类
///
public abstract class EventProcessor
{
///
/// 处理消息
///
///
public abstract void Process(JObject paraObj);
///
/// 是否可以处理此类型的消息
///
///
///
public abstract bool CanProcess(EventMessageType type);
}
///
/// 时间消息处理器链
///
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;
}
}
}
}
}
}