WaitForCardData.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Wayne.Lib.StateEngine;
  2. using Wayne.Lib.StateEngine.Generic;
  3. using WayneChina_IcCardReader_SinoChem.MessageEntity.Incoming;
  4. namespace SinochemInternetPlusApp.States.ICCardMode
  5. {
  6. public class WaitForCardData : TimeoutState<FuelingPoint>
  7. {
  8. protected override void Enter(StateEntry stateEntry, ref Transition transition)
  9. {
  10. base.Enter(stateEntry, ref transition);
  11. }
  12. protected override void HandleNonTimeoutEvent(StateEngineEvent stateEngineEvent, ref Transition transition)
  13. {
  14. if (stateEngineEvent.Type.Equals(EventType.OnlineVerification))
  15. {
  16. GenericEvent<CardOnlineVerificationEventArgs> genericEvent = stateEngineEvent as GenericEvent<CardOnlineVerificationEventArgs>;
  17. if (genericEvent != null && genericEvent.EventArgs != null)
  18. {
  19. genericEvent.Handled = true;
  20. Main.OnlineVerificationRequest = genericEvent.EventArgs.OnlineVerificationRequest;
  21. transition = new Transition(this, TransitionType.Done);
  22. }
  23. }
  24. else if (stateEngineEvent.Type.Equals(EventType.ReaderStateChanged))
  25. {
  26. GenericEvent<CardReaderStateEventArgs> readerEvent = stateEngineEvent as GenericEvent<CardReaderStateEventArgs>;
  27. if (readerEvent != null && readerEvent.EventArgs != null)
  28. {
  29. if (readerEvent.EventArgs.CardReaderState.State == CardReaderState.Idle)
  30. {
  31. DebugLog("User aborts card processing before PIN");
  32. readerEvent.Handled = true;
  33. transition = new Transition(this, TransitionType.Abort);
  34. }
  35. }
  36. }
  37. else if (stateEngineEvent.Type.Equals(EventType.ExternalCheckFailure))
  38. {
  39. GenericEvent<ExternalCheckFailedEventArgs> e = stateEngineEvent as GenericEvent<ExternalCheckFailedEventArgs>;
  40. if (e != null && e.EventArgs != null)
  41. {
  42. //可能为:1、外部验证错误,2:PIN验证错误
  43. DebugLog($"Error type: {e.EventArgs.ExternalCheckErrorRequest.ErrorType.ToString()}");
  44. e.Handled = true;
  45. transition = new Transition(this, TransitionType.Error);
  46. }
  47. }
  48. }
  49. protected override void Timeout(ref Transition transition)
  50. {
  51. transition = new Transition(this, TransitionType.Timeout);
  52. }
  53. protected override int TimeoutInterval =>
  54. TimeoutValues.GetValueInMilliSec(TimeoutValues.FuelingPoint.ICCardMode_WaitForCardData, 15);
  55. }
  56. }