WaitForPayableTrx.cs 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.FuelingDone:
  21. var genericEvent = stateEngineEvent as GenericEvent<FuelingDoneEventArgs>;
  22. if (genericEvent != null && genericEvent.EventArgs != null &&
  23. IsFdEventForCurrentFueling(genericEvent.EventArgs)) // check if it is for the current fueling
  24. {
  25. var liushuino = genericEvent.EventArgs.FuelingSqNo;
  26. var amount = genericEvent.EventArgs.Amount;
  27. var quantity = genericEvent.EventArgs.Quantity;
  28. if (Main.CurrentTrxMode == TransactionMode.CarPlateMode || Main.CurrentTrxMode == TransactionMode.ICCardMode)
  29. {
  30. Main.CurrentEpsTrx.Model.liushuino = Convert.ToString(liushuino);
  31. Main.CurrentEpsTrx.Model.amount = Convert.ToDouble(amount);
  32. Main.CurrentEpsTrx.Model.qty = Convert.ToDouble(quantity);
  33. Main.CurrentEpsTrx.Model.trx_status = EpsTrxStatus.FuelingDone;
  34. Main.CurrentEpsTrx.SaveToDb();
  35. }
  36. else if (Main.CurrentTrxMode == TransactionMode.BasicMode)
  37. {
  38. MultiFusionsSupport.CopyXiaofei2ToTargetFusion(Main.CurrentNozzleId, Convert.ToString(liushuino), Main.DebugLogger);
  39. }
  40. transition = new Transition(this, TransitionType.FuelingDone);
  41. stateEngineEvent.Handled = true;
  42. }
  43. else
  44. {
  45. DebugLog("Not matached AuthorizationId in FuelingDone event!!! Just ignore it and keep waiting.");
  46. }
  47. break;
  48. }
  49. }
  50. }
  51. private bool IsFdEventForCurrentFueling(FuelingDoneEventArgs fdEventArgs)
  52. {
  53. return fdEventArgs.AuthId == Main.AuthorizationId;
  54. }
  55. protected override void Timeout(ref Transition transition)
  56. {
  57. // two situations here:
  58. // 1) no fueling occured -- Zero filling
  59. // 2) fueling has occured, but eps did not receive the FuelingDone event from fcc in a given period
  60. if (Main.CurrentTrxMode == TransactionMode.CarPlateMode || Main.CurrentTrxMode == TransactionMode.ICCardMode)
  61. {
  62. Main.CurrentEpsTrx.Model.trx_status = EpsTrxStatus.PaymentFailed;
  63. Main.CurrentEpsTrx.Model.amount = 0.00;
  64. Main.CurrentEpsTrx.Model.qty = 0.00;
  65. Main.CurrentEpsTrx.Model.real_pay_amount = 0.00;
  66. Main.CurrentEpsTrx.SaveToDb();
  67. }
  68. transition = new Transition(this, TransitionType.Timeout);
  69. }
  70. protected override int TimeoutInterval =>
  71. TimeoutValues.GetValueInMilliSec(TimeoutValues.FuelingPoint.Shared_WaitForPayableTrx, 5);
  72. }
  73. }