コード例 #1
0
        public void validConfigDateTime(TicketOrders config, CrawlerModels.orderPageInfo orderInfo)
        {
            var haveBackDate = haveBackDateFunc(config);
            var haveToDate   = haveToDateFunc(config);

            if (haveToDate)
            {
                var configToDate = validDateFormat(config.targetDate.TripToDate, config.OrderId);
                validPassDate(configToDate, config.OrderId);

                /**
                 * logic:去程到達時間不可晚於回程出發時間或相距過近
                 * 去程日期不可晚於回程日期
                 **/
                var backTripInfo = orderInfo.trips.FirstOrDefault(x => x.tripType == "回程");
                compareTripDateAndConfigDate(backTripInfo, configToDate);
            }


            if (haveBackDate)
            {
                var configBackDate = validDateFormat(config.targetDate.TripBackDate, config.OrderId);
                validPassDate(configBackDate, config.OrderId);
                var toTripInfo = orderInfo.trips.FirstOrDefault(x => x.tripType == "去程");
                compareTripDateAndConfigDate(toTripInfo, configBackDate);
            }
        }
コード例 #2
0
 public void validOrderIdAndIdCard(TicketOrders config)
 {
     if (string.IsNullOrEmpty(config.OrderId) || string.IsNullOrEmpty(config.IdCard))
     {
         var msg = $"訂位代號及身份證字號不得為空";
         _logger.LogCritical(msg);
         throw new InvalidConfigException(msg);
     }
 }
コード例 #3
0
        public CrawlerModels.modifyResult ModifyTrip(CrawlerModels.ModifyTripType tripType, TicketOrders config, CrawlerModels.orderPageInfo orderInfo)
        {
            CrawlerModels.modifyResult result = CrawlerModels.modifyResult.fail;

            try
            {
                var modifyTripPageHtml = _requestClient.GoTo_modifyTrip_form(orderInfo.nextStepUrl);
                //判斷去/回程是否可更改
                var OrderStatus = _htmlParser.CheckModifyFormIsAvailable(modifyTripPageHtml);
                _validation.validOrderStatus(tripType, OrderStatus);
                var searchTripUrl = _htmlParser.GetNextStepUrl(modifyTripPageHtml);

                var formatDate     = _config.GetValidOrderDate(config, tripType, orderInfo);
                var html           = _requestClient.post_search_trip_form(tripType, searchTripUrl, formatDate);
                var modifyOrderUrl = _htmlParser.GetNextStepUrl(html);
                var trips          = _htmlParser.GetTripsPerPageAndHandleError(html, tripType);
                if (trips != null && trips.Count() >= 0)
                {
                    var tripInfo = new CrawlerModels.tripInfo();
                    if (tripType == CrawlerModels.ModifyTripType.To)
                    {
                        tripInfo = orderInfo.trips.FirstOrDefault(x => x.tripType == "去程");
                    }
                    else
                    {
                        tripInfo = orderInfo.trips.FirstOrDefault(x => x.tripType == "回程");
                    }

                    var matchTrip = _tripCompare.FindMatchTrip(trips.ToList(), tripInfo, formatDate.tripDateTime);
                    if (!string.IsNullOrEmpty(matchTrip))
                    {
                        string modifyResultHtml = _requestClient.post_modifyTrip_form(matchTrip, modifyOrderUrl, tripType);
                        result = _htmlParser.ModifyOrderResult(modifyResultHtml);
                        if (result == CrawlerModels.modifyResult.needConfirm)
                        {
                            var    confirmOrderUrl = _htmlParser.GetNextStepUrl(modifyResultHtml);
                            string confirmResult   = _requestClient.post_confirm_form(confirmOrderUrl);
                            result = _htmlParser.ModifyOrderResult(confirmResult);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogInformation(ex.Message);
            }
            return(result);
        }
コード例 #4
0
ファイル: Config.cs プロジェクト: vi000246/THSRLazyBird
        //將設定檔的訂位時間轉成高鐵網站可用的格式
        public (string tripDate, string tripTime, DateTime tripDateTime) GetValidOrderDate(TicketOrders config, CrawlerModels.ModifyTripType tripType, CrawlerModels.orderPageInfo orderInfo)
        {
            string tripDate   = "";
            string tripTime   = "";
            var    targetDate = config.targetDate;

            switch (tripType)
            {
            case CrawlerModels.ModifyTripType.To:
                tripDate = targetDate.TripToDate;
                tripTime = targetDate.TripToTime;
                break;

            case CrawlerModels.ModifyTripType.Back:
                tripDate = targetDate.TripBackDate;
                tripTime = targetDate.TripBackTime;
                break;
            }

            var formatTime = getTimeDropDownValue(tripTime);

            if (string.IsNullOrEmpty(formatTime))
            {
                var msg = $"訂位代號:{config.OrderId} 設定檔Time欄位格式錯誤,time:{tripTime} 必須為mm:dd 以30分鐘為間隔";
                _logger.LogCritical(msg);
                throw new InvalidConfigException(msg);
            }
            var tripDateTime = Convert.ToDateTime($"{tripDate} {tripTime}");

            return(tripDate, formatTime, tripDateTime);
        }