Пример #1
0
 /// <summary>
 /// This will put an entry into the logs with level INFO and then save the payload into
 /// a file. The filename will appear in the main log for reference.
 /// </summary>
 public void InfoPayload(string providerName, string methodName, Func <string> payload)
 {
     using (var acl = new ApiCallLogger(providerName, methodName))
     {
         acl.LogResponse(payload);
     }
 }
Пример #2
0
        public HotelAvailabilityProviderRes Execute(HotelAvailabilityProviderReq request)
        {
            Logger.Instance.LogFunctionEntry(this.GetType().Name, "Execute");
            Availability avail  = new Availability();
            List <Hotel> hotels = new List <Hotel>();

            if (request.CheckInDate <= DateTime.Today)
            {
                throw new ArgumentOutOfRangeException(nameof(request.CheckInDate));
            }
            if (request.CheckInDate >= request.CheckOutDate)
            {
                throw new ArgumentOutOfRangeException(nameof(request.CheckOutDate));
            }
            if (request.TotalAdults < HotelBedsConstants.TotalAdults)
            {
                throw new ArgumentOutOfRangeException(nameof(request.TotalAdults));
            }
            //Check if #of nights are more than 30, if so throw exception
            var duration = (request.CheckOutDate - request.CheckInDate).TotalDays;

            if (duration > HotelBedsConstants.NightsDuration)
            {
                throw new ArgumentOutOfRangeException(nameof(duration));
            }

            HotelAvailabilityProviderRes hotelSearchResults;

            using (var hotelBedsworker = new HotelBedsWorker())
            {
                //convert the request dto to the HotelBeds search api payload
                AvailabilityRQ hotelBedsSearchRq = ConvertToHotelBedsSearchRequest(request);

                try
                {
                    var xmlRequest = HotelBedsSerialize.Serialize <HotelAvailabilityProviderReq>(request);
                    var provider   = "HotelBeds";
                    using (var apiCallLogger = new ApiCallLogger(provider, xmlRequest, true, "xml"))
                    {
                        apiCallLogger.LogRequest(
                            () => xmlRequest);
                    }
                    var hotelBedsHotels = hotelBedsworker.GetAvailability <AvailabilityRQ, AvailabilityRS>(hotelBedsSearchRq);
                    //Check if we need to check .hotels == null
                    if (hotelBedsHotels.hotels.hotels == null)
                    {
                        //throw new ProviderUnavailableException(ProviderTypes.HotelBeds.ToString(), $"No response to {nameof(AvailabilityRQ)}.", null);
                        throw new ProviderUnavailableException(ProviderTypes.HotelBeds.ToString(), hotelBedsHotels.error.message.ToString(), null);
                    }
                    hotelSearchResults = ConvertToProviderResponse(hotelBedsHotels);
                    var xmlResponse = HotelBedsSerialize.Serialize <HotelAvailabilityProviderRes>(hotelSearchResults);
                    using (var apiCallLogger = new ApiCallLogger(provider, xmlResponse, true, "xml"))
                    {
                        apiCallLogger.LogResponse(
                            () => xmlResponse);
                    }
                }
                catch (HotelBedsProviderException e)
                {
                    if (e.HasKnownError(HotelBedsProviderException.HotelKnownError.NoListings))
                    {
                        hotelSearchResults = new HotelAvailabilityProviderRes();
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            Logger.Instance.LogFunctionExit(this.GetType().Name, "Execute");
            return(hotelSearchResults);
        }