Browse Source

2023年6月18日15:30:49

master
fajiao 2 years ago
parent
commit
4e35f91c67
  1. 2
      ECMonitor/ECMonitor.csproj
  2. 45
      ECMonitor/Manager/WebSocketManager.cs
  3. 37
      ECMonitor/Manager/ZMQManager.cs
  4. 30
      ECMonitor/appsettings.json

2
ECMonitor/ECMonitor.csproj

@ -152,7 +152,7 @@
</Target> </Target>
<ProjectExtensions><VisualStudio><UserProperties /></VisualStudio></ProjectExtensions> <ProjectExtensions><VisualStudio><UserProperties appsettings_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent"> <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="Copy $(ProjectDir)appsettings.json $(OutDir)appsettings.json" /> <Exec Command="Copy $(ProjectDir)appsettings.json $(OutDir)appsettings.json" />

45
ECMonitor/Manager/WebSocketManager.cs

@ -1,41 +1,33 @@
 using EC.Utils;
using EC.Utils.ZMQ; using EC.Utils.ZMQ;
using Fleck;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EC.Utils;
using Fleck;
namespace ECMonitor.Manager namespace ECMonitor.Manager
{ {
public class WebSocketManager public class WebSocketManager
{ {
WebSocketServer _webSocketServer = null; private WebSocketServer _webSocketServer = null;
List<IWebSocketConnection> allSockets = new List<IWebSocketConnection>(); private List<IWebSocketConnection> allSockets = new List<IWebSocketConnection>();
public event EventHandler<PubSubModel> OnDataReceived; //定义一个委托类型的事件
public WebSocketManager( ) public event EventHandler<PubSubModel> OnDataReceived; //定义一个委托类型的事件
public WebSocketManager()
{ {
FleckLog.Level = LogLevel.Debug; FleckLog.Level = LogLevel.Debug;
_webSocketServer = new WebSocketServer("ws://0.0.0.0:"+ ConfigHelper.WebSocketSvrPort()); _webSocketServer = new WebSocketServer("ws://0.0.0.0:" + ConfigHelper.WebSocketSvrPort());
} }
public void Start() public void Start()
{ {
_webSocketServer.Start(socket => _webSocketServer.Start(socket =>
{ {
socket.OnOpen = () => socket.OnOpen = () =>
{ {
// Console.WriteLine("Open!"); // Console.WriteLine("Open!");
allSockets.Add(socket); allSockets.Add(socket);
}; };
socket.OnClose = () => socket.OnClose = () =>
@ -47,16 +39,17 @@ namespace ECMonitor.Manager
{ {
//Console.WriteLine(message); //Console.WriteLine(message);
// allSockets.ToList().ForEach(s => s.Send("Echo: " + message)); // allSockets.ToList().ForEach(s => s.Send("Echo: " + message));
WebSocketDataReceived(socket,message); WebSocketDataReceived(socket, message);
}; };
}); });
} }
public void Stop() public void Stop()
{ {
allSockets.ToList().ForEach(s => s.Close()); allSockets.ToList().ForEach(s => s.Close());
_webSocketServer.Dispose(); _webSocketServer.Dispose();
} }
private void WebSocketDataReceived(object sender, string message) private void WebSocketDataReceived(object sender, string message)
{ {
try try
@ -70,12 +63,10 @@ namespace ECMonitor.Manager
} }
} }
} }
catch(Exception ex) { catch (Exception ex)
{
LogFactory.GetLogger().Error(ex); LogFactory.GetLogger().Error(ex);
} }
} }
} }
} }

37
ECMonitor/Manager/ZMQManager.cs

@ -1,14 +1,8 @@
using EC.Utils.ZMQ; using EC.UsingEventAggregator;
using EC.UsingEventAggregator; using EC.Utils;
using EC.Utils.Config; using EC.Utils.ZMQ;
using Prism.Events;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EC.Utils;
namespace ECMonitor.Code namespace ECMonitor.Code
{ {
@ -17,11 +11,10 @@ namespace ECMonitor.Code
/// <summary> /// <summary>
/// 通用zmq /// 通用zmq
/// </summary> /// </summary>
static ZMQHelper _zmqHelper; private static ZMQHelper _zmqHelper;
public event EventHandler<PubSubModel> OnDataReceived; //定义一个委托类型的事件
public event EventHandler<PubSubModel> OnDataReceived; //定义一个委托类型的事件
public void Start() public void Start()
{ {
try try
@ -33,14 +26,11 @@ namespace ECMonitor.Code
_zmqHelper = new ZMQHelper(pubserver, subserver, topics); _zmqHelper = new ZMQHelper(pubserver, subserver, topics);
_zmqHelper.OnSubData += SubDataReceived; _zmqHelper.OnSubData += SubDataReceived;
_zmqHelper.Start(); _zmqHelper.Start();
}catch(Exception ex) }
catch (Exception ex)
{ {
FLogger.Error(ex); FLogger.Error(ex);
} }
} }
internal static List<string> SUBTopicList() internal static List<string> SUBTopicList()
@ -52,15 +42,15 @@ namespace ECMonitor.Code
topicList.Add(ZMQTopic.MainFrom_Show_Video); topicList.Add(ZMQTopic.MainFrom_Show_Video);
topicList.Add(ZMQTopic.AI_Detect_Warning_Data); topicList.Add(ZMQTopic.AI_Detect_Warning_Data);
return topicList; return topicList;
} }
public void Stop() public void Stop()
{ {
_zmqHelper?.Stop(); _zmqHelper?.Stop();
} }
private void SubDataReceived(object sender, PubSubModel msgModel) private void SubDataReceived(object sender, PubSubModel msgModel)
{ {
try try
@ -71,12 +61,11 @@ namespace ECMonitor.Code
{ {
LogFactory.GetLogger().Error(ex); LogFactory.GetLogger().Error(ex);
} }
} }
public void Send(string topic, string msg) public void Send(string topic, string msg)
{ {
_zmqHelper.Send( topic, msg); _zmqHelper.Send(topic, msg);
} }
} }
} }

30
ECMonitor/appsettings.json

@ -1,29 +1,29 @@
{ {
"EC_App": { "EC_App": {
//================== ====================================== --> //================== ϵͳҪ ====================================== -->
// //ͻ˱ Ψһݱʶ
"AppId": "Video001", "AppId": "Video001",
// //
"SoftName": "YDFK", "SoftName": "YDFK",
// //ȫ
"SoftFullName": "要地防控系统-视频监控", "SoftFullName": "Ҫ�ط���ϵͳ-��Ƶ���",
// //
"SoftVersion": "V1.0.0", "SoftVersion": "V1.0.0",
// //ԶرԤ
"AutoWarningClose": 1,// "AutoWarningClose": 1,//ԤԶر
"VideoAIDetection": 0, //AI "VideoAIDetection": 0, //ƵAI
"WebSocketSvrPort": 5003, "WebSocketSvrPort": 5003,
"APIServer": "http://192.168.1.200:8080/military/videoRecorder/qryCameraList", "APIServer": "http://192.168.1.200:8080/military/videoRecorder/qryCameraList",
"MainBarButtonSelectedIndex": 1, // 01,14, 29 "MainBarButtonSelectedIndex": 1, // ѡʼͼ 01,14, 29
"AIInputPath": "F:/TestImage/imgs/", "AIInputPath": "F:/TestImage/imgs/",
"AIOutPath": "F:/TestImage/outs/" "AIOutPath": "F:/TestImage/outs/"
}, },
"ZMQ": { "ZMQ": {
"SUBServer": "tcp://192.168.1.182:5000", //ZMQ SUB "SUBServer": "tcp://192.168.1.182:5000", //ͨZMQ SUBϢĵַ
"PUBServer": "tcp://192.168.1.182:5001", //ZMQ PUB "PUBServer": "tcp://192.168.1.182:5001", //ͨZMQ PUB Ϣַ
"AISvrServer": "tcp://127.0.0.1:5002", // AI byte[] ZMQ REQ-> REP "AISvrServer": "tcp://127.0.0.1:5002", // ҪAI ͼƬbyte[] ZMQ REQ-> REP ַ
"SUBImageServer": "tcp://192.168.1.182:5000", //SUB byte[] "SUBImageServer": "tcp://192.168.1.182:5000", //SUB ͼƬ byte[] ĵַ ֿԭ ͼƬ
"DBSvrServer": "tcp://127.0.0.1:5010", // ZMQ REQ-> REP "DBSvrServer": "tcp://127.0.0.1:5010", // ݿӿ ZMQ REQ-> REP ַ
"SUBTopic": "Topic,A", "SUBTopic": "Topic,A",
"Top": "Topic,A" "Top": "Topic,A"
}, },

Loading…
Cancel
Save