using System; using System.Collections.Generic; using Wayne.Lib; using Wayne.Lib.StateEngine; using Wayne.Lib.StateEngine.Generic; namespace SinochemInternetPlusApp.States.Shared { class AuthorizePump : TimeoutState { protected override void Enter(StateEntry stateEntry, ref Transition transition) { base.Enter(stateEntry, ref transition); ClearExpiredLastTrx(); Main.AuthorizePumpAsync(0); // auth unlimited amount } protected override void HandleNonTimeoutEvent(StateEngineEvent stateEngineEvent, ref Transition transition) { if (stateEngineEvent.Type is EventType) { switch ((EventType)stateEngineEvent.Type) { case EventType.PumpAuthOk: var genericEvent = stateEngineEvent as GenericEvent>; if (genericEvent != null && Main.CurrentEpsTrx != null) { Main.DebugLogger.Add($"Current jihao: {Main.CurrentEpsTrx.Model.jihao}"); Main.CurrentEpsTrx.Model.auth_time = genericEvent.EventArgs.Arg; Main.CurrentEpsTrx.Model.trx_status = EpsTrxStatus.Fueling; Main.CurrentEpsTrx.SaveToDb(); } //} transition = new Transition(this, TransitionType.PumpAuthOk); stateEngineEvent.Handled = true; break; case EventType.PumpAuthFailed: transition = new Transition(this, TransitionType.PumpAuthFailed); stateEngineEvent.Handled = true; break; } } } protected override void Timeout(ref Transition transition) { transition = new Transition(this, TransitionType.Timeout); } protected override int TimeoutInterval => TimeoutValues.GetValueInMilliSec(TimeoutValues.FuelingPoint.Shared_AuthorizePump, 10); private int expiredTrxInterval = TimeoutValues.GetValueInSec(TimeoutValues.FuelingPoint.__FP_Shared_AuthorizePump_ClearLastTrx, 30 * 60); private void ClearExpiredLastTrx() { if (Main.CurrentEpsTrx != null) { Main.DebugLogger.Add($"expired interval value is: {expiredTrxInterval}"); DateTime oldEnoughDatetime = DateTime.Now.AddSeconds(-1 * expiredTrxInterval); Main.DebugLogger.Add($" ClearExpiredLastTrx Main.CurrentEpsTrx.Model.created_time: {Main.CurrentEpsTrx.Model.created_time}, " + $"oldEnoughDatetime: {oldEnoughDatetime}"); if (Main.CurrentEpsTrx.Model.created_time < oldEnoughDatetime) { Main.DebugLogger.Add("Set CurrentEpsTrx to null"); Main.CurrentEpsTrx = null; } } } } }