using Cis.Application.Cb; using Cis.Application.Cm; using Cis.Application.Tb; using System.Collections.Concurrent; namespace Cis.Application.Core; public class CameraDataCenter { #region Attr private readonly SqlSugarRepository _cbCameraRep; private readonly SqlSugarRepository _cmMarkLableRep; private readonly SqlSugarRepository _tbPtzCameraRep; private readonly PtzServerApi _ptzServerApi; private Thread _thread { get; set; } private List _tbPtzCameraList { get; set; } private ConcurrentDictionary _cameraPtzInfoDict { get; set; } #endregion Attr public CameraDataCenter() { _cbCameraRep = App.GetService>(); _cmMarkLableRep = App.GetService>(); _tbPtzCameraRep = App.GetService>(); _ptzServerApi = App.GetService(); Init(); } private void Init() { // 初始化 tbPtzCameraList _tbPtzCameraList = _tbPtzCameraRep.GetList(); // 根据 Ip 去重 _tbPtzCameraList = _tbPtzCameraList.Where((a, i) => _tbPtzCameraList.FindIndex(b => b.Ip == a.Ip) == i).ToList(); // 初始化 ptzInfoDict _cameraPtzInfoDict = new ConcurrentDictionary(); // 初始化 thread _thread = new Thread(WorkLoop) { IsBackground = true// 设置后台线程 }; _thread.Start(); } private void LazyInit() { // 初始化 tbPtzCameraList _tbPtzCameraList = new(); // 初始化 ptzInfoDict _cameraPtzInfoDict = new ConcurrentDictionary(); // 初始化 thread _thread = new Thread(WorkLoop) { IsBackground = true// 设置后台线程 }; _thread.Start(); } #region Loop private void WorkLoop() { while (true) { GetPtzInfoByApi(); Thread.Sleep(10000); } } private void GetPtzInfoByApi() { foreach (TbPtzCamera item in _tbPtzCameraList) { RequestRealControl rrc = _ptzServerApi.GetPtzInfo(item.CameraId); CameraCalcInfo ptzInfo = new() { Pan = rrc.PTZPositionInfo.FP, Tilt = rrc.PTZPositionInfo.FT, Zoom = rrc.PTZPositionInfo.FZ }; _cameraPtzInfoDict[item.Ip] = ptzInfo; } } private void Calc() { } #endregion Loop #region external call public bool GetCamera(string ip) { return false; } public bool ActiveCamera(string ip) { return false; } #endregion external call }