X2D1PosRefService.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.Collections.Generic;
  4. using System.Configuration;
  5. using System.Data.Entity;
  6. using System.Linq;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. using XdCxRhDW.Dto;
  10. using XdCxRhDW.Entity;
  11. using XdCxRhDW.Framework;
  12. using XdCxRhDW.Repostory;
  13. namespace XdCxRhDW.App
  14. {
  15. /// <summary>
  16. /// 两星一地定位取参考服务
  17. /// </summary>
  18. public class X2D1PosRefService
  19. {
  20. public static X2D1PosRefService Instance { get; private set; } = new X2D1PosRefService();
  21. readonly List<X2D1PosHandle> handles = new List<X2D1PosHandle>();
  22. public double TakeRefTime;
  23. public X2D1PosRefService()
  24. {
  25. TakeRefTime = AppConfigHelper.Get("TakeRefTime", 10);
  26. }
  27. public void AddPosDto(List<X2D1NoXlNoParlPosDto> dtos)
  28. {
  29. try
  30. {
  31. var dto = dtos.First();
  32. lock (this)
  33. {
  34. var firstDto = handles.FirstOrDefault(m => m.TaskId == dto.TaskID);
  35. if (firstDto == null)
  36. {
  37. firstDto = new X2D1PosHandle(dto.TaskID.Value, TakeRefTime);
  38. handles.Add(firstDto);
  39. }
  40. firstDto.Append(dtos);
  41. }
  42. }
  43. catch (Exception ex)
  44. {
  45. LogHelper.Error($"【任务{dtos.First().TaskID}】添加取参考信号流程异常,{ex.Message}", ex).GetAwaiter();
  46. }
  47. }
  48. public void Stop(int taskID)
  49. {
  50. try
  51. {
  52. lock (this)
  53. {
  54. var firstDto = handles.FirstOrDefault(m => m.TaskId == taskID);
  55. if (firstDto != null)
  56. {
  57. firstDto.Stop();
  58. handles.Remove(firstDto);
  59. }
  60. }
  61. }
  62. catch (Exception ex)
  63. {
  64. LogHelper.Error($"停止【任务{taskID}】取参考信号流程异常,{ex.Message}", ex).GetAwaiter();
  65. }
  66. }
  67. }
  68. }