public static SuperAvailabilityResponse Search(AccommodationSearchRequest request, Settings settings, AggregatorSetting aggregatorSetting, out int searchTime) { var availabilityRequest = GetRequest(request, aggregatorSetting, settings); var authSoapHd = new AuthSoapHd { strUserName = aggregatorSetting.PtsUserName, strNetwork = aggregatorSetting.PtsNetwork, strPassword = aggregatorSetting.PtsPassword, strUserRef = "", strCustomerIP = "" //HttpContext.Current == null ? String.Empty : (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]).Split(',')[0].Trim() }; //"http://172.16.200.174/Tritonroomswsdev/AccommodationServicev2.svc"; var service = new AccommodationService { Url = aggregatorSetting.PtsUrl, AuthSoapHdValue = authSoapHd, Timeout = aggregatorSetting.PtsTimeOut }; var stopwatch = new Stopwatch(); stopwatch.Start(); SuperAvailabilityResponse response = service.GetSuperAvailability(availabilityRequest); stopwatch.Stop(); searchTime = (int)stopwatch.ElapsedMilliseconds; return(response); }
public static void GetTransfers(Dictionary <int, decimal> transfers, SuperAvailabilityResponse superAvailabilityResponse, AggregatorSetting aggregatorSetting) { var threads = new List <ThreadWorking>(); foreach (var transfer in transfers) { var transfersRequestV3 = new TransfersRequestV3 { ClientType = 0, ConfirmationLevel = 0, ChildAge = superAvailabilityResponse.AvailabilityRequest.ChildAge, NoOfAdults = superAvailabilityResponse.AvailabilityRequest.NoOfAdults, NoOfChildren = superAvailabilityResponse.AvailabilityRequest.NoOfChildren, SvcDateFrom = superAvailabilityResponse.AvailabilityRequest.SvcDate, SvcDateTo = superAvailabilityResponse.AvailabilityRequest.SvcDate.AddDays(superAvailabilityResponse.AvailabilityRequest.Nites), LocationID = transfer.Key }; var thread = new ThreadWorking { TransferSearch = new TransferSearch(transfersRequestV3, aggregatorSetting) }; thread.Thread = new Thread(thread.TransferSearch.Search); thread.Thread.Start(); threads.Add(thread); } // join up all the threads foreach (var threadWorking in threads) { threadWorking.Thread.Join(); transfers[threadWorking.TransferSearch.Request.LocationID] = threadWorking.TransferSearch.CheapestTransferPrice; } }
public static AccommodationSearchResponse Process(Settings settings, SuperAvailabilityResponse superAvailabilityResponse, AggregatorSetting aggregatorSetting, string rooms) { if (superAvailabilityResponse == null) { return(new AccommodationSearchResponse { Message = new Message { Success = false, Errors = new List <string> { "There was no Search results returned due to an error" } }, Results = null, SearchResultSetGuid = new Guid() }); } var returnHotels = new List <AccommodationSearchResponseHotel>(); var getTheIataFromCity = (settings.LookupSettings.CityAsIata.ContainsKey((int)superAvailabilityResponse.AvailabilityRequest.CityCode) ? settings.LookupSettings.CityAsIata[(int)superAvailabilityResponse.AvailabilityRequest.CityCode] : null) ?? "-1"; var destinationMarkup = (settings.LookupSettings.DestinationMarkup.ContainsKey(getTheIataFromCity) ? settings.LookupSettings.DestinationMarkup[getTheIataFromCity] : null) ?? settings.LookupSettings.DestinationMarkup["-1"]; var transfers = new Dictionary <int, decimal>(); // loop through each hotel if (superAvailabilityResponse.SuperHotelAvailabilityDetail != null) { if (aggregatorSetting.UserName.ToLower() == "tripadvisor") { // loop through the hotels and see if there are any compulsory foreach (var hotel in superAvailabilityResponse.SuperHotelAvailabilityDetail) { foreach (var room in hotel.Hotels) { if (room.TransferCompulsory && room.HotelLocationID.HasValue && !transfers.ContainsKey(room.HotelLocationID.Value)) { transfers.Add(room.HotelLocationID.Value, -1); } } } TransferService.GetTransfers(transfers, superAvailabilityResponse, aggregatorSetting); } foreach (var hotel in superAvailabilityResponse.SuperHotelAvailabilityDetail) { int star; if (!string.IsNullOrEmpty(hotel.SuperHotelCategory) && int.TryParse(hotel.SuperHotelCategory.Substring(0, 1), out star)) { // do nothing } else { star = 0; } // convert the hotel ready var returnHotel = ConvertService.Convert(hotel, star); var hotelId = int.Parse(hotel.SuperHotelID); var hotelMarkups = settings.LookupSettings.HotelMarkup.ContainsKey(hotelId) ? settings.LookupSettings.HotelMarkup[hotelId] : null; // loop through each room foreach (var room in hotel.Hotels) { // see if we need to find out transfers // hotel markup rules if (hotelMarkups != null) { if (hotelMarkups.IsPercentageMarkup) { room.Price += (room.Price / 100m) * hotelMarkups.Markup; } else { room.Price += hotelMarkups.Markup; } } else { // now apply a destination markup foreach (var markupDestination in destinationMarkup) { if (room.Price > markupDestination.MinPriceTakesEffect) { if (markupDestination.IsPercentageMarkup) { room.Price += (room.Price / 100m) * markupDestination.Markup; } else { room.Price += markupDestination.Markup; } break; } } } // apply transfers if needed //if (room.HotelLocationID.HasValue && room.TransferCompulsory && transfers.ContainsKey(room.HotelLocationID.Value)) //{ // if (transfers[room.HotelLocationID.Value] == -1) // continue; // room.MarkupTotals.FixedTotal += transfers[room.HotelLocationID.Value];/} // round the price off room.Price = Math.Round(room.Price, 2); // convert to the object to return returnHotel.Rooms.Add(ConvertService.Convert(room, aggregatorSetting, hotel.SuperHotelID, rooms)); } if (returnHotel.Rooms.Any()) { returnHotels.Add(returnHotel); } } } var returnResult = new AccommodationSearchResponse { Message = new Message { Success = true }, Results = returnHotels, SearchResultSetGuid = superAvailabilityResponse.ResultID == null ? new Guid() : new Guid(superAvailabilityResponse.ResultID) }; return(returnResult); }
public static AccommodationSearchResponse Search(AccommodationSearchRequest accommodationSearchRequest, Settings settings) { // this so we know when we got the request var dateOfSearch = DateTime.Now; // this is so we can time how long we take to process var startOfSearch = new Stopwatch(); startOfSearch.Start(); // Check login credentials var auth = AuthenticationHelper.CheckAuth(settings, accommodationSearchRequest.Authentication); if (!auth.LoginSuccess) { // they failed to login var message = new Message { Success = false }; // add error message if there if (!String.IsNullOrEmpty(auth.Error)) { message.Errors.Add(auth.Error); } // add warning if not there if (!String.IsNullOrEmpty(auth.Warning)) { message.Warnings.Add(auth.Warning); } return(new AccommodationSearchResponse { Message = message }); } // now we need to check how many searches they have done var areWeOkToSearch = TooManySearchesHelper.CheckIfWeAreOkToSearch(auth, settings); if (!areWeOkToSearch) { TooManySearchesHelper.MinusToSearchCount(auth); throw new Exception("Speed Limit: Sorry but we have had too many searches at once please try again in a minute"); } try { //Debug.WriteLine(TooManySearchesHelper.GetCurrentSearchCount(auth)); // validate Search var errors = ValidationHelper.ValidateSearch(accommodationSearchRequest); if (errors.Count != 0) { // they failed validation var message = new Message { Success = false }; // add error messages in foreach (var error in errors) { message.Errors.Add(error); } TooManySearchesHelper.MinusToSearchCount(auth); return(new AccommodationSearchResponse { Message = message }); } var log = new AccommodationSearchLog(); // do the search var isError = false; var errorMessage = String.Empty; int timeToSearchPts = 0; SuperAvailabilityResponse ptsResults = null; try { ptsResults = PtsService.Search(accommodationSearchRequest, settings, auth, out timeToSearchPts); } catch (Exception exception) { log.ConvertSearch(accommodationSearchRequest, auth); log.StartOfSearch = dateOfSearch; log.TimeToSearchSupplier = timeToSearchPts; log.TimeToSearchTotal = (int)startOfSearch.ElapsedMilliseconds; log.NumberOfHotelResults = 0; log.Error = exception.Message; settings.LoggingSettings.AccommodationJobHost.AddLog(log); isError = true; errorMessage = exception.Message; } // process and add in mark-ups var processdResults = ProcessService.Process(settings, ptsResults, auth, accommodationSearchRequest.PassengerUrl()); if (isError) { processdResults.Message.Success = false; processdResults.Message.Errors.Add(errorMessage); } startOfSearch.Stop(); log.ConvertSearch(accommodationSearchRequest, auth); log.StartOfSearch = dateOfSearch; log.TimeToSearchSupplier = timeToSearchPts; log.TimeToSearchTotal = (int)startOfSearch.ElapsedMilliseconds; log.NumberOfHotelResults = processdResults.Results == null ? 0 : processdResults.Results.Count; settings.LoggingSettings.AccommodationJobHost.AddLog(log); TooManySearchesHelper.MinusToSearchCount(auth); return(processdResults); } catch (Exception ex) { ErrorHelper.SendErrorEmail(ex, "Error In Search", settings); TooManySearchesHelper.MinusToSearchCount(auth); throw; } }