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 { static NLog.Logger logger = NLog.LogManager.LoadConfiguration("nlog.config").GetLogger("SinochemEpsApp"); private Eps eps; public EpsTrxCleanupManager(Eps eps) : base(0, "EpsTrxCleanup") { //debugLogger.Add("EpsTrxCleanupManager is constructed"); logger.Info("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); logger.Info("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); logger.Info("NeedResendPosNotifyEpsTrxes expiration datetime: " + expirationDatetime); List needResendPosNotifyEpsTrxes = EpsTransactionQuery.GetEpsTrxesByNotifyPosFlagAndCreatedTime (NotifyPosFlag.NotifyFailed, expirationDatetime); //debugLogger.Add(needResendPosNotifyEpsTrxes.Count() + " eps trxes need resending pos notify"); logger.Info(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() { DateTime oldEnoughDatetime = DateTime.Now.AddDays(-1 * ConfigurationValues.EpsTrxHistoryArchiveInDays); //debugLogger.Add("RemoveEpsTrxHistory before datetime: " + oldEnoughDatetime); logger.Info("RemoveEpsTrxHistory before datetime: " + oldEnoughDatetime); EpsTransactionQuery.DeleteEpsTrxesBefore(oldEnoughDatetime); } } }