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

83 lines
2.0 KiB

3 years ago
using EC.Utils.ZMQ;
using EC.UsingEventAggregator;
using EC.Utils.Config;
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EC.Utils;
namespace ECMonitor.Code
{
public class ZMQManager
{
/// <summary>
/// 通用zmq
/// </summary>
static ZMQHelper _zmqHelper;
public event EventHandler<PubSubModel> OnDataReceived; //定义一个委托类型的事件
public void Start()
{
try
{
string pubserver = ConfigHelper.PUBServer();
string subserver = ConfigHelper.SUBServer();
List<string> topics = SUBTopicList();
_zmqHelper = new ZMQHelper(pubserver, subserver, topics);
_zmqHelper.OnSubData += SubDataReceived;
_zmqHelper.Start();
}catch(Exception ex)
{
FLogger.Error(ex);
}
}
internal static List<string> SUBTopicList()
{
List<string> topicList = new List<string>();
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);
}
}
}