1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- 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<FuelingPoint>
- {
- 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<FuelingDoneEventArgs>;
- 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);
- }
- }
|