WaitForPayableTrx.cs 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using System.Collections.Generic;
  3. using Wayne.Lib;
  4. using Wayne.Lib.StateEngine;
  5. using Wayne.Lib.StateEngine.Generic;
  6. namespace SinochemInternetPlusApp.States.Shared
  7. {
  8. class WaitForPayableTrx : TimeoutState<FuelingPoint>
  9. {
  10. protected override void Enter(StateEntry stateEntry, ref Transition transition)
  11. {
  12. base.Enter(stateEntry, ref transition);
  13. }
  14. protected override void HandleNonTimeoutEvent(StateEngineEvent stateEngineEvent, ref Transition transition)
  15. {
  16. if (stateEngineEvent.Type is EventType)
  17. {
  18. switch ((EventType)stateEngineEvent.Type)
  19. {
  20. case EventType.NozzleReplaced:
  21. Main.DebugLogger.Add($"Nozzle replaced before fueling trx arriving");
  22. stateEngineEvent.Handled = true;
  23. break;
  24. case EventType.FuelingDone:
  25. var genericEvent = stateEngineEvent as GenericEvent<FuelingDoneEventArgs>;
  26. if (genericEvent != null && genericEvent.EventArgs != null &&
  27. IsFdEventForCurrentFueling(genericEvent.EventArgs)) // check if it is for the current fueling
  28. {
  29. var liushuino = genericEvent.EventArgs.FuelingSqNo;
  30. var amount = genericEvent.EventArgs.Amount;
  31. var quantity = genericEvent.EventArgs.Quantity;
  32. //if (Main.CurrentTrxMode == TransactionMode.CarPlateMode || Main.CurrentTrxMode == TransactionMode.ICCardMode)
  33. //{
  34. if (Main.CurrentEpsTrx != null)
  35. {
  36. Main.DebugLogger.Add($"liushuino: {liushuino}, amount: {amount}, qty: {quantity}");
  37. Main.CurrentEpsTrx.Model.liushuino = Convert.ToString(liushuino);
  38. Main.CurrentEpsTrx.Model.amount = Convert.ToDouble(amount);
  39. Main.CurrentEpsTrx.Model.qty = Convert.ToDouble(quantity);
  40. Main.CurrentEpsTrx.Model.trx_status = EpsTrxStatus.FuelingDone;
  41. Main.CurrentEpsTrx.SaveToDb();
  42. }
  43. //}
  44. //else if (Main.CurrentTrxMode == TransactionMode.BasicMode)
  45. //{
  46. //MultiFusionsSupport.CopyXiaofei2ToTargetFusion(Main.CurrentNozzleId, Convert.ToString(liushuino), Main.DebugLogger);
  47. //}
  48. transition = new Transition(this, TransitionType.FuelingDone);
  49. stateEngineEvent.Handled = true;
  50. }
  51. else
  52. {
  53. DebugLog("Not matached AuthorizationId in FuelingDone event!!! Just ignore it and keep waiting.");
  54. }
  55. break;
  56. }
  57. }
  58. }
  59. private bool IsFdEventForCurrentFueling(FuelingDoneEventArgs fdEventArgs)
  60. {
  61. return fdEventArgs.AuthId == Main.AuthorizationId;
  62. }
  63. protected override void Timeout(ref Transition transition)
  64. {
  65. // two situations here:
  66. // 1) no fueling occured -- Zero filling
  67. // 2) fueling has occured, but eps did not receive the FuelingDone event from fcc in a given period
  68. if (Main.CurrentEpsTrx != null && Main.CurrentTrxMode == EpsTransactionMode.CarPlateMode || Main.CurrentTrxMode == EpsTransactionMode.ICCardMode)
  69. {
  70. Main.CurrentEpsTrx.Model.trx_status = EpsTrxStatus.PaymentFailed;
  71. Main.CurrentEpsTrx.Model.amount = 0.00;
  72. Main.CurrentEpsTrx.Model.qty = 0.00;
  73. Main.CurrentEpsTrx.Model.real_pay_amount = 0.00;
  74. Main.CurrentEpsTrx.SaveToDb();
  75. }
  76. transition = new Transition(this, TransitionType.Timeout);
  77. }
  78. protected override int TimeoutInterval =>
  79. TimeoutValues.GetValueInMilliSec(TimeoutValues.FuelingPoint.Shared_WaitForPayableTrx, 5);
  80. }
  81. }