AuthorizePump.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 AuthorizePump : TimeoutState<FuelingPoint>
  9. {
  10. protected override void Enter(StateEntry stateEntry, ref Transition transition)
  11. {
  12. base.Enter(stateEntry, ref transition);
  13. Main.AuthorizePumpAsync(0); // auth unlimited amount
  14. }
  15. protected override void HandleNonTimeoutEvent(StateEngineEvent stateEngineEvent, ref Transition transition)
  16. {
  17. if (stateEngineEvent.Type is EventType)
  18. {
  19. switch ((EventType)stateEngineEvent.Type)
  20. {
  21. case EventType.PumpAuthOk:
  22. if (Main.CurrentTrxMode == TransactionMode.CarPlateMode || Main.CurrentTrxMode == TransactionMode.ICCardMode)
  23. {
  24. var genericEvent = stateEngineEvent as GenericEvent<GenericEventArg<string>>;
  25. if (genericEvent != null && Main.CurrentEpsTrx != null)
  26. {
  27. Main.CurrentEpsTrx.Model.auth_time = genericEvent.EventArgs.Arg;
  28. Main.CurrentEpsTrx.Model.trx_status = EpsTrxStatus.Fueling;
  29. Main.CurrentEpsTrx.SaveToDb();
  30. }
  31. }
  32. transition = new Transition(this, TransitionType.PumpAuthOk);
  33. stateEngineEvent.Handled = true;
  34. break;
  35. case EventType.PumpAuthFailed:
  36. transition = new Transition(this, TransitionType.PumpAuthFailed);
  37. stateEngineEvent.Handled = true;
  38. break;
  39. }
  40. }
  41. }
  42. protected override void Timeout(ref Transition transition)
  43. {
  44. transition = new Transition(this, TransitionType.Timeout);
  45. }
  46. protected override int TimeoutInterval =>
  47. TimeoutValues.GetValueInMilliSec(TimeoutValues.FuelingPoint.Shared_AuthorizePump, 10);
  48. }
  49. }