/// <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); }
/// <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); }
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; }
public ScopedRegexOperation(Analyzer analyzer) : base(Operation.Custom, analyzer) { CustomOperation = "ScopedRegex"; regexEngine = new RegexOperation(analyzer); OperationDelegate = ScopedRegexOperationDelegate; ValidationDelegate = ScopedRegexValidationDelegate; }
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); }
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; }
public CtripRegexExpression() { XPathNavigator navigator = RegexOperation.GetXPathNavigatorByPath(CommonOperation.GetConfigValueByKey(Constant.CCTRIPPATH)); nodeIterator = navigator.Select(Constant.CREGEXEXPRESSION); nodeIterator.MoveNext(); }
private string GetNomalFragment(string strContent, VeryTripRegexExpression veryRegexInstance) { string strNomalContent = RegexOperation.GetValueByRegex(veryRegexInstance.GetNormalFragmentRegex(), strContent); if (!string.IsNullOrEmpty(strNomalContent)) { strNomalContent += Constant.CMATCHSIGN; } return(strNomalContent); }
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); }
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); }
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); }
/// <summary> /// 获取Tbody元素中Data属性的值 /// </summary> public string GetTbodyDataRegex() { return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CTBODYDATA)); }
/// <summary> /// 获取Y舱价格的正则表达式 /// </summary> public string GetYpriceRegex() { return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CYPRICE)); }
/// <summary> /// 获取折扣的正则表达式 /// </summary> public string GetDiscountRegex() { return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CDISCOUNT)); }
/// <summary> /// 获取航班号的正则表达式 /// </summary> public string GetFlightNORegex() { return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CFLIGHTNO)); }
/// <summary> /// 获取退改签的正则表达式 /// </summary> public string GetChangeRuleRegex() { return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CCHANGERULE)); }
/// <summary> /// 获取出发时间的正则表达式 /// </summary> public string GetDepartureTimeRegex() { return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CDEPARTURETIME)); }
/// <summary> /// 获取到达时间的正则表达式 /// </summary> public string GetArrivalTimeRegex() { return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CARRIVALTIME)); }
/// <summary> /// 获取舱位的正则表达式 /// </summary> public string GetCabinRegex() { return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CCABIN)); }
/// <summary> /// 获取机场建设费的正则表达式 /// </summary> public string GetAirportRegex() { return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CAIRPORT)); }
/// <summary> /// 获取到达城市的正则表达式 /// </summary> public string GetArrivalCityRegex() { return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CARRIVALCITY)); }
/// <summary> /// 获取城市对值 /// </summary> public string GetCityRegex() { return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CCITY)); }
/// <summary> /// 获取日期对值 /// </summary> public string GetDateRegex() { return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CDATE)); }
/// <summary> /// 获取某个航班的所有舱位信息 /// </summary> /// <returns></returns> public string GetAllCabinInfomation() { return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CALLCABININFOMATION)); }
/// <summary> /// 获取飞行时间表达式 /// </summary> /// <returns></returns> public string GetFlightIntervalRegex() { return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CFLIGHTINTERVAL)); }
/// <summary> /// 获取餐食 /// </summary> public string GetMealRegex() { return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CMEAL)); }
/// <summary> /// 获取某个航班舱位的价格 /// </summary> /// <returns></returns> public string GetOtherCanbinPrice() { return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.COTHERCANBINPRICE)); }
/// <summary> /// 获取航空公司的正则表达式 /// </summary> public string GetAirLineRegex() { return(RegexOperation.GetElementNodeValue(nodeIterator, Constant.CAIRLINE)); }