123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml.Serialization;
- using Wayne.Lib.StateEngine;
- using Wayne.Lib.StateEngine.Generic;
- namespace SinochemInternetPlusApp.States.CarPlateManualMode
- {
- public class ShowPaymentResult : TimeoutState<FuelingPoint>
- {
- private int requestId;
- protected override void Enter(StateEntry stateEntry, ref Transition transition)
- {
- base.Enter(stateEntry, ref transition);
- //Don't need send rquest to BigScreen
- if (!Main.HasBigSreen())
- {
- transition = new Transition(this, TransitionType.Done);
- return;
- }
- if (Main.Eps.CarPlateHandler != null && Main.CurrentEpsTrx != null)
- {
- string text = CreateDisplayTrxResultCommand(Main.CurrentEpsTrx.Model);
- DebugLog(text);
- Main.Eps.CarPlateHandler.BroadcastMessageViaFdc(text);
- if (!Main.ContainsRequestId(requestId))
- Main.AddRequestId(requestId);
- }
- else
- transition = new Transition(this, TransitionType.Done);
- }
- protected override void HandleNonTimeoutEvent(StateEngineEvent stateEngineEvent, ref Transition transition)
- {
- if (stateEngineEvent.Type.Equals(EventType.DisplayResponseReceived))
- {
- var e = stateEngineEvent as GenericEvent<DisplayResponseEventArgs>;
- if (e != null && e.EventArgs != null)
- {
- if (requestId == e.EventArgs.DispResponse.RequestId)
- {
- e.Handled = true;
- if (Main.ContainsRequestId(requestId))
- Main.RemoveRequestId(requestId);
- transition = new Transition(this, TransitionType.Done);
- }
- }
- }
- }
- protected override void Timeout(ref Transition transition)
- {
- transition = new Transition(this, TransitionType.Timeout);
- }
- protected override int TimeoutInterval =>
- TimeoutValues.GetValueInMilliSec(TimeoutValues.FuelingPoint.CarPlateMode_SendPaymentResult, 10);
- private string CreateDisplayTrxResultCommand(EpsTransactionModel epsTrxModel)
- {
- Display display;
- string cmdText = "";
- XmlSerializer serializer = new XmlSerializer(typeof(Display));
- MemoryStream ms;
- StreamReader sr;
- display = new Display();
- display.ScreenType = ScreenType.TrxResult;
- display.RequestId = Main.Eps.GetNextRequestId();
- requestId = display.RequestId;
- display.TimeoutSpecified = true;
- display.Timeout = 10;
- display.PumpInfo = new DisplayPumpInfo
- {
- Id = 1,
- NozzleId = Main.CurrentNozzleId
- };
- display.TrxList = new DisplayTrx[] {
- Main.Eps.ConvertEpsTrxModelToDisplayTrx(epsTrxModel)
- };
- ms = new MemoryStream();
- serializer.Serialize(ms, display);
- ms.Position = 0;
- sr = new StreamReader(ms, true);
- cmdText = sr.ReadToEnd();
- ms.Close();
- sr.Close();
- return cmdText;
- }
- }
- }
|