public void CreateCheapAwsomeConnectorTask(int destinationId, int nights, MyResponseDto result) { var resultAux = _hotelConnector.GetHotels(destinationId: destinationId, nights: nights); if (resultAux.hotels != null) { result.hotels.AddRange(resultAux.hotels); } }
public MyResponseDto SearchAvail(int destinationId, int nights) { var result = new MyResponseDto(); result.hotels = new List <MyHotelDto>(); try { var itemInCache = _cache.Get <MyResponseDto>("search[" + destinationId + "#" + nights + "]"); if (itemInCache != null) { return(itemInCache); } var tasks = new List <Task>(); var connectivityTask = Task.Factory.StartNew(() => CreateCheapAwsomeConnectorTask(destinationId: destinationId, nights: nights, result: result)); connectivityTask.ContinueWith(t => { }, TaskContinuationOptions.OnlyOnFaulted); tasks.Add(connectivityTask); Task.WaitAll(tasks.ToArray <Task>(), TimeSpan.FromMilliseconds(int.Parse(ConfigurationManager.AppSettings["SearchTimeOutMilliseconds"]))); if (result != null & result.hotels.Any()) { _cache.Set("search[" + destinationId + "#" + nights + "]", result); } return(result); } catch (Exception ex) { return(result); } }
public MyResponseDto getDataFromResponse(List <CheapAwsomeDto> data, int nights) { var myResponseDto = new MyResponseDto(); myResponseDto.hotels = new List <MyHotelDto>(); if (data != null) { foreach (var hotel in data) { if (hotel != null) { var myHotelDtoToAdd = new MyHotelDto(); if (!String.IsNullOrEmpty(hotel.hotel.name)) { myHotelDtoToAdd.Name = hotel.hotel.name; } else { //here we can launch a task or event to save for example in a table of warnings: "warning propertyID = id has no name", //and in another process send a sumary of warnings for example each hour continue; } myHotelDtoToAdd.hotelRates = new List <MyHotelRateDto>(); foreach (var rate in hotel.rates) { if (rate != null) { if (rate.value > 0) { var myHotelRateDtoToAdd = new MyHotelRateDto(); if (rate.rateType == "Stay") { myHotelRateDtoToAdd.price = rate.value; } else if (rate.rateType == "PerNight") { myHotelRateDtoToAdd.price = rate.value * nights; } myHotelRateDtoToAdd.boardType = rate.boardType; myHotelDtoToAdd.hotelRates.Add(myHotelRateDtoToAdd); } else { //here we can launch a task or event to save for example in a table of warnings: "warning propertyID = id has incorrect price", //and in another process send a sumary of warnings for example each hour continue; } } } if (myHotelDtoToAdd.hotelRates.Any()) { myResponseDto.hotels.Add(myHotelDtoToAdd); } else { //here we can launch a task or event to save for example in a table of warnings: "warning propertyID = id has no rates", //and in another process send a sumary of warnings for example each hour } } } } return(myResponseDto); }