ShowTrxListFueling.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Wayne.Lib.StateEngine;
  7. using Wayne.Lib.StateEngine.Generic;
  8. namespace SinochemInternetPlusApp.States.Shared
  9. {
  10. public class ShowTrxListFueling : TimeoutState<FuelingPoint>
  11. {
  12. private int requestId;
  13. protected override void Enter(StateEntry stateEntry, ref Transition transition)
  14. {
  15. base.Enter(stateEntry, ref transition);
  16. //Don't need send rquest to BigScreen
  17. if (!Main.HasBigSreen())
  18. {
  19. Main.DebugLogger.Add("No screen configured");
  20. transition = new Transition(this, TransitionType.Done);
  21. return;
  22. }
  23. if (Main.CurrentEpsTrx != null)
  24. {
  25. var validTrx = EpsTransactionQuery.GetValidCarPlateEpsTrxModels(
  26. Main.GetAllNozzlesOnThisSide(), ConfigurationValues.AlreadyDoneEpsTrxCountPerDisplay, Main.DebugLogger);
  27. Main.ActiveTrx = validTrx;
  28. if (Main.Eps.NozzleMappingGradeName() != null)
  29. {
  30. foreach (var trx in validTrx)
  31. {
  32. if (trx.trx_status == EpsTrxStatus.BeforeFueling || trx.trx_status == EpsTrxStatus.Fueling)
  33. {
  34. trx.AvailableNozzleGrade = Main.GetAvailableNozzleInfo();
  35. }
  36. }
  37. }
  38. var text = Main.Eps.CreateDisplayTrxCommand(validTrx, out requestId, 1);
  39. if (Main.Eps.CarPlateHandler != null)
  40. {
  41. Main.Eps.CarPlateHandler.BroadcastMessageViaFdc(text);
  42. if (!Main.ContainsRequestId(requestId))
  43. Main.AddRequestId(requestId);
  44. }
  45. else
  46. {
  47. transition = new Transition(this, TransitionType.Done);
  48. }
  49. }
  50. else
  51. {
  52. transition = new Transition(this, TransitionType.Done);
  53. }
  54. }
  55. protected override void HandleNonTimeoutEvent(StateEngineEvent stateEngineEvent, ref Transition transition)
  56. {
  57. if (stateEngineEvent.Type.Equals(EventType.DisplayResponseReceived))
  58. {
  59. var e = stateEngineEvent as GenericEvent<DisplayResponseEventArgs>;
  60. if (e != null && e.EventArgs != null)
  61. {
  62. if (requestId == e.EventArgs.DispResponse.RequestId)
  63. {
  64. e.Handled = true;
  65. if (Main.ContainsRequestId(requestId))
  66. Main.RemoveRequestId(requestId);
  67. transition = new Transition(this, TransitionType.Done);
  68. }
  69. }
  70. }
  71. }
  72. protected override void Timeout(ref Transition transition)
  73. {
  74. transition = new Transition(this, TransitionType.Timeout);
  75. }
  76. protected override int TimeoutInterval =>
  77. TimeoutValues.GetValueInMilliSec(TimeoutValues.FuelingPoint.CarPlateMode_ShowTrxListFueling, 10);
  78. }
  79. }