示例#1
0
        public async Task <HotelSearchCityRS> Get(string locale, string currency, string cacheKey,
                                                  string cacheLocation, string requestKey)
        {
            HotelGetMoreRQ request = new HotelGetMoreRQ
            {
                Locale        = locale,
                Currency      = currency,
                CacheKey      = cacheKey,
                CacheLocation = cacheLocation,
                RequestKey    = requestKey,
                Suppliers     = new List <string> {
                    "EAN"
                }
            };

            return(await _HotelService.HotelGetMoreAsync(request));
        }
示例#2
0
        private HotelSearchCityRS ConvertToResponse(HotelListRs rs,
                                                    HotelGetMoreRQ request)
        {
            HotelSearchCityRS response = new HotelSearchCityRS
            {
                Supplier = "EAN",
                Locale   = request.Locale,
                Currency = request.Currency,
                Hotels   = rs.HotelListResponse.HotelList.HotelSummary.ToList().Select(h =>
                                                                                       new HotelRS
                {
                    Id         = h.hotelId.ToString(),
                    Name       = h.name,
                    Address    = h.address1,
                    Latitude   = h.latitude,
                    Longitude  = h.longitude,
                    Location   = h.locationDescription,
                    ShortDesc  = h.shortDescription,
                    StarRating = (decimal)h.hotelRating,
                    Thumbnail  = h.thumbNailUrl,
                    CurrCode   = h.rateCurrencyCode,
                    RateFrom   = (decimal)h.lowRate,
                    RateTo     = (decimal)h.highRate
                }
                                                                                       ).ToList()
            };

            if (rs.HotelListResponse.moreResultsAvailable)
            {
                response.CacheKey      = rs.HotelListResponse.cacheKey;
                response.CacheLocation = rs.HotelListResponse.cacheLocation;
                response.RequestKey    = request.RequestKey;
            }

            return(response);
        }
示例#3
0
        public async Task <HotelSearchCityRS> HotelGetMoreAsync(HotelGetMoreRQ request)
        {
            if (!request.Suppliers.Contains("EAN"))
            {
                return(new HotelSearchCityRS());
            }

            _LogService = new LogService();

            if (string.IsNullOrEmpty(request.Locale))
            {
                request.Locale = "en_US";
            }

            if (string.IsNullOrEmpty(request.Currency))
            {
                request.Currency = "USD";
            }

            try
            {
                _LogService.LogInfo("EAN/HotelGetMoreRQ", request);

                var response = await SubmitAsync($"locale={request.Locale ?? "en_US"}" +
                                                 $"&currencyCode={request.Currency ?? "USD"}" +
                                                 $"&cachekey={request.CacheKey}" +
                                                 $"&cachelocation={request.CacheLocation}" +
                                                 $"&maxRatePlanCount=3",
                                                 //+     $"&includeDetails=true",
                                                 RequestType.HotelList);

                var rs = JsonConvert.DeserializeObject <HotelListRs>(response);
                HotelSearchCityRS hotelSearchCityRS = ConvertToResponse(rs, request);

                _LogService.LogInfo("EAN/HotelGetMoreRS", hotelSearchCityRS);

                //Add result to cache

                HotelSearchCityRS cacheSearchRS;

                var cacheEntryOptions = new MemoryCacheEntryOptions()
                                        // Keep in cache for this time, reset time if accessed.
                                        .SetAbsoluteExpiration(TimeSpan.FromHours(1));

                if (!_cache.TryGetValue(request.RequestKey, out cacheSearchRS))
                {
                    _cache.Set(request.RequestKey, hotelSearchCityRS, cacheEntryOptions);
                }
                else
                {
                    hotelSearchCityRS.Hotels.ForEach(hotel =>
                    {
                        if (cacheSearchRS.Hotels.FirstOrDefault(h => h.Id == hotel.Id) == null)
                        {
                            cacheSearchRS.Hotels.Add(hotel);
                        }
                    });

                    if (rs.HotelListResponse.moreResultsAvailable)
                    {
                        cacheSearchRS.CacheKey      = rs.HotelListResponse.cacheKey;
                        cacheSearchRS.CacheLocation = rs.HotelListResponse.cacheLocation;
                        cacheSearchRS.RequestKey    = request.RequestKey;
                    }

                    _cache.Set(request.RequestKey, cacheSearchRS, cacheEntryOptions);
                }
                return(hotelSearchCityRS);
            }
            catch (Exception ex)
            {
                _LogService.LogException(ex, "Ean.HotelService.HotelGetMoreAsync");
                return(new HotelSearchCityRS());
            }
            finally
            {
                _LogService = null;
            }
        }
示例#4
0
 public Task <HotelSearchCityRS> HotelGetMoreAsync(HotelGetMoreRQ request)
 {
     throw new NotImplementedException();
 }