public static List<string> ValidateSearch(AccommodationSearchRequest accommodationSearchRequest) { var errors = new List<string>(); // first check in if (accommodationSearchRequest.CheckIn < DateTime.Now.AddDays(3)) errors.Add("Check-in must be more that 3 days from now"); // check out if (accommodationSearchRequest.CheckIn > accommodationSearchRequest.CheckOut) errors.Add("Check-in must be before checkout"); if (accommodationSearchRequest.CountryCode < 0) errors.Add("Please provide valid country code"); if (accommodationSearchRequest.CityCode < 0) errors.Add("Please provide valid city code"); if (accommodationSearchRequest.MinStarRating.HasValue) { if (accommodationSearchRequest.MinStarRating > 5) errors.Add("Min star rating can not be greater than 5"); if (accommodationSearchRequest.MinStarRating < 0) errors.Add("Min star rating can not be less than 0"); } if (accommodationSearchRequest.PassengerCount() > 10) errors.Add("The maximum number of passengers per search is 10"); if (accommodationSearchRequest.NumberOfRooms < 1 || accommodationSearchRequest.NumberOfRooms > 4) errors.Add("Number of rooms must be between 1 and 4"); if (accommodationSearchRequest.NumberOfAdults < 1) errors.Add("There must be 1 or more adults travelling"); if (accommodationSearchRequest.ChildAge != null) { var i = 0; foreach (var age in accommodationSearchRequest.ChildAge) { i++; if (age < 2) errors.Add("Child " + i + " must be 2 or older"); if (age > 16) errors.Add("Child " + i + " must be 16 or younger"); } } if (accommodationSearchRequest.NumberOfRooms > 1 && accommodationSearchRequest.ChildAge != null && accommodationSearchRequest.ChildAge.Count != 0) errors.Add("Sorry but we don't currently support more than 1 room with children"); return errors; }
public void ConvertSearch(AccommodationSearchRequest request, AggregatorSetting aggregatorSetting) { Tracker = aggregatorSetting.Tracker; NumberOfRooms = request.NumberOfRooms; NumberOfAdults = request.NumberOfAdults; NumberOfChildren = request.ChildAge == null ? 0 : request.ChildAge.Count; NumberOfInfants = request.NumberOfInfants ?? 0; if (request.ChildAge != null) { var isFirst = true; foreach (var childAge in request.ChildAge) { if (isFirst) { isFirst = false; } else { ChildAges += ","; } ChildAges += childAge; } } MinStarRating = request.MinStarRating; CheckIn = request.CheckIn; CheckOut = request.CheckOut; CountryCode = request.CountryCode; CityCode = request.CityCode; ResortCode = request.ResortCode ?? 0; if (request.SuperIds != null && request.SuperIds.Count != 0) { var isFirst = true; foreach (var superId in request.SuperIds) { if (isFirst) { isFirst = false; } else { SuperIds += ","; } SuperIds += superId; } } }
/// <summary> /// </summary> /// <param name="request"></param> /// <param name="aggregatorSetting"></param> /// <param name="settings"></param> /// <returns></returns> private static AvailabilityRequest GetRequest(AccommodationSearchRequest request, AggregatorSetting aggregatorSetting, Settings settings) { var availabilityRequest = new AvailabilityRequest { HotelId = request.SuperIds == null ? null : string.Join(",", request.SuperIds), H2H = GetH2H(request.CityCode, aggregatorSetting, settings), FeatureCode = aggregatorSetting.PtsFeatureCode, DetailLevel = 5, CityCode = request.CityCode, ConfirmationLevel = 0 }; TimeSpan ts = request.CheckOut - request.CheckIn; availabilityRequest.Nites = (sbyte)ts.Days; availabilityRequest.SvcDate = request.CheckIn; availabilityRequest.NoOfAdults = (sbyte)request.NumberOfAdults; availabilityRequest.NoOfChildren = (sbyte)(request.ChildAge == null ? 0 : request.ChildAge.Count + request.NumberOfInfants ?? 0); if (request.ResortCode.HasValue && request.ResortCode.Value > 0) availabilityRequest.Location = (int)request.ResortCode.Value; var ages = new List<sbyte>(); if (request.ChildAge != null) foreach (var i in request.ChildAge) { ages.Add((sbyte)i); } for (var i = 0; i < request.NumberOfInfants; i++) { ages.Add(1); } availabilityRequest.ChildAge = ages.ToArray(); availabilityRequest.Units = (sbyte)request.NumberOfRooms; return availabilityRequest; }
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 void ConvertSearch(AccommodationSearchRequest request, AggregatorSetting aggregatorSetting) { Tracker = aggregatorSetting.Tracker; NumberOfRooms = request.NumberOfRooms; NumberOfAdults = request.NumberOfAdults; NumberOfChildren = request.ChildAge == null ? 0 : request.ChildAge.Count; NumberOfInfants = request.NumberOfInfants ?? 0; if (request.ChildAge != null) { var isFirst = true; foreach (var childAge in request.ChildAge) { if (isFirst) isFirst = false; else ChildAges += ","; ChildAges += childAge; } } MinStarRating = request.MinStarRating; CheckIn = request.CheckIn; CheckOut = request.CheckOut; CountryCode = request.CountryCode; CityCode = request.CityCode; ResortCode = request.ResortCode ?? 0; if (request.SuperIds != null && request.SuperIds.Count != 0) { var isFirst = true; foreach (var superId in request.SuperIds) { if (isFirst) isFirst = false; else SuperIds += ","; SuperIds += superId; } } }
public AccommodationSearchResponse AccommodationSearch(AccommodationSearchRequest request) { return HotelSearch.Search(request, InitializeService.Settings); }
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; } }