示例#1
0
        public virtual IList<Tour> Create(IPttRequest request, IOperator op, out TourFactoryStatus status)
        {
            if (op.ExtensiveLoggingNeeded)
            {
                Logger.LogProcess("TourFactory.Create trying to get html for " + request.Url + " with postdata:"+request.PostValue);
            }

            var htmlSource = op.RequestResponseBehavior.GetHtmlMaster(request, false, op.ExtensiveLoggingNeeded, op.Name);
            if(op.ExtensiveLoggingNeeded)
            {
                Logger.LogProcess("TourFactory.Create Html coming from htmlmaster");
                Logger.LogProcess(htmlSource ?? "");
            }
            if (string.IsNullOrEmpty(htmlSource))
            {
                status = new TourFactoryStatus { Success = false };
                return null;
            }

            var htmlSourceRefined = op.Refine(request, htmlSource);
            if (op.ExtensiveLoggingNeeded)
            {
                Logger.LogProcess("TourFactory.Create Html refined");
                Logger.LogProcess(htmlSourceRefined ?? "");
            }
            var html = new HtmlDocument();
            html.LoadHtml(htmlSourceRefined);
            var list = GetToursFromHtml(request, op, html, out status);
            return list;
        }
示例#2
0
 public override IList<Tour> Create(IPttRequest request, IOperator op, out TourFactoryStatus status)
 {
     if(!Biblo.TourDates.Contains(op.QueryObject.StartDate))
     {
         status = new TourFactoryStatus { Success = true, MoveToNextHotel = true};
         return null;
     }
     return base.Create(request, op, out status);
 }
示例#3
0
        protected virtual IList<Tour> GetToursFromHtml(IPttRequest request, IOperator op, HtmlDocument html, out TourFactoryStatus status)
        {
            status = new TourFactoryStatus { Success = true, MoveToNextHotel = false };

            if (html.DocumentNode.SelectNodes(op.TourInfo.XPath) == null)
            {
                if (op.ExtensiveLoggingNeeded)
                {
                    Logger.LogProcess("TourFactory.GetToursFromHtml xpath node selection returns no nodes");
                }
                status.MoveToNextHotel = true;
                return null;
            }

            if (_beforeIteratingWhileGettingTours != null)
            {
                var ret = _beforeIteratingWhileGettingTours(request, html);
                if (op.ExtensiveLoggingNeeded)
                {
                    Logger.LogProcess("TourFactory.GetToursFromHtml _beforeIteratingWhileGettingTours  flags:"+ret.ToString());
                }
                status.MoveToNextHotel = status.MoveToNextHotel || ret.HasFlag(TourFactoryControlFlags.MoveToNextHotel);
                if (ret.HasFlag(TourFactoryControlFlags.Return))
                {
                    return null;
                }
            }

            var list = new List<Tour>();
            foreach (HtmlNode node in html.DocumentNode.SelectNodes(op.TourInfo.XPath))
            {
                if (_iteratingWhileGettingToursBeforeTourItemSet != null)
                {
                    var ret = _iteratingWhileGettingToursBeforeTourItemSet(request, node);
                    if (op.ExtensiveLoggingNeeded)
                    {
                        Logger.LogProcess("TourFactory.GetToursFromHtml _iteratingWhileGettingToursBeforeTourItemSet  flags:" + ret.ToString());
                    }
                    status.MoveToNextHotel = status.MoveToNextHotel || ret.HasFlag(TourFactoryControlFlags.MoveToNextHotel);
                    if (ret.HasFlag(TourFactoryControlFlags.Continue))
                    {
                        continue;
                    }
                    if (ret.HasFlag(TourFactoryControlFlags.Break))
                    {
                        break;
                    }
                    if (ret.HasFlag(TourFactoryControlFlags.Return))
                    {
                        return null;
                    }
                }

                var tourItem = new Tour();

                tourItem.City = Dictionnaries.Regions[op.QueryObject.OriginId];
                tourItem.TO = op.Name.Replace("_", "");//anex_ gibiler icin
                tourItem.IssueDate = DateTime.Now;

                tourItem.Date = op.TourInfo.GetFieldValue<DateTime>(node, "Date");
                tourItem.Night = op.TourInfo.GetFieldValue<string>(node, "Night");
                tourItem.Hotel = op.TourInfo.GetFieldValue<string>(node, "Hotel");
                tourItem.RoomType = op.TourInfo.GetFieldValue<string>(node, "RoomType");
                tourItem.ACC = op.TourInfo.GetFieldValue<string>(node, "Accomodation");
                tourItem.Price = op.TourInfo.GetFieldValue<Double>(node, "Price");

                var meal = op.TourInfo.GetFieldValue<string>(node, "Meal");
                var mealTypeIndex = 7;
                var innerMealIndex = 0;
                foreach (var mealtypeAlternative in op.MealTypes)
                {
                    if (mealtypeAlternative.Contains(meal))
                    {
                        mealTypeIndex = innerMealIndex;
                        break;
                    }
                    innerMealIndex++;
                }
                tourItem.Meal = Dictionnaries.MealTypes[mealTypeIndex];
                tourItem.SPONo = op.TourInfo.GetFieldValue<string>(node, "SPONo");

                if (_iteratingWhileGettingToursAfterTourItemSet != null)
                {
                    var ret = _iteratingWhileGettingToursAfterTourItemSet(request, tourItem);
                    if (op.ExtensiveLoggingNeeded)
                    {
                        Logger.LogProcess("TourFactory.GetToursFromHtml _iteratingWhileGettingToursAfterTourItemSet  flags:" + ret.ToString());
                    }

                    status.MoveToNextHotel = status.MoveToNextHotel || ret.HasFlag(TourFactoryControlFlags.MoveToNextHotel);
                    if (ret.HasFlag(TourFactoryControlFlags.Continue))
                    {
                        continue;
                    }
                    if (ret.HasFlag(TourFactoryControlFlags.Break))
                    {
                        break;
                    }
                    if (ret.HasFlag(TourFactoryControlFlags.Return))
                    {
                        return null;
                    }
                }
                if (op.QueryObject != null && tourItem.Price < op.QueryObject.MinPrice)
                {
                    if (op.ExtensiveLoggingNeeded)
                    {
                        Logger.LogProcess("TourFactory.GetToursFromHtml tour info found but less than minprice:" + tourItem.Price);
                    }
                    continue;
                }

                if (op.QueryObject != null && (op.QueryObject.MealType == mealTypeIndex || op.QueryObject.MealType == 0))
                {
                    if (op.ExtensiveLoggingNeeded)
                    {
                        Logger.LogProcess("TourFactory.GetToursFromHtml tour info added:" + tourItem.ToString());
                    }

                    list.Add(tourItem);
                }
                else
                {
                    if (op.ExtensiveLoggingNeeded)
                    {
                        Logger.LogProcess("TourFactory.GetToursFromHtml tour info found but excluded bcz of meal type:" + mealTypeIndex);
                    }

                }
            }
            return list;
        }
示例#4
0
        protected override IList<Tour> GetToursFromHtml(IPttRequest pttRequest, IOperator op, HtmlDocument html, out TourFactoryStatus status)
        {
            status = new TourFactoryStatus { Success = true, MoveToNextHotel = false };

            if (html.DocumentNode.SelectNodes(op.TourInfo.XPath) == null)
            {
                status.MoveToNextHotel = true;
                return null;
            }

            var list = new List<Tour>();
            var hotelName = html.DocumentNode.SelectNodes("//div[@id='fs-ed-hHtl']")[0].InnerText;

            //kur degerini cek sayfadan
            //fm.rate.setRates([102,101,0.029542097489, den kuru cek, bu katsayi ile carpip dolar degerini bulmus olursun.
            double usdToRubRate = 1.0;// 0.029542097489;
            var curId = 101;
            if (op.QueryObject.Currency == "EUR") curId = 103;
            //102,101, usd rate
            //102,103, eur rate
            //var match = Regex.Match(html.DocumentNode.OuterHtml, @"setRates\(\[\d+\,\d+\,([\d\.]+)\s*", RegexOptions.IgnoreCase);
            var match = Regex.Match(html.DocumentNode.OuterHtml, @"102\," + curId + @"\,([\d\.]+)\s*", RegexOptions.IgnoreCase);
            if (match.Success)
            {
                NumberStyles style;
                style = NumberStyles.Number | NumberStyles.AllowDecimalPoint;

                string key = match.Groups[1].Value;
                double.TryParse(key, style, CultureInfo.CreateSpecificCulture("en-GB"), out usdToRubRate);
            }

            foreach (var node in html.DocumentNode.SelectNodes(op.TourInfo.XPath))
            {
                var startIndex = 0;
                var tourItem = new Tour();
                tourItem.Date = op.QueryObject.StartDate;
                var priceColIndex = 7;
                if (op.QueryObject.MinNights != op.QueryObject.MaxNights)
                {
                    priceColIndex = 9;
                }
                if (!node.ChildNodes[2 * startIndex + priceColIndex].InnerText.Contains("RUB"))//otel adi kolonu var
                {
                    startIndex = 1;
                }
                var night = node.ChildNodes[2 * startIndex + 7].InnerText;
                if (op.QueryObject.MinNights != op.QueryObject.MaxNights)
                {
                    match = Regex.Match(night, @"(\d+)\s*", RegexOptions.IgnoreCase);
                    if (match.Success)
                    {
                        tourItem.Night = match.Groups[1].Value;
                    }

                }
                else
                {
                    tourItem.Night = op.QueryObject.MinNights.ToString();
                }

                tourItem.Hotel = hotelName;

                var roomType = node.ChildNodes[2 * startIndex + 3].InnerText;
                tourItem.RoomType = roomType;

                var price = node.ChildNodes[2 * startIndex + priceColIndex].InnerText.Replace("RUB", "").Trim();
                tourItem.Price = 0;
                if (!string.IsNullOrEmpty(price))
                {
                    tourItem.Price = System.Convert.ToDouble(price, CultureInfo.GetCultureInfo("tr-TR"));
                }
                tourItem.Price = Math.Round(usdToRubRate * tourItem.Price, 0);

                var meal = node.ChildNodes[2 * startIndex + 5].InnerText;
                tourItem.Meal = meal;
                var mealTypeIndex = 7;
                var innerMealIndex = 0;
                foreach (var mealtypeAlternative in op.MealTypes)
                {
                    if (mealtypeAlternative.Contains(meal))
                    {
                        mealTypeIndex = innerMealIndex;
                        break;
                    }
                    innerMealIndex++;
                }
                tourItem.Meal = Dictionnaries.MealTypes[mealTypeIndex];

                tourItem.City = Dictionnaries.Regions[op.QueryObject.OriginId];
                tourItem.ACC = node.ChildNodes[2 * startIndex + 1].InnerText; //"DBL + 1 CHD";

                tourItem.TO = op.Name;
                tourItem.SPONo = "";
                tourItem.IssueDate = DateTime.Now;

                if (tourItem.Price > op.QueryObject.MaxPrice)
                {
                    status.MoveToNextHotel = true;
                    break;
                }

                if (op.QueryObject != null && (op.QueryObject.MealType == mealTypeIndex || op.QueryObject.MealType == 0) && (tourItem.Price >= op.QueryObject.MinPrice))
                {
                    list.Add(tourItem);
                }
            }
            return list;
        }
示例#5
0
        protected override IList<Tour> GetToursFromHtml(IPttRequest pttRequest, IOperator op, HtmlDocument html, out TourFactoryStatus status)
        {
            status = new TourFactoryStatus { Success = true, MoveToNextHotel = false };

            if (html.DocumentNode.SelectNodes(op.TourInfo.XPath) == null)
            {
                status.MoveToNextHotel = true;
                return null;
            }

            var nextPageAnchorNode = html.DocumentNode.SelectNodes(NEXT_PAGE_LINK_XPATH);
            if (nextPageAnchorNode != null)
            {
                var nextPageAnchor = nextPageAnchorNode[0];
                var hrefAttr = nextPageAnchor.Attributes[NEXT_PAGE_LINK_ATTRIBUTE];
                if (hrefAttr != null)
                {
                    status.NextPageUrl = BIBLO_URL + hrefAttr.Value;
                }
            }
            else
            {
                status.MoveToNextHotel = true;
            }

            var list = new List<Tour>();
            foreach (HtmlNode node in html.DocumentNode.SelectNodes(op.TourInfo.XPath))
            {
                if (node.FirstChild.Name.ToLower() == "th") continue;

                var tourItem = new Tour();

                tourItem.City = Dictionnaries.Regions[op.QueryObject.OriginId];
                tourItem.TO = op.Name.Replace("_", "");//anex_ gibiler icin
                tourItem.IssueDate = DateTime.Now;

                tourItem.Date = op.TourInfo.GetFieldValue<DateTime>(node, "Date");
                tourItem.Night = op.TourInfo.GetFieldValue<string>(node, "Night");
                tourItem.Hotel = op.TourInfo.GetFieldValue<string>(node, "Hotel");
                tourItem.ACC = op.QueryObject.NumberOfAdults + " AD";
                if(op.QueryObject.ChildrenAges != null && op.QueryObject.ChildrenAges.Any())
                {
                    tourItem.ACC += op.QueryObject.ChildrenAges.Count().ToString() + " CHD";
                }

                var mealTypeIndex = 7;
                tourItem.Meal = "-";
                var roomType = node.ChildNodes[5].ChildNodes[0].InnerText.Trim();
                if (roomType.Length > 2)
                {

                    var innerMealIndex = 0;
                    foreach (var mealtypeAlternative in op.MealTypes)
                    {
                        foreach (var mealType in mealtypeAlternative.OrderByDescending(a => a.Length))
                            {
                                if (roomType.EndsWith(mealType))
                                {
                                    roomType = roomType.Substring(0, roomType.Length - mealType.Length).Trim();
                                    mealTypeIndex = innerMealIndex;
                                    break;
                                }
                            }

                        innerMealIndex++;
                    }
                }
                tourItem.Meal = Dictionnaries.MealTypes[mealTypeIndex];
                tourItem.RoomType = roomType;

                tourItem.Price = 0;
                var price = node.ChildNodes[7].InnerText.Replace("*", "").Trim();//2 adult icin 2162&nbsp;&nbsp;2 ruscabiseyler geliyor bu
                if (!string.IsNullOrEmpty(price))
                {
                    if (op.QueryObject.ChildrenAges != null && op.QueryObject.ChildrenAges.Count > 0 &&
                        price.IndexOf("[") > -1)
                    {
                        //TODO: bunu degistirmisler ne idugu belirsiz...
                        price = price.Replace("&nbsp;", "");
                        var priceList = new List<string>();
                        var priceConverted = price.Replace("][", "$_$");
                        var priceConvertedPieces = priceConverted.Split(new[] { "]" },
                                                                        StringSplitOptions.RemoveEmptyEntries);
                        foreach (var priceConvertedPiece in priceConvertedPieces)
                        {
                            priceList.Add(priceConvertedPiece.Replace("$_$", "][") + "]");
                        }

                        var priceRangeValueFactory = new PriceRangeValueFactory();
                        var priceRangeValuesCalcd = priceRangeValueFactory.RangeValues(priceList);
                        var priceRangeCalculator = new PriceRangeValueCalculator(priceRangeValuesCalcd);

                        tourItem.Price = priceRangeCalculator.GetPrice(op.QueryObject.ChildrenAges);

                    }
                    else
                    {
                        var matchDouble = Regex.Match(price, @"(\d+)", RegexOptions.IgnoreCase);
                        if (matchDouble.Success)
                        {
                            price = matchDouble.Groups[1].Value;
                        }

                        tourItem.Price = Convert.ToDouble(price, CultureInfo.GetCultureInfo("tr-TR"));
                    }

                }

                if (op.QueryObject != null && tourItem.Price < op.QueryObject.MinPrice) continue;
                tourItem.SPONo = op.TourInfo.GetFieldValue<string>(node, "SPONo");
                if (op.QueryObject != null)
                {
                    if ((tourItem.Price >= op.QueryObject.MinPrice && tourItem.Price <= op.QueryObject.MaxPrice) && (tourItem.Date >= op.QueryObject.StartDate && tourItem.Date<=op.QueryObject.EndDate))
                    //                            &&(QueryObject.MealType == mealTypeIndex || QueryObject.MealType == 0)) //biblo da uyusmazliklar mevcut... ai sectiginde uai ler de geliyor....
                    {
                        list.Add(tourItem);
                    }
                }
            }
            return list;
        }