ShowPaymentResult.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml.Serialization;
  8. using Wayne.Lib.StateEngine;
  9. using Wayne.Lib.StateEngine.Generic;
  10. namespace SinochemInternetPlusApp.States.CarPlateManualMode
  11. {
  12. public class ShowPaymentResult : TimeoutState<FuelingPoint>
  13. {
  14. private int requestId;
  15. protected override void Enter(StateEntry stateEntry, ref Transition transition)
  16. {
  17. base.Enter(stateEntry, ref transition);
  18. //Don't need send rquest to BigScreen
  19. if (!Main.HasBigSreen())
  20. {
  21. transition = new Transition(this, TransitionType.Done);
  22. return;
  23. }
  24. if (Main.Eps.CarPlateHandler != null && Main.CurrentEpsTrx != null)
  25. {
  26. string text = CreateDisplayTrxResultCommand(Main.CurrentEpsTrx.Model);
  27. DebugLog(text);
  28. Main.Eps.CarPlateHandler.BroadcastMessageViaFdc(text);
  29. if (!Main.ContainsRequestId(requestId))
  30. Main.AddRequestId(requestId);
  31. }
  32. else
  33. transition = new Transition(this, TransitionType.Done);
  34. }
  35. protected override void HandleNonTimeoutEvent(StateEngineEvent stateEngineEvent, ref Transition transition)
  36. {
  37. if (stateEngineEvent.Type.Equals(EventType.DisplayResponseReceived))
  38. {
  39. var e = stateEngineEvent as GenericEvent<DisplayResponseEventArgs>;
  40. if (e != null && e.EventArgs != null)
  41. {
  42. if (requestId == e.EventArgs.DispResponse.RequestId)
  43. {
  44. e.Handled = true;
  45. if (Main.ContainsRequestId(requestId))
  46. Main.RemoveRequestId(requestId);
  47. transition = new Transition(this, TransitionType.Done);
  48. }
  49. }
  50. }
  51. }
  52. protected override void Timeout(ref Transition transition)
  53. {
  54. transition = new Transition(this, TransitionType.Timeout);
  55. }
  56. protected override int TimeoutInterval =>
  57. TimeoutValues.GetValueInMilliSec(TimeoutValues.FuelingPoint.CarPlateMode_SendPaymentResult, 10);
  58. private string CreateDisplayTrxResultCommand(EpsTransactionModel epsTrxModel)
  59. {
  60. Display display;
  61. string cmdText = "";
  62. XmlSerializer serializer = new XmlSerializer(typeof(Display));
  63. MemoryStream ms;
  64. StreamReader sr;
  65. display = new Display();
  66. display.ScreenType = ScreenType.TrxResult;
  67. display.RequestId = Main.Eps.GetNextRequestId();
  68. requestId = display.RequestId;
  69. display.TimeoutSpecified = true;
  70. display.Timeout = 10;
  71. display.PumpInfo = new DisplayPumpInfo
  72. {
  73. Id = 1,
  74. NozzleId = Main.CurrentNozzleId
  75. };
  76. display.TrxList = new DisplayTrx[] {
  77. Main.Eps.ConvertEpsTrxModelToDisplayTrx(epsTrxModel)
  78. };
  79. ms = new MemoryStream();
  80. serializer.Serialize(ms, display);
  81. ms.Position = 0;
  82. sr = new StreamReader(ms, true);
  83. cmdText = sr.ReadToEnd();
  84. ms.Close();
  85. sr.Close();
  86. return cmdText;
  87. }
  88. }
  89. }