PumpHandlerGroupApp.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using Edge.Core.Configuration;
  2. using Edge.Core.IndustryStandardInterface.Pump;
  3. using Edge.Core.Processor;
  4. using Edge.Core.Processor.Dispatcher.Attributes;
  5. using Edge.Core.UniversalApi;
  6. using System;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using Wayne.FDCPOSLibrary;
  13. namespace Bogus_Pump
  14. {
  15. [MetaPartsDescriptor(
  16. "lang-zh-cn:加油机模拟器lang-en-us:Pumps Simulator",
  17. "lang-zh-cn:用于模拟多个通用加油机(多个Pumps), 自动提枪并等待授权, 然后自动加油,但也可以关闭自动模拟转而接收外部调用来模拟油机行为.lang-en-us:Used for simulate generic pumps, auto timely lift nozzle, wait for authorizing and then start fuelling",
  18. new[] { "lang-zh-cn:加油机lang-en-us:Pump" })]
  19. public class PumpHandlerGroupApp : IEnumerable<IFdcPumpController>, IFdcCommunicableController, IAppProcessor, IDisposable
  20. {
  21. private IEnumerable<NozzleExtraInfo> nozzleExtraInfos = null;
  22. private List<PumpHandler> pumpHandlers = new List<PumpHandler>();
  23. public PumpHandlerGroupApp(int pumpsCount, byte nozzlesCountPerPump, bool enableFuelSimulation)
  24. {
  25. pumpHandlers.AddRange(Enumerable.Range(1, pumpsCount).Select(i => new PumpHandler(i, nozzlesCountPerPump, enableFuelSimulation)));
  26. }
  27. public string MetaConfigName { get; set; }
  28. public Func<string, bool> BroadcastMessageViaFdc { get; set; }
  29. public Func<string, string, string, bool> SendMessageViaFdc { get; set; }
  30. public Func<string, Tuple<string, OverallResult>> OnMessageReceivedViaFdc { get; set; }
  31. public void Dispose()
  32. {
  33. this.pumpHandlers?.ForEach(ph => ph.Dispose());
  34. }
  35. public IEnumerator<IFdcPumpController> GetEnumerator()
  36. {
  37. return this.pumpHandlers.GetEnumerator();
  38. }
  39. public void Init(IEnumerable<IProcessor> processors)
  40. {
  41. }
  42. IEnumerator IEnumerable.GetEnumerator()
  43. {
  44. return this.pumpHandlers.GetEnumerator();
  45. }
  46. public void OnFdcServerInit(Dictionary<string, object> parameters)
  47. {
  48. if (parameters != null && parameters.TryGetValue("NozzleProductMapping", out object param))
  49. {
  50. this.nozzleExtraInfos = param as IEnumerable<NozzleExtraInfo>;
  51. }
  52. }
  53. [UniversalApi]
  54. public async Task<bool> ChangePumpStateTo(int siteLevelNozzleId, LogicalDeviceState pumpNewState,
  55. int? amountWithoutDecimalPoint, int? volumeWithoutDecimalPoint, int? priceWithoutDecimalPoint)
  56. {
  57. var targetNozzleInfo = this.nozzleExtraInfos.FirstOrDefault(i => i.SiteLevelNozzleId == siteLevelNozzleId);
  58. if (targetNozzleInfo == null) return false;
  59. var targetPump = this.pumpHandlers.FirstOrDefault(ph => ph.PumpId == targetNozzleInfo.PumpId);
  60. if (targetPump == null) return false;
  61. targetPump.DrivenPumpStateTo((byte?)(targetNozzleInfo.NozzleLogicalId), pumpNewState, amountWithoutDecimalPoint, volumeWithoutDecimalPoint, priceWithoutDecimalPoint);
  62. return true;
  63. }
  64. [UniversalApi]
  65. public async Task<bool> RaisePumpNewTrx(int siteLevelNozzleId,
  66. int amountWithoutDecimalPoint, int volumeWithoutDecimalPoint, int priceWithoutDecimalPoint, int trxSeqNumber)
  67. {
  68. var targetNozzleInfo = this.nozzleExtraInfos.FirstOrDefault(i => i.SiteLevelNozzleId == siteLevelNozzleId);
  69. if (targetNozzleInfo == null) return false;
  70. var targetPump = this.pumpHandlers.FirstOrDefault(ph => ph.PumpId == targetNozzleInfo.PumpId);
  71. if (targetPump == null) return false;
  72. targetPump.DrivenPumpRaiseNewTrx((byte?)(targetNozzleInfo.NozzleLogicalId), amountWithoutDecimalPoint, volumeWithoutDecimalPoint, priceWithoutDecimalPoint, trxSeqNumber);
  73. return true;
  74. }
  75. [UniversalApi]
  76. public async Task<bool> DisplayTextOnPumpScreen(int[] screenIds, int areaId, string text)
  77. {
  78. if (BroadcastMessageViaFdc != null)
  79. {
  80. var p = new
  81. {
  82. source = "fc",
  83. data = new
  84. {
  85. screenIds = screenIds,
  86. areaId = areaId,
  87. text = text,
  88. }
  89. };
  90. BroadcastMessageViaFdc(System.Text.Json.JsonSerializer.Serialize(p));
  91. return true;
  92. }
  93. else
  94. return false;
  95. }
  96. }
  97. }