Exemplo n.º 1
0
        /// <summary>
        /// 解析航线信息
        /// </summary>
        /// <param name="strContent">航线内容</param>
        /// <param name="regexInstance">正则实例</param>
        /// <returns></returns>
        public IList <RouteInformation> ParseHtmlCode(string strContent, IRegexExpression regexInstance)
        {
            if (string.IsNullOrEmpty(strContent) || regexInstance == null)
            {
                return(null);
            }

            CtripRegexExpression ctripRegex = (CtripRegexExpression)regexInstance;

            IList <string> valueList = RegexOperation.GetValuesByRegex(ctripRegex.GetSingleRowRegex(), strContent);

            IList <RouteInformation> routeInformationList = new List <RouteInformation>();
            RouteInformation         routeInformation;

            foreach (string strValue in valueList)
            {
                routeInformation = GetRouteInformation(strValue, ctripRegex);

                if (routeInformation != null)
                {
                    routeInformation.SeatList = GetSeatInformation(routeInformation, ctripRegex);

                    routeInformationList.Add(routeInformation);
                }
            }

            return(routeInformationList);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 解析航线信息
        /// </summary>
        /// <param name="strContent">航线内容</param>
        /// <param name="regexInstance">正则实例</param>
        /// <returns></returns>
        public IList <RouteInformation> ParseHtmlCode(string strContent, IRegexExpression regexInstance)
        {
            if (string.IsNullOrEmpty(strContent) || regexInstance == null)
            {
                return(null);
            }

            ElongRegexEpression etripRegex = (ElongRegexEpression)regexInstance;
            //StringReader sr = new StringReader(strContent);
            IList <string> valueList = RegexOperation.GetValuesByRegex(etripRegex.GetSingleRowRegex(), strContent);

            IList <RouteInformation> ElongrouteInformationList = new List <RouteInformation>();
            RouteInformation         elongrouteInformation;

            foreach (string strValue in valueList)
            {
                elongrouteInformation = GetElongRouteInformation(strValue.ToString(), etripRegex);

                if (elongrouteInformation != null)
                {
                    ElongrouteInformationList.Add(elongrouteInformation);
                }
            }

            return(ElongrouteInformationList);
        }
Exemplo n.º 3
0
        private string ControlResponse(string strUrl)
        {
            if (string.IsNullOrEmpty(strUrl))
            {
                return(string.Empty);
            }

            string strRegexExpression = CommonOperation.GetConfigValueByKey(Constant.CTRAVELSKY);

            string strDeparture     = RegexOperation.GetValueByRegex(string.Format(strRegexExpression, Constant.CORGCITY), strUrl);
            string strArrival       = RegexOperation.GetValueByRegex(string.Format(strRegexExpression, Constant.CDSTCITY), strUrl);
            string strDepartureTime = RegexOperation.GetValueByRegex(string.Format(strRegexExpression, Constant.CFLYDATE), strUrl);

            DateTime?departureTime = Convert.ToDateTime(strDepartureTime.Substring(0, 4)
                                                        + "-" + strDepartureTime.Substring(4, 2)
                                                        + "-" + strDepartureTime.Substring(6, 2));

            IList <RouteInformation> routeInformationList = RequestRoute(strDeparture, strArrival, departureTime);

            if (routeInformationList == null)
            {
                return(string.Empty);
            }

            return(CommonOperation.GetXmlOfFlightInformation(routeInformationList));
        }
 public WithinOperation(Analyzer analyzer) : base(Operation.Custom, analyzer)
 {
     regexEngine        = new RegexOperation(analyzer);
     CustomOperation    = "Within";
     OperationDelegate  = WithinOperationDelegate;
     ValidationDelegate = WithinValidationDelegate;
 }
Exemplo n.º 5
0
 public ScopedRegexOperation(Analyzer analyzer) : base(Operation.Custom, analyzer)
 {
     CustomOperation    = "ScopedRegex";
     regexEngine        = new RegexOperation(analyzer);
     OperationDelegate  = ScopedRegexOperationDelegate;
     ValidationDelegate = ScopedRegexValidationDelegate;
 }
Exemplo n.º 6
0
        private IList <Seat> GetSeatInformation(RouteInformation routeInformation, CtripRegexExpression ctripRegex)
        {
            IList <Seat> seatList = new List <Seat>();
            Seat         seat;

            string strUrl = GetUrl(routeInformation.OriginalAirport, routeInformation.DestinationAirport, routeInformation.DepartureTime, routeInformation.FlightNO);

            IList <string> resultList = RegexOperation.GetValuesByRegex(string.Format(ctripRegex.GetAllCabinInfomation(), routeInformation.FlightNO.Trim()), DownHtmlSource(strUrl));

            if (resultList == null)
            {
                return(seatList);
            }

            string strPrice = string.Empty;

            foreach (string strResult in resultList)
            {
                seat       = new Seat();
                seat.Cabin = RegexOperation.GetValueByRegex(ctripRegex.GetOtherCanbin(), strResult);

                strPrice = RegexOperation.GetValueByRegex(ctripRegex.GetOtherCanbinPrice(), strResult);
                if (!string.IsNullOrEmpty(strPrice))
                {
                    seat.Price = double.Parse(strPrice);
                }

                seat.Count = 9;

                seatList.Add(seat);
            }

            return(seatList);
        }
Exemplo n.º 7
0
        private IList <Seat> GetSeatInformation(string strContent, VeryTripRegexExpression veryTripRegex)
        {
            IList <Seat> seatList = new List <Seat>();
            Seat         seat;

            IList <string> secondContentList = RegexOperation.GetValuesByRegex(veryTripRegex.GetSingleRowSecondRegex(), strContent);

            if (secondContentList == null)
            {
                return(seatList);
            }

            string strPrice = string.Empty;

            foreach (string strResult in secondContentList)
            {
                seat       = new Seat();
                seat.Cabin = RegexOperation.GetValueByRegex(veryTripRegex.GetCabinRegex(), strResult);

                strPrice = RegexOperation.GetValueByRegex(veryTripRegex.GetTicketPriceRegex(), strResult);
                if (!string.IsNullOrEmpty(strPrice))
                {
                    seat.Price = double.Parse(strPrice);
                }

                seat.Count = 9;

                seat.SubCanbin = RegexOperation.GetValueByRegex(veryTripRegex.GetSubCanbin(), strResult);

                seatList.Add(seat);
            }

            return(seatList);
        }
 public WithinOperation(Analyzer analyzer, ILoggerFactory?loggerFactory = null) : base(Operation.Custom, analyzer)
 {
     _loggerFactory     = loggerFactory ?? new NullLoggerFactory();
     _regexEngine       = new RegexOperation(analyzer);
     CustomOperation    = "Within";
     OperationDelegate  = WithinOperationDelegate;
     ValidationDelegate = WithinValidationDelegate;
 }
Exemplo n.º 9
0
        public CtripRegexExpression()
        {
            XPathNavigator navigator = RegexOperation.GetXPathNavigatorByPath(CommonOperation.GetConfigValueByKey(Constant.CCTRIPPATH));

            nodeIterator = navigator.Select(Constant.CREGEXEXPRESSION);

            nodeIterator.MoveNext();
        }
Exemplo n.º 10
0
        private string GetNomalFragment(string strContent, VeryTripRegexExpression veryRegexInstance)
        {
            string strNomalContent = RegexOperation.GetValueByRegex(veryRegexInstance.GetNormalFragmentRegex(), strContent);

            if (!string.IsNullOrEmpty(strNomalContent))
            {
                strNomalContent += Constant.CMATCHSIGN;
            }

            return(strNomalContent);
        }
Exemplo n.º 11
0
        private IList <string> GetPageUrl(string strContent, VeryTripRegexExpression veryRegexInstance)
        {
            IList <string> pageUrlList = new List <string>();

            string strPages = RegexOperation.GetValueByRegex(veryRegexInstance.GetPageFragmentRegex(), strContent);

            if (string.IsNullOrEmpty(strPages))
            {
                return(pageUrlList);
            }


            IList <string> suffixUrlList = RegexOperation.GetValuesByRegex(veryRegexInstance.GetPageLinkRegex(), strPages);

            foreach (string strSuffixUrl in suffixUrlList)
            {
                pageUrlList.Add(GetPrefixUrl() + strSuffixUrl);
            }

            return(pageUrlList);
        }
Exemplo n.º 12
0
        private List <RouteInformation> GetCurrentPageRoute(string strContent, VeryTripRegexExpression veryTripRegex)
        {
            IList <string> valueList = RegexOperation.GetValuesByRegex(veryTripRegex.GetSingleRowRegex(), strContent);

            List <RouteInformation> routeInformationList = new List <RouteInformation>();
            RouteInformation        routeInformation;

            foreach (string strValue in valueList)
            {
                routeInformation = GetRouteInformation(strValue, veryTripRegex);

                if (routeInformation != null)
                {
                    routeInformation.SeatList = GetSeatInformation(strValue, veryTripRegex);

                    routeInformationList.Add(routeInformation);
                }
            }

            return(routeInformationList);
        }
Exemplo n.º 13
0
        private RouteInformation GetRouteInformation(string strContent, CtripRegexExpression ctripRegex)
        {
            if (string.IsNullOrEmpty(strContent))
            {
                return(null);
            }

            string strTbodyData = RegexOperation.GetValueByRegex(ctripRegex.GetTbodyDataRegex(), strContent);

            if (string.IsNullOrEmpty(strTbodyData))
            {
                return(null);
            }

            RouteInformation routeInformation = new RouteInformation();
            IList <string>   valueList;

            valueList = RegexOperation.GetValuesByRegex(ctripRegex.GetCityRegex(), strContent);
            if (valueList != null && valueList.Count == 2)
            {
                routeInformation.OriginalAirport    = valueList[0];
                routeInformation.DestinationAirport = valueList[1];
            }

            valueList = RegexOperation.GetValuesByRegex(ctripRegex.GetDateRegex(), strContent);
            if (valueList != null && valueList.Count == 2)
            {
                if (!string.IsNullOrEmpty(valueList[0]))
                {
                    routeInformation.DepartureTime = DateTime.Parse(valueList[0]);
                }

                if (!string.IsNullOrEmpty(valueList[1]))
                {
                    routeInformation.ArriveTime = DateTime.Parse(valueList[1]);
                }
            }

            routeInformation.AirDate = routeInformation.DepartureTime;

            string strDiscount = RegexOperation.GetValueByRegex(ctripRegex.GetDiscountRegex(), strTbodyData);

            if (!string.IsNullOrEmpty(strDiscount))
            {
                routeInformation.Discount = double.Parse(strDiscount);
            }

            string strTicketPrice = RegexOperation.GetValueByRegex(ctripRegex.GetTicketPriceRegex(), strTbodyData);

            if (!string.IsNullOrEmpty(strTicketPrice))
            {
                routeInformation.TicketPrice = double.Parse(strTicketPrice);
            }

            routeInformation.Meal    = RegexOperation.GetValueByRegex(ctripRegex.GetMealRegex(), strTbodyData);
            routeInformation.AirLine = RegexOperation.GetValueByRegex(ctripRegex.GetAirLineRegex(), strTbodyData);

            routeInformation.ChangeRule     = RegexOperation.GetValueByRegex(ctripRegex.GetChangeRuleRegex(), strContent);
            routeInformation.FlightInterval = RegexOperation.GetValueByRegex(ctripRegex.GetFlightIntervalRegex(), strContent);
            routeInformation.FlightNO       = RegexOperation.GetValueByRegex(ctripRegex.GetFlightNORegex(), strContent);
            routeInformation.FlightType     = RegexOperation.GetValueByRegex(ctripRegex.GetFlightTypeRegex(), strContent);
            routeInformation.ChangeRule     = RegexOperation.GetValueByRegex(ctripRegex.GetChangeRuleRegex(), strContent);
            routeInformation.Cabin          = RegexOperation.GetValueByRegex(ctripRegex.GetCabinRegex(), strContent);


            string strYprice = RegexOperation.GetValueByRegex(ctripRegex.GetYpriceRegex(), strContent);

            if (!string.IsNullOrEmpty(strYprice))
            {
                routeInformation.Yprice = double.Parse(strYprice);
            }

            string strAirportFuelTax = RegexOperation.GetValueByRegex(ctripRegex.GetAirportFuelRegex(), strContent);

            if (!string.IsNullOrEmpty(strAirportFuelTax))
            {
                string[] strDatas = strAirportFuelTax.Split('+');

                if (!string.IsNullOrEmpty(strDatas[0]))
                {
                    routeInformation.AirportTax = double.Parse(strDatas[0]);
                }

                if (!string.IsNullOrEmpty(strDatas[1]))
                {
                    routeInformation.FuelTax = double.Parse(strDatas[1]);
                }
            }

            return(routeInformation);
        }
Exemplo n.º 14
0
 /// <summary>
 /// 获取Tbody元素中Data属性的值
 /// </summary>
 public string GetTbodyDataRegex()
 {
     return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CTBODYDATA));
 }
Exemplo n.º 15
0
 /// <summary>
 /// 获取Y舱价格的正则表达式
 /// </summary>
 public string GetYpriceRegex()
 {
     return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CYPRICE));
 }
Exemplo n.º 16
0
 /// <summary>
 /// 获取折扣的正则表达式
 /// </summary>
 public string GetDiscountRegex()
 {
     return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CDISCOUNT));
 }
Exemplo n.º 17
0
 /// <summary>
 /// 获取航班号的正则表达式
 /// </summary>
 public string GetFlightNORegex()
 {
     return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CFLIGHTNO));
 }
Exemplo n.º 18
0
 /// <summary>
 /// 获取退改签的正则表达式
 /// </summary>
 public string GetChangeRuleRegex()
 {
     return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CCHANGERULE));
 }
Exemplo n.º 19
0
 /// <summary>
 /// 获取出发时间的正则表达式
 /// </summary>
 public string GetDepartureTimeRegex()
 {
     return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CDEPARTURETIME));
 }
Exemplo n.º 20
0
 /// <summary>
 /// 获取到达时间的正则表达式
 /// </summary>
 public string GetArrivalTimeRegex()
 {
     return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CARRIVALTIME));
 }
Exemplo n.º 21
0
 /// <summary>
 /// 获取舱位的正则表达式
 /// </summary>
 public string GetCabinRegex()
 {
     return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CCABIN));
 }
Exemplo n.º 22
0
 /// <summary>
 /// 获取机场建设费的正则表达式
 /// </summary>
 public string GetAirportRegex()
 {
     return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CAIRPORT));
 }
Exemplo n.º 23
0
 /// <summary>
 /// 获取到达城市的正则表达式
 /// </summary>
 public string GetArrivalCityRegex()
 {
     return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CARRIVALCITY));
 }
Exemplo n.º 24
0
 /// <summary>
 /// 获取城市对值
 /// </summary>
 public string GetCityRegex()
 {
     return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CCITY));
 }
Exemplo n.º 25
0
 /// <summary>
 /// 获取日期对值
 /// </summary>
 public string GetDateRegex()
 {
     return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CDATE));
 }
Exemplo n.º 26
0
 /// <summary>
 /// 获取某个航班的所有舱位信息
 /// </summary>
 /// <returns></returns>
 public string GetAllCabinInfomation()
 {
     return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CALLCABININFOMATION));
 }
Exemplo n.º 27
0
 /// <summary>
 /// 获取飞行时间表达式
 /// </summary>
 /// <returns></returns>
 public string GetFlightIntervalRegex()
 {
     return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CFLIGHTINTERVAL));
 }
Exemplo n.º 28
0
 /// <summary>
 /// 获取餐食
 /// </summary>
 public string GetMealRegex()
 {
     return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CMEAL));
 }
Exemplo n.º 29
0
 /// <summary>
 /// 获取某个航班舱位的价格
 /// </summary>
 /// <returns></returns>
 public string GetOtherCanbinPrice()
 {
     return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.COTHERCANBINPRICE));
 }
Exemplo n.º 30
0
 /// <summary>
 /// 获取航空公司的正则表达式
 /// </summary>
 public string GetAirLineRegex()
 {
     return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CAIRLINE));
 }