1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- using SinochemCloudClient.Models;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Wayne.Lib.StateEngine;
- using Wayne.Lib.StateEngine.Generic;
- namespace SinochemInternetPlusApp.States.ICCardMode
- {
- public class CheckCardBalance : TimeoutState<FuelingPoint>
- {
- protected override void Enter(StateEntry stateEntry, ref Transition transition)
- {
- base.Enter(stateEntry, ref transition);
- var tid = Main.OnlineVerificationRequest.TID;
- var encryptedPin = Main.OnlineVerificationRequest.EncryptedPIN;
- var cardNo = Main.OnlineVerificationRequest.CardNo.TrimStart('0');
- Main.SendBalanceQueryToCloudAsync(cardNo, encryptedPin, tid, Main.AssociatedNozzles.First());
- //transition = new Transition(this, TransitionType.Done);
- }
- protected override void HandleNonTimeoutEvent(StateEngineEvent stateEngineEvent, ref Transition transition)
- {
- if (stateEngineEvent.Type is EventType)
- {
- switch ((EventType)stateEngineEvent.Type)
- {
- case EventType.CloudBalanceOk:
- var genericEvent = stateEngineEvent as GenericEvent<BalanceInquiryResponse>;
- if (genericEvent != null)
- {
- var tid = Main.OnlineVerificationRequest.TID;
- var cardNo = Main.OnlineVerificationRequest.CardNo;
- Main.CreateEpsTransaction(TransactionMode.ICCardMode);
- Main.CurrentEpsTrx.Model.car_number = genericEvent.EventArgs.result.car_Number;
- Main.CurrentEpsTrx.Model.card_no = cardNo;
- //Not in db
- Main.CurrentEpsTrx.Model.EnryptedPIN = Main.OnlineVerificationRequest.EncryptedPIN;
- Main.CurrentEpsTrx.Model.ttc = genericEvent.EventArgs.result.ttc;
- Main.CurrentEpsTrx.Model.balance_before_trx = genericEvent.EventArgs.result.amount;
- Main.CurrentEpsTrx.Model.token = genericEvent.EventArgs.result.token;
- Main.CurrentEpsTrx.Model.tid = tid;
- Main.CurrentEpsTrx.Model.xf_date = DateTime.Parse(DateTime.Now.Date.ToString("yyyy-MM-dd"));
- Main.CurrentEpsTrx.SaveToDb();
- transition = new Transition(this, TransitionType.CloudBalanceOk);
- }
- else
- {
- transition = HandleCloudBalanceFailed();
- }
- stateEngineEvent.Handled = true;
- break;
- case EventType.CloudBalanceFailed:
- transition = HandleCloudBalanceFailed();
- stateEngineEvent.Handled = true;
- break;
- }
- }
- }
- protected override void Timeout(ref Transition transition)
- {
- transition = HandleCloudBalanceFailed();
- }
- private Transition HandleCloudBalanceFailed()
- {
- return new Transition(this, TransitionType.CloudBalanceFailed);
- }
- protected override int TimeoutInterval =>
- TimeoutValues.GetValueInMilliSec(TimeoutValues.FuelingPoint.ICCardMode_CheckCardBalance, 10);
- }
- }
|