TaskTarCache.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using DevExpress.XtraScheduler.Outlook.Interop;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using DW5S.DTO;
  8. using DW5S.Entity;
  9. namespace DW5S.App
  10. {
  11. /// <summary>
  12. /// 任务目标信号缓存
  13. /// </summary>
  14. public class TaskTarCache
  15. {
  16. public static TaskTarCache Instance { get; private set; } = new TaskTarCache();
  17. //取参考时间 单位:秒
  18. public double TakeRefTimeSeconds;
  19. public TaskTarCache()
  20. {
  21. //取参考时间 单位:分钟
  22. var takeRefTime = AppConfigHelper.Get("TakeRefTime", 10);
  23. TakeRefTimeSeconds = takeRefTime * 60;//秒
  24. }
  25. /// <summary>
  26. /// 缓存目标信号信息
  27. /// </summary>
  28. private Dictionary<int, List<X2D1NoRefPosDto>> _cahceTars = new Dictionary<int, List<X2D1NoRefPosDto>>();
  29. public void AddRange(int taskId, List<X2D1NoRefPosDto> tarItems)
  30. {
  31. lock (this)
  32. {
  33. if (!_cahceTars.ContainsKey(taskId))
  34. _cahceTars[taskId] = new List<X2D1NoRefPosDto>();
  35. _cahceTars[taskId].AddRange(tarItems);
  36. }
  37. }
  38. public void Remove(int taskId, X2D1NoRefPosDto tarItem)
  39. {
  40. lock (this)
  41. {
  42. if (_cahceTars.ContainsKey(taskId))
  43. {
  44. _cahceTars[taskId].Remove(tarItem);
  45. }
  46. }
  47. }
  48. public void ClearCache(int taskID)
  49. {
  50. lock (this)
  51. {
  52. if (_cahceTars.ContainsKey(taskID))
  53. {
  54. _cahceTars.Remove(taskID);
  55. }
  56. }
  57. }
  58. public List<X2D1NoRefPosDto> GetTaskTar(int taskID)
  59. {
  60. lock (this)
  61. {
  62. if (_cahceTars.ContainsKey(taskID))
  63. {
  64. return _cahceTars[taskID];
  65. }
  66. else
  67. {
  68. return new List<X2D1NoRefPosDto>();
  69. }
  70. }
  71. }
  72. public void ClearAll()
  73. {
  74. lock (this)
  75. {
  76. _cahceTars.Clear();
  77. }
  78. }
  79. }
  80. }