Ejemplo n.º 1
0
        public HotelContentRS MappingHotelInfo(HotelInformationResponse rawRs)
        {
            HotelContentRS rs = new HotelContentRS();

            //EAN warning and error
            if (rawRs.EanWsError != null)
            {
                //error! something has happened
                rs.Errors = new List<WarningAndError>();
                WarningAndError error = helper.GenerateWarningAndError(9001, rawRs.EanWsError);
                rs.Errors.Add(error);
            }
            else
            {

                rs.Hotels = new List<HDSInterfaces.Hotel>();

                HDSInterfaces.Hotel hotel = new HDSInterfaces.Hotel();
                hotel.HotelInfo = new HotelInformation();
                hotel.HotelInfo.Id = rawRs.hotelId;

                //name and address
                if (rawRs.HotelSummary != null){
                    hotel.HotelInfo.Name = rawRs.HotelSummary.name;
                    hotel.HotelInfo.Address = helper.GenerateHotelAddress(rawRs.HotelSummary);

                    //rating
                    if (rawRs.HotelSummary.hotelRatingSpecified) { hotel.HotelInfo.StarRating = rawRs.HotelSummary.hotelRating; }
                    if (rawRs.HotelSummary.tripAdvisorRatingSpecified) { hotel.HotelInfo.TripAdvisorRating = rawRs.HotelSummary.tripAdvisorRating; }
                }

                //description and information
                if (rawRs.HotelDetails != null){
                    hotel.HotelInfo.HotelDescription = rawRs.HotelDetails.propertyDescription;
                    hotel.HotelInfo.AreaInfo         = rawRs.HotelDetails.areaInformation;
                    hotel.HotelInfo.RoomInfo         = rawRs.HotelDetails.roomInformation;
                    hotel.HotelInfo.DrivingDirection = rawRs.HotelDetails.drivingDirections;
                    hotel.HotelInfo.AdditionalInfo   = rawRs.HotelDetails.propertyInformation;

                    hotel.HotelInfo.PolicyInfo = new HotelPolicy{
                                                                    PolicyDescription  = rawRs.HotelDetails.hotelPolicy,
                                                                    CheckInInstruction = rawRs.HotelDetails.checkInInstructions,
                                                                    CheckInTime        = rawRs.HotelDetails.checkInTime,
                                                                    CheckOutTime       = rawRs.HotelDetails.checkOutTime,
                                                                };
                }

                //room info
                hotel.HotelInfo.RoomInfos = new List<RoomInfo>();
                if (rawRs.RoomTypes != null) {
                    if (rawRs.RoomTypes.size > 0){
                        foreach (Expedia.HotelShoppingServiceReference.RoomType roomType in rawRs.RoomTypes.RoomType){
                            RoomInfo room = new RoomInfo{
                                                                         Id = roomType.roomTypeId,
                                                                         Code = roomType.roomCode,
                                                                         Name = roomType.description,
                                                                         Description = roomType.descriptionLong
                                                                      };
                            hotel.HotelInfo.RoomInfos.Add(room);
                        }
                    }
                }

                //amenitity
                hotel.HotelInfo.Amenities = new List<HDSInterfaces.Amenity>();
                if (rawRs.PropertyAmenities != null){
                    if (rawRs.PropertyAmenities.size > 0){
                        foreach (PropertyAmenity rawAmenitity in rawRs.PropertyAmenities.PropertyAmenity){
                            HDSInterfaces.Amenity amenity = new Amenity { Id = rawAmenitity.amenityId, Description = rawAmenitity.amenity.Trim() };
                            hotel.HotelInfo.Amenities.Add(amenity);
                        }
                    }
                }

                //images
                hotel.HotelInfo.Images = new List<HDSInterfaces.HotelImage>();
                if (rawRs.HotelImages != null){
                    if (rawRs.HotelImages.size > 0){
                        foreach (Expedia.HotelShoppingServiceReference.HotelImage rawImage in rawRs.HotelImages.HotelImage){
                            hotel.HotelInfo.Images.Add(helper.GenerateHotelImage(rawImage));
                        }
                    }
                }

                rs.Hotels.Add(hotel);
            }

            return rs;
        }
Ejemplo n.º 2
0
        private Hotel processOneHotel(XmlNode hotelNode)
        {
            try
            {
                Hotel result = new Hotel();
                result.HotelInfo = new HotelInformation();
                result.HotelInfo.Address = new Address();

                foreach (XmlNode node in hotelNode.ChildNodes)
                {

                    if (node.Name == "id") {
                        result.HotelInfo.Id = long.Parse(node.ChildNodes.Item(0).InnerText);
                    }

                    if (node.Name == "name") {
                        result.HotelInfo.Name = node.InnerText;

                        //Console.WriteLine("  Hotel Id: " + result.HotelInfo.Id + ", Name: " + result.HotelInfo.Name);
                    }

                    if (node.Name == "addr")
                    {
                        foreach (XmlNode item in node.ChildNodes)
                        {
                            if (item.Name == "line1"){
                                result.HotelInfo.Address.Street1 = item.InnerText;
                            }
                            if (item.Name == "line2"){
                                result.HotelInfo.Address.Street2 = item.InnerText;
                            }

                            if (item.Name == "city"){
                                result.HotelInfo.Address.City = new City { Name = item.InnerText };
                            }

                            if (item.Name == "state"){
                                result.HotelInfo.Address.State = new State { Code = item.Attributes.Item(0).InnerText, Name = item.Attributes.Item(1).InnerText };
                            }

                            if (item.Name == "country"){
                                result.HotelInfo.Address.Country = new Country { Code = item.Attributes.Item(0).InnerText, Name = item.Attributes.Item(1).InnerText };
                            }

                            if (item.Name == "postal"){
                                result.HotelInfo.Address.Postcode = item.InnerText;
                            }
                        }
                        //Console.WriteLine("  Address is processed");
                    }

                    if (node.Name == "latitude"){
                        result.HotelInfo.Address.Latitude = float.Parse(node.InnerText);
                    }
                    if (node.Name == "longitude"){
                        result.HotelInfo.Address.Longtitude = float.Parse(node.InnerText);
                    }

                    if (node.Name == "stars"){
                        result.HotelInfo.StarRating = float.Parse(node.InnerText);
                    }

                    if (node.Name == "airportsDesc"){
                        result.HotelInfo.AreaInfo = "Airport Description: " + node.InnerText;
                    }

                    if (node.Name == "description"){
                        result.HotelInfo.HotelDescription = node.InnerText;
                    }

                    if (node.Name == "checkInTime")
                    {
                        if (result.HotelInfo.PolicyInfo == null) { result.HotelInfo.PolicyInfo = new HotelPolicy(); }
                        result.HotelInfo.PolicyInfo.CheckInTime = node.InnerText;
                    }
                    if (node.Name == "checkOutTime"){
                        if (result.HotelInfo.PolicyInfo == null) { result.HotelInfo.PolicyInfo = new HotelPolicy(); }
                        result.HotelInfo.PolicyInfo.CheckOutTime = node.InnerText;
                    }

                    if (node.Name == "amenities")
                    {
                        result.HotelInfo.Amenities = new List<Amenity>();
                        foreach (XmlNode amenityNode in node.ChildNodes)
                        {
                            if (amenityNode.FirstChild.Name == "code")
                            {
                                Amenity amenity = new Amenity();
                                amenity.Code = amenityNode.FirstChild.InnerText;
                                if (amenitiesList.getAmenitiesCodeList.Contains(amenity.Code))
                                {
                                    amenity.Name = amenitiesList.getAmenitiesCodeList[amenity.Code].ToString();
                                    result.HotelInfo.Amenities.Add(amenity);
                                }
                                else
                                {
                                    //Console.WriteLine("  *** Amenity code NOT found: '" + amenity.Code + "'   ***");
                                }
                            }

                        }

                        //Console.WriteLine("  Amenities are processed");
                    }

                    if (node.Name == "medias")
                    {
                        result.HotelInfo.Images = new List<HotelImage>();
                        foreach (XmlNode mediaNode in node.ChildNodes)
                        {
                            HotelImage image = new HotelImage();
                            for (int i = 0; i <= mediaNode.ChildNodes.Count - 1; i++)
                            {
                                if (mediaNode.ChildNodes[i].Name == "type"){
                                    image.Code = mediaNode.ChildNodes[i].InnerText;
                                }

                                if (mediaNode.ChildNodes[i].Name == "url"){
                                    image.URL = mediaNode.ChildNodes[i].InnerText;
                                }
                            }
                            result.HotelInfo.Images.Add(image);
                        }

                        //Console.WriteLine("  Medias are processed");
                    }

                    if (node.Name == "facilities")
                    {
                        result.HotelInfo.Facilities = new List<Facility>();
                        foreach (XmlNode facilityNode in node.ChildNodes)
                        {
                            Facility facility = new Facility();
                            for (int i = 0; i <= facilityNode.ChildNodes.Count - 1; i++)
                            {
                                if (facilityNode.ChildNodes[i].Name == "type")
                                {
                                    facility.Code = facilityNode.ChildNodes[i].InnerText;
                                }

                                if (facilityNode.ChildNodes[i].Name == "desc")
                                {
                                    facility.Description = facilityNode.ChildNodes[i].InnerText;
                                }
                            }
                            result.HotelInfo.Facilities.Add(facility);
                        }

                        //Console.WriteLine("  Facilities are processed");
                    }

                    if (node.Name == "userReviews")
                    {
                        result.HotelInfo.GuestReview = new GuestReview();
                        foreach (XmlNode reviewNode in node.ChildNodes)
                        {
                            if (reviewNode.Name == "userScore")
                            {
                                result.HotelInfo.GuestReview.UserScore = float.Parse(reviewNode.InnerText);
                            }
                            if (reviewNode.Name == "numberOfReviews")
                            {
                                result.HotelInfo.GuestReview.NumberOfReviews = long.Parse(reviewNode.InnerText);
                            }
                            if (reviewNode.Name == "numberOfRecommendations")
                            {
                                result.HotelInfo.GuestReview.NumberOfRecommendations = long.Parse(reviewNode.InnerText);
                            }
                        }

                        //Console.WriteLine("  UserReviews is processed");
                    }

                    if (node.Name == "chainCode"){
                        result.HotelInfo.Chain = new Identification { Code = node.InnerText };
                    }

                }

                return result;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return null;
            }
        }
Ejemplo n.º 3
0
        public SearchResultRS MappingSearchResult(HotelListResponse rawRs, HDSRequest request)
        {
            SearchResultRS rs = new SearchResultRS();

            //EAN warning and error
            if (rawRs.EanWsError != null)
            {
                if ((rawRs.EanWsError.handling == errorHandling.RECOVERABLE) && (rawRs.EanWsError.category == errorCategory.DATA_VALIDATION)){
                    //warning about location
                    rs.Warnings = new List<WarningAndError>();
                    WarningAndError warning = helper.GenerateWarningAndError(9002, rawRs.EanWsError);
                    rs.Warnings.Add(warning);
                }
                else{
                    //error! something has happened
                    rs.Errors = new List<WarningAndError>();
                    WarningAndError error = helper.GenerateWarningAndError(9001, rawRs.EanWsError);
                    rs.Errors.Add(error);
                }
            }

            //hotels
            if (rawRs.HotelList != null)
            {
                //pagination
                if (rawRs.moreResultsAvailableSpecified){
                    rs.IsMoreResultsAvailable = rawRs.moreResultsAvailable;
                    if (rawRs.moreResultsAvailable){
                        string tempQs = request.RequestQueryString;

                        if (tempQs.Contains("&cacheKey=") && request.Session.Expedia != null)         //remove old cacheKey from request query string
                            tempQs = tempQs.Replace("&cacheKey=" + HttpUtility.UrlEncode(request.Session.Expedia.CacheKey), "");

                        if (tempQs.Contains("&cacheLocation=") && request.Session.Expedia != null)    //remove old cacheLocation from request query string
                            tempQs = tempQs.Replace("&cacheLocation=" + HttpUtility.UrlEncode(request.Session.Expedia.CacheLocation), "");

                        rs.NextPageQueryString = tempQs + "&cacheKey="      + HttpUtility.UrlEncode(rawRs.cacheKey)
                                                        + "&cacheLocation=" + HttpUtility.UrlEncode(rawRs.cacheLocation);

                        //re-create new expedia session
                        rs.Session.Expedia = new ExpediaSpecific { CacheKey = rawRs.cacheKey, CacheLocation = rawRs.cacheLocation };
                    }

                }

                //popuplate each of every hotels
                rs.Hotels = new List<HDSInterfaces.Hotel>();
                foreach (HotelSummary rawHotel in rawRs.HotelList.HotelSummary)
                {
                    bool isHotelWithRate = false;

                    HDSInterfaces.Hotel hotel = new HDSInterfaces.Hotel();

                    /* ****************** for testing ****************** */
                    //if (hotel.Id == 356393) { string breakkkkkkk = ""; }
                    /* ****************** for testing ****************** */

                    //address and location
                    hotel.HotelInfo = new HotelInformation();
                    hotel.HotelInfo.Id = rawHotel.hotelId;
                    hotel.HotelInfo.Name = rawHotel.name;

                    hotel.HotelInfo.Address = helper.GenerateHotelAddress(rawHotel);

                    //star rating
                    if (rawHotel.hotelRatingSpecified) { hotel.HotelInfo.StarRating = rawHotel.hotelRating; }
                    if (rawHotel.tripAdvisorRatingSpecified) { hotel.HotelInfo.TripAdvisorRating = rawHotel.tripAdvisorRating; }

                    //description and image
                    hotel.HotelInfo.HotelDescription = rawHotel.shortDescription;
                    hotel.HotelInfo.Images = new List<HDSInterfaces.HotelImage>();
                    hotel.HotelInfo.Images.Add(new HDSInterfaces.HotelImage { UrlThumbnail = IMAGE_URL_PREFIX + rawHotel.thumbNailUrl });

                    //rooms and rates - some expedia hotel won't have rate (but still has all other information)
                    if (rawHotel.RoomRateDetailsList != null)
                    {
                        isHotelWithRate = true;
                        hotel.Rooms = new List<HDSInterfaces.Room>();
                        foreach (RoomRateDetails rawRoom in rawHotel.RoomRateDetailsList)
                        {

                            /*
                             * room identification code - do it later
                             */

                            //room info and promotion
                            HDSInterfaces.Room room = new HDSInterfaces.Room();
                            room.Description = rawRoom.roomDescription;
                            if (rawRoom.currentAllotment > 0) { room.NumberOfRoomAvailable = rawRoom.currentAllotment; }    //as per expedia document, 0 doesn't mean unavailable :(

                            //promotion
                            if (!string.IsNullOrEmpty(rawRoom.promoDescription)) {
                                room.Promotions = new List<Promotion>();
                                room.Promotions.Add(new Promotion { Code = rawRoom.promoId, Description = rawRoom.promoDescription });
                            }

                            //room rate total and nightly
                            room.Rates = helper.GenerateRoomRate(rawRoom.RateInfo);

                            //value adds
                            if (rawRoom.ValueAdds != null){
                                room.ValueAdds = new List<RoomValueAdd>();
                                foreach (valueAdd rawValueAdd in rawRoom.ValueAdds.ValueAdd){
                                    RoomValueAdd valueAdd = new RoomValueAdd { Id = rawValueAdd.id, Description = rawValueAdd.description };
                                    room.ValueAdds.Add(valueAdd);
                                }
                            }

                            hotel.Rooms.Add(room);
                        }

                    }

                    if (isHotelWithRate)        //populate hotel only if there is at least 1 rate
                        rs.Hotels.Add(hotel);
                }
            }

            //location suggestion
            if (rawRs.LocationInfos != null){
                rs.Locations = new List<Location>();
                foreach (LocationInfo rawLocation in rawRs.LocationInfos.LocationInfo) {
                    if (rawLocation.active){
                        Location location = new Location
                        {
                            Code = rawLocation.destinationId,
                            Name = rawLocation.code,
                            Address = new Address
                            {
                                State = new State { Name = rawLocation.stateProvinceCode },
                                City = new City { Name = rawLocation.city },
                                Country = new Country { Name = rawLocation.countryName, Code = rawLocation.countryCode },
                            }
                        };
                        rs.Locations.Add(location);
                    }
                }
            }

            return rs;
        }