App.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using Applications.FDC;
  2. using Edge.Core.Processor;using Edge.Core.IndustryStandardInterface.Pump;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. namespace VeederRootAtgConsoleDispenserInterfaceApp
  8. {
  9. public class App : IAppProcessor
  10. {
  11. public string MetaConfigName { get; set; }
  12. private bool isStopped = false;
  13. public void Init(IEnumerable<IProcessor> processors)
  14. {
  15. var fdcServerApp = processors.OfType<FdcServerHostApp>().FirstOrDefault();
  16. if (fdcServerApp == null) throw new ArgumentNullException("Can't find the FdcServerHostApp from processors");
  17. var veederRootAtgConsoleHandler = processors.OfType<VeederRoot_ATG_Console.Handler>().FirstOrDefault();
  18. if (veederRootAtgConsoleHandler == null) throw new ArgumentNullException("Can't find the VeederRoot_ATG_Console.Handler from processors");
  19. fdcServerApp.OnStateChange += async (s, a) =>
  20. {
  21. if (this.isStopped) return;
  22. var pump = s as IFdcPumpController;
  23. if (a.NewPumpState == Wayne.FDCPOSLibrary.LogicalDeviceState.FDC_AUTHORISED)
  24. await veederRootAtgConsoleHandler.NotifyFuelTrxEventToAtgConsoleAsync(
  25. new VeederRoot_ATG_Console.MessageEntity.DispenserInterface.Outgoing.StartEventReportRequest(
  26. 9, 0, 0, (byte)pump.PumpId));
  27. };
  28. fdcServerApp.OnCurrentFuellingStatusChange += async (s, a) =>
  29. {
  30. if (this.isStopped) return;
  31. var pump = s as IFdcPumpController;
  32. if (a.Transaction.Finished == true)
  33. await veederRootAtgConsoleHandler.NotifyFuelTrxEventToAtgConsoleAsync(
  34. new VeederRoot_ATG_Console.MessageEntity.DispenserInterface.Outgoing.StopEventReportRequest(
  35. 1, 0, 0, (byte)pump.PumpId,
  36. VeederRoot_ATG_Console.MessageEntity.DispenserInterface.Outgoing.StopEventReportRequest.FuelingInfo.SingleProductDispensed,
  37. new List<Tuple<byte, double, double>>() {
  38. new Tuple<byte, double, double>(
  39. 9,
  40. a.Transaction.VolumeTotalizer??-1,
  41. a.Transaction.Volumn) })
  42. );
  43. };
  44. }
  45. public async Task<bool> Start()
  46. {
  47. this.isStopped = false;
  48. return true;
  49. }
  50. public async Task<bool> Stop()
  51. {
  52. this.isStopped = true;
  53. return true;
  54. }
  55. }
  56. }