using DW5S.DTO; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DW5S.Service { /// /// 任务目标信号缓存 /// public class TaskTarCache { public static TaskTarCache Instance { get; private set; } = new TaskTarCache(); //取参考时间 单位:秒 public double TakeRefTimeSeconds; public TaskTarCache() { //取参考时间 单位:分钟 var takeRefTime = AppConfigHelper.Get("TakeRefTime", 10); TakeRefTimeSeconds = takeRefTime * 60;//秒 } /// /// 缓存目标信号信息 /// private Dictionary> _cahceTars = new Dictionary>(); public void AddRange(int taskId, List tarItems) { lock (this) { if (!_cahceTars.ContainsKey(taskId)) _cahceTars[taskId] = new List(); _cahceTars[taskId].AddRange(tarItems); } } public void Remove(int taskId, X2D1NoRefPosDto tarItem) { lock (this) { if (_cahceTars.ContainsKey(taskId)) { _cahceTars[taskId].Remove(tarItem); } } } public void ClearCache(int taskID) { lock (this) { if (_cahceTars.ContainsKey(taskID)) { _cahceTars.Remove(taskID); } } } public List GetTaskTar(int taskID) { lock (this) { if (_cahceTars.ContainsKey(taskID)) { return _cahceTars[taskID]; } else { return new List(); } } } public void ClearAll() { lock (this) { _cahceTars.Clear(); } } } }