Example #1
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;
        }
Example #2
0
 private TourFactoryControlFlags IteratingWhileGettingToursAfterTourItemSet(IPttRequest request, Tour tourItem)
 {
     return (tourItem.Price >= QueryObject.MinPrice && tourItem.Price <= QueryObject.MaxPrice) &&
            (Int32.Parse(tourItem.Night) >= QueryObject.MinNights &&
             Int32.Parse(tourItem.Night) <= QueryObject.MaxNights)
         ? TourFactoryControlFlags.Pass
         : TourFactoryControlFlags.Continue;
 }
Example #3
0
 private TourFactoryControlFlags SkipIteratingAfterTourItemSet(IPttRequest request, Tour tour)
 {
     var moveToNextHotel =(QueryObject != null && tour.Price >= QueryObject.MaxPrice+1);
     return moveToNextHotel ? TourFactoryControlFlags.MoveToNextHotel | TourFactoryControlFlags.Continue : TourFactoryControlFlags.Pass;
 }
Example #4
0
 private TourFactoryControlFlags IteratingWhileGettingToursAfterTourItemSet(IPttRequest request, Tour tourItem)
 {
     return tourItem.Price <= QueryObject.MaxPrice
         ? TourFactoryControlFlags.Pass
         : TourFactoryControlFlags.Continue;
 }
Example #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 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;
        }
Example #6
0
        private TourFactoryControlFlags IteratingWhileGettingToursAfterTourItemSet(IPttRequest request, Tour tourItem)
        {
            if (!request.SessionJar.ContainsKey("EurRate")) return TourFactoryControlFlags.Pass;
            var rate = (double)request.SessionJar["EurRate"];
            tourItem.Price = Math.Round(tourItem.Price / (double)rate, MidpointRounding.AwayFromZero);

            return tourItem.Price > QueryObject.MaxPrice ? TourFactoryControlFlags.Continue : TourFactoryControlFlags.Pass;
        }
Example #7
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;
        }