using EC.UsingEventAggregator;
using EC.Utils;
using EC.Utils.ZMQ;
using System;
using System.Collections.Generic;
namespace ECMonitor.Code
{
public class ZMQManager
{
///
/// 通用zmq
///
private static ZMQHelper _zmqHelper;
public event EventHandler OnDataReceived; //定义一个委托类型的事件
public void Start()
{
try
{
string pubserver = ConfigHelper.PUBServer();
string subserver = ConfigHelper.SUBServer();
List topics = SUBTopicList();
_zmqHelper = new ZMQHelper(pubserver, subserver, topics);
_zmqHelper.OnSubData += SubDataReceived;
_zmqHelper.Start();
}
catch (Exception ex)
{
FLogger.Error(ex);
}
}
internal static List SUBTopicList()
{
List topicList = new List();
topicList.Add("Topic");
topicList.Add(ZMQTopic.Show_Single_Video + ConfigHelper.AppId);
topicList.Add(ZMQTopic.MainFrom_Show_Video + ConfigHelper.AppId);
topicList.Add(ZMQTopic.MainFrom_Show_Video);
topicList.Add(ZMQTopic.AI_Detect_Warning_Data);
return topicList;
}
public void Stop()
{
_zmqHelper?.Stop();
}
private void SubDataReceived(object sender, PubSubModel msgModel)
{
try
{
OnDataReceived?.Invoke(sender, msgModel);
}
catch (Exception ex)
{
LogFactory.GetLogger().Error(ex);
}
}
public void Send(string topic, string msg)
{
_zmqHelper.Send(topic, msg);
}
}
}