using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Text; using System.Threading.Tasks; using SinochemCloudClient.Models; using SinochemPosClient.Models; namespace SinochemInternetPlusApp.EpsTrxCleanup { public class EpsTrxCleanupManager : StateManager { private Eps eps; public EpsTrxCleanupManager(Eps eps) : base(0, "EpsTrxCleanup") { debugLogger.Add("EpsTrxCleanupManager is constructed"); this.eps = eps; } public override string EntityType => "EpsTrxCleanup"; public override string EntitySubType => ""; protected override void ConfigStates() { States.CONFIGURATION.Config(stateMachine.StateTransitionLookup); } internal List GetNeedRefundEpsTrxes() { DateTime dummyTime = DateTime.Now; return EpsTransactionQuery.GetEpsTrxesByTrxStatusAndCreatedTime (EpsTrxStatus.PaymentOkButNeedRefund, dummyTime, true); } internal List GetNeedConfirmEpsTrxes() { DateTime expirationDatetime = DateTime.Now.AddMinutes(-1 * ConfigurationValues.NeedConfirmEpsTrxExpirationInMinutes); debugLogger.Add("NeedConfirmEpsTrxes expiration datetime: " + expirationDatetime); List needConfirmEpsTrxes = EpsTransactionQuery.GetEpsTrxesByTrxStatusAndCreatedTime (EpsTrxStatus.PaymentNeedConfirm, expirationDatetime, false); debugLogger.Add(needConfirmEpsTrxes.Count() + " eps trxes need confirmation"); return needConfirmEpsTrxes; } internal List GetNeedResendPosNotifyEpsTrxes() { DateTime expirationDatetime = DateTime.Now.AddMinutes(-1 * ConfigurationValues.ResendPosNotifyExpirationInMinutes); debugLogger.Add("NeedResendPosNotifyEpsTrxes expiration datetime: " + expirationDatetime); List needResendPosNotifyEpsTrxes = EpsTransactionQuery.GetEpsTrxesByNotifyPosFlagAndCreatedTime (NotifyPosFlag.NotifyFailed, expirationDatetime); debugLogger.Add(needResendPosNotifyEpsTrxes.Count() + " eps trxes need resending pos notify"); return needResendPosNotifyEpsTrxes; } internal RefundResponse RefundEpsTrxInCloud(EpsTransactionModel trxModel) { return eps.SendRefundToCloud(trxModel, debugLogger); } internal TrxStatusInquiryResponse InquiryCloudTrxStatus(EpsTransactionModel trxModel) { return eps.SendTrxQueryToCloud(trxModel, debugLogger); } internal TrxNotificationResponse NotifySuccessfulTrxToPos(EpsTransactionModel trxModel) { return eps.NotifySuccessfulTrxToPos(trxModel, debugLogger); } internal void RemoveEpsTrxHistoryBeforeCertainDate() { //Remove the old trxes DateTime oldEnoughDatetime = DateTime.Now.AddDays(-1 * ConfigurationValues.EpsTrxHistoryArchiveInDays); debugLogger.Add("RemoveEpsTrxHistory before datetime: " + oldEnoughDatetime); EpsTransactionQuery.DeleteEpsTrxesBefore(oldEnoughDatetime); //Remove the eps trxes that the status is "before fueling" DateTime epsPendingTrxExpiredHours = DateTime.Now.AddHours(-1 * ConfigurationValues.EpsPendingTrxExpiredInHours); debugLogger.Add("Remove Eps Pending Trx before datetime: " + epsPendingTrxExpiredHours); EpsTransactionQuery.DeleteEpsTrxPendingBefore(epsPendingTrxExpiredHours); } } }