public void AddLog(AccommodationSearchLog log)
        {
            lock (_lock)
            {

                DataRow dr = _dt.NewRow();
                dr.BeginEdit();
                dr["Tracker"] = log.Tracker;
                dr["NumberOfRooms"] = log.NumberOfRooms;
                dr["NumberOfAdults"] = log.NumberOfAdults;
                dr["NumberOfChildren"] = log.NumberOfChildren;
                dr["NumberOfInfants"] = log.NumberOfInfants;
                dr["ChildAges"] = log.ChildAges;
                dr["MinStarRating"] = log.MinStarRating ?? 0;
                dr["CheckIn"] = log.CheckIn;
                dr["CheckOut"] = log.CheckOut;
                dr["CityCode"] = log.CityCode;
                dr["ResortCode"] = log.ResortCode;
                dr["SuperIds"] = log.SuperIds;
                dr["StartOfSearch"] = log.StartOfSearch;
                dr["TimeToSearchSupplier"] = log.TimeToSearchSupplier;
                dr["TimeToSearchTotal"] = log.TimeToSearchTotal;
                dr["NumberOfHotelResults"] = log.NumberOfHotelResults;
                dr["Error"] = log.Error;
                dr.EndEdit();
                _dt.Rows.Add(dr);

                if (_dt.Rows.Count > settings.LoggingSettings.NumberOfRowsBeforeLogging)
                {
                    new Thread(SaveAndClearLog).Start();
                }
            }
        }
Пример #2
0
        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;
            }
        }