using System; using System.Collections.Generic; using Wayne.Lib; using Wayne.Lib.StateEngine; using Wayne.Lib.StateEngine.Generic; namespace SinochemInternetPlusApp.States.Shared { class WaitForPayableTrx : TimeoutState { protected override void Enter(StateEntry stateEntry, ref Transition transition) { base.Enter(stateEntry, ref transition); } protected override void HandleNonTimeoutEvent(StateEngineEvent stateEngineEvent, ref Transition transition) { if (stateEngineEvent.Type is EventType) { switch ((EventType)stateEngineEvent.Type) { case EventType.NozzleReplaced: Main.DebugLogger.Add($"Nozzle replaced before fueling trx arriving"); stateEngineEvent.Handled = true; break; case EventType.FuelingDone: var genericEvent = stateEngineEvent as GenericEvent; if (genericEvent != null && genericEvent.EventArgs != null && IsFdEventForCurrentFueling(genericEvent.EventArgs)) // check if it is for the current fueling { var liushuino = genericEvent.EventArgs.FuelingSqNo; var amount = genericEvent.EventArgs.Amount; var quantity = genericEvent.EventArgs.Quantity; //if (Main.CurrentTrxMode == TransactionMode.CarPlateMode || Main.CurrentTrxMode == TransactionMode.ICCardMode) //{ if (Main.CurrentEpsTrx != null) { Main.DebugLogger.Add($"liushuino: {liushuino}, amount: {amount}, qty: {quantity}"); Main.CurrentEpsTrx.Model.liushuino = Convert.ToString(liushuino); Main.CurrentEpsTrx.Model.amount = Convert.ToDouble(amount); Main.CurrentEpsTrx.Model.qty = Convert.ToDouble(quantity); Main.CurrentEpsTrx.Model.trx_status = EpsTrxStatus.FuelingDone; Main.CurrentEpsTrx.SaveToDb(); } //} //else if (Main.CurrentTrxMode == TransactionMode.BasicMode) //{ //MultiFusionsSupport.CopyXiaofei2ToTargetFusion(Main.CurrentNozzleId, Convert.ToString(liushuino), Main.DebugLogger); //} transition = new Transition(this, TransitionType.FuelingDone); stateEngineEvent.Handled = true; } else { DebugLog("Not matached AuthorizationId in FuelingDone event!!! Just ignore it and keep waiting."); } break; } } } private bool IsFdEventForCurrentFueling(FuelingDoneEventArgs fdEventArgs) { return fdEventArgs.AuthId == Main.AuthorizationId; } protected override void Timeout(ref Transition transition) { // two situations here: // 1) no fueling occured -- Zero filling // 2) fueling has occured, but eps did not receive the FuelingDone event from fcc in a given period if (Main.CurrentEpsTrx != null && Main.CurrentTrxMode == EpsTransactionMode.CarPlateMode || Main.CurrentTrxMode == EpsTransactionMode.ICCardMode) { Main.CurrentEpsTrx.Model.trx_status = EpsTrxStatus.PaymentFailed; Main.CurrentEpsTrx.Model.amount = 0.00; Main.CurrentEpsTrx.Model.qty = 0.00; Main.CurrentEpsTrx.Model.real_pay_amount = 0.00; Main.CurrentEpsTrx.SaveToDb(); } transition = new Transition(this, TransitionType.Timeout); } protected override int TimeoutInterval => TimeoutValues.GetValueInMilliSec(TimeoutValues.FuelingPoint.Shared_WaitForPayableTrx, 5); } }