public override async Task <HashSet <Restaurant> > GetRestaurants(FeedRestaurantsRequest request, Type responseType)
        {
            var htmlRestaurants = new HashSet <Restaurant>();

            foreach (string endpoint in request.Endpoints)
            {
                try
                {
                    var            doc        = new HtmlDocument();
                    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(endpoint);
                    webRequest.UserAgent = USER_AGENT_VALID;
                    var webResponse = await webRequest.GetResponseAsync();

                    doc.Load(webResponse.GetResponseStream());

                    htmlRestaurants.UnionWith(_mapper.Map <Restaurant[]>(GetDominosPizzaRestaurants(doc)));
                }
                catch (Exception)
                {
                    return(new HashSet <Restaurant>());
                }
            }

            return(htmlRestaurants);
        }
        public override async Task <HashSet <Restaurant> > GetRestaurants(FeedRestaurantsRequest request, Type responseType)
        {
            HashSet <Restaurant> localRestaurants = new HashSet <Restaurant>();

            var localRequest = request as FeedLocalRestaurantsRequest;

            var restaurantsRetrieved = await Task.Run(() => JsonConvert.DeserializeObject(localRequest.FileContent, responseType));

            Restaurant[] restaurants = _mapper.Map <Restaurant[]>(restaurantsRetrieved);

            localRestaurants.UnionWith(restaurants);

            return(localRestaurants);
        }
Esempio n. 3
0
        public override async Task <HashSet <Restaurant> > GetRestaurants(FeedRestaurantsRequest request, Type responseType)
        {
            //TODO No evita añadir repetidos
            HashSet <Restaurant> apiRestaurants = new HashSet <Restaurant>();

            var apiRequest = request as FeedApiRestaurantsRequest;

            foreach (string endpoint in apiRequest.Endpoints)
            {
                try
                {
                    HttpResponseMessage endpointResponse = await _client.GetAsync(endpoint);

                    if (endpointResponse.IsSuccessStatusCode)
                    {
                        string responseContent = await endpointResponse.Content.ReadAsStringAsync();

                        if (!String.IsNullOrEmpty(responseContent))
                        {
                            switch (apiRequest.ApiFormat)
                            {
                            case RestaurantFormat.XML:
                                apiRestaurants.UnionWith(GetXmlRestaurants(responseContent, responseType));
                                break;

                            default:
                                apiRestaurants.UnionWith(GetJsonRestaurants(responseContent, responseType));
                                break;
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    return(new HashSet <Restaurant>());
                }
            }

            return(apiRestaurants);
        }