Esempio n. 1
0
        /// <summary>
        /// 根据当前查询结果,获得下一个可能的休息时间
        /// </summary>
        /// <param name="session"></param>
        /// <param name="enableAutoRefresh"></param>
        /// <param name="isError"></param>
        /// <returns></returns>
        public (int sleep, string msg, int msgTime) GetSleepTime(Session session = null, bool enableAutoRefresh = true, bool isError = false)
        {
            var sleep   = 0;
            var msg     = string.Empty;
            var msgTime = 0;
            var now     = DateTime.Now;
            var sp      = RunTime.ServerTime;

            if (EnableAutoPreSubmit && enableAutoRefresh)
            {
                var(isOpen, toOpenTime) = ParamData.GetSubmitOrderOpenTime();
                if (!isOpen)
                {
                    sleep   = toOpenTime;
                    msg     = "当前不可提交订单,请等待系统开放。";
                    msgTime = 30 * 1000;
                }
                else if (AutoPreSubmitConfig.AutoWaitToSell && FindNextSellTime(LastQueryResult, out var time))
                {
                    sleep   = (int)(time.Value - sp).TotalMilliseconds + (int)(Configuration.QueryConfiguration.Current.AutoDelayAfterOClock * 1000);
                    msg     = "车票未起售,等待车票起售,等待时间可能会有变化。";
                    msgTime = sleep - 10000;
                }
                else if (AutoPreSubmitConfig.EnableOClockRefresh && (sp.Minute >= 59 || sp.Minute == 29))
                {
                    sleep   = (60 - sp.Second) * 1000;
                    msg     = "即将等待整点起售,等待时间可能会有变化。";
                    msgTime = sleep - 10000;
                }
                else if (Configuration.QueryConfiguration.Current.SpeedingQueryOnOClock != null && (now.Minute == 0 || now.Minute == 30) && now.Second <= 30)
                {
                    sleep = Configuration.QueryConfiguration.Current.SpeedingQueryOnOClock.Value;
                }
                else
                {
                    //默认时间,最低1秒
                    sleep = Configuration.QueryConfiguration.Current.GetRandomQuerySleep(isError);
                }

                if (session != null)
                {
                    sleep = session.UserProfile.QueryParams.CheckForSafty(sleep);
                }
            }

            return(sleep, msg, msgTime);
        }