Beispiel #1
0
        // GET api/PopularBeers
        public async Task <List <BeerItem> > Get(double longitude, double latitude)
        {
            //Find the current country of the user
            string bingKey;

            if (!(Services.Settings.TryGetValue("BING_API_KEY", out bingKey)))
            {
                Services.Log.Error("Could not retrieve Bing API key.");
                bingKey = "AlPB42X199-b_n7tnHPSNM15E4cvLv18hfj4upv3irWgSFHx5GplSaOS3wpggCox";
            }
            Services.Log.Info($"Bing API Key{bingKey}");

            string countryRegion;
            var    client = new Bing.MapsClient(bingKey);
            var    result = await client.LocationQuery(new Bing.Maps.Point(latitude, longitude));

            var locations = result.GetLocations();

            if (locations.Count != 0)
            {
                countryRegion = result.GetLocations().First().Address.CountryRegion;

                Services.Log.Info($"A user is has just been seen in {countryRegion}");
            }
            else
            {
                Services.Log.Error("Failed to lookup country. Results returned as null");
            }



            var context  = new BeerDrinkinContext();
            var beerList = new List <BeerItem>();

            //Setup BreweryDB Client
            if (string.IsNullOrEmpty(BreweryDBClient.ApplicationKey))
            {
                string apiKey;
                // Try to get the BreweryDB API key  app settings.
                if (!(Services.Settings.TryGetValue("BREWERYDB_API_KEY", out apiKey)))
                {
                    Services.Log.Error("Could not retrieve BreweryDB API key.");
                    return(null);
                }
                Services.Log.Info($"BreweryDB API Key {apiKey}");
                BreweryDBClient.Initialize(apiKey);
            }



            return(beerList);
        }
        // GET api/PopularBeers
        public async Task<List<BeerItem>> Get(double longitude, double latitude)
        {
            //Find the current country of the user
            string bingKey;
            if (!(Services.Settings.TryGetValue("BING_API_KEY", out bingKey)))
            {
                Services.Log.Error("Could not retrieve Bing API key.");
                bingKey = "AlPB42X199-b_n7tnHPSNM15E4cvLv18hfj4upv3irWgSFHx5GplSaOS3wpggCox";
            }
            Services.Log.Info($"Bing API Key{bingKey}");

            string countryRegion;
            var client = new Bing.MapsClient(bingKey);
            var result = await client.LocationQuery(new Bing.Maps.Point(latitude, longitude));
            var locations = result.GetLocations();

            if(locations.Count != 0)
            {
                countryRegion = result.GetLocations().First().Address.CountryRegion;

                Services.Log.Info($"A user is has just been seen in {countryRegion}");
            }
            else
            {
                Services.Log.Error("Failed to lookup country. Results returned as null");
            }
                        


            var context = new BeerDrinkinContext();
            var beerList = new List<BeerItem>();
            
            //Setup BreweryDB Client 
            if (string.IsNullOrEmpty(BreweryDBClient.ApplicationKey))
            {
                string apiKey;
                // Try to get the BreweryDB API key  app settings.  
                if (!(Services.Settings.TryGetValue("BREWERYDB_API_KEY", out apiKey)))
                {
                    Services.Log.Error("Could not retrieve BreweryDB API key.");
                    return null;
                }
                Services.Log.Info($"BreweryDB API Key {apiKey}");
                BreweryDBClient.Initialize(apiKey);
            }

          
           
            return beerList;
        }
        private void ProcessCinemaInfo(Dictionary <int, CinemaInfo> currentCinemas, Dictionary <int, List <FilmInfo> > cinemaFilms, Dictionary <int, FilmInfo> Films, RegionDef region)
        {
            CineworldService cws      = new CineworldService();
            Cinemas          cinemas  = null;
            Task <Cinemas>   tcinemas = cws.GetCinemas(region, true);

            tcinemas.Wait();

            if (!tcinemas.IsFaulted && tcinemas.Result != null)
            {
                cinemas = tcinemas.Result;
            }

            CineMobileService mobileService = new CineMobileService();

            //foreach (var cinema in cinemas.cinemas)
            for (int i = 0; i < cinemas.cinemas.Count; i++)
            {
                //if (i > 1)
                //    break;

                var cinema = cinemas.cinemas[i];

                //if (cinema.id != 91)
                //    continue;

                Task <Films> tf = cws.GetFilms(region, false, cinema.id);

                Task <List <CinemaReview> > tReviews = mobileService.GetCinemaReviews(cinema.id);

                if (!currentCinemas.ContainsKey(cinema.id))
                {
                    CinemaInfo ci = new CinemaInfo()
                    {
                        Address   = cinema.address,
                        ID        = cinema.id,
                        Name      = cinema.name,
                        Postcode  = cinema.postcode,
                        Telephone = cinema.telephone
                    };

                    if (this.LatitudeDictionary.ContainsKey(cinema.id) && this.LongitudeDictionary.ContainsKey(cinema.id))
                    {
                        ci.Latitude  = this.LatitudeDictionary[cinema.id];
                        ci.Longitute = this.LongitudeDictionary[cinema.id];
                    }
                    else
                    {
                        Bing.MapsClient mapClient = new Bing.MapsClient("At7qhfJw20G5JptEm0fdIaMehzBAU6GT4jJRpznGY_rdPRa5NquCN5GP8bzzdG0d", "en-GB");
                        var             tLocation = mapClient.LocationQuery(
                            new Bing.Maps.Address()
                        {
                            AddressLine   = cinema.address,
                            PostalCode    = cinema.postcode,
                            CountryRegion = (region == RegionDef.GB ? "United Kingdom" : "Ireland")
                        });

                        tLocation.Wait();

                        Bing.Maps.Location location = null;

                        try
                        {
                            if (!tLocation.IsFaulted && tLocation.Result != null)
                            {
                                location = tLocation.Result.GetLocations().FirstOrDefault();
                            }
                        }
                        catch { }

                        if (location != null && location.Point != null && location.Point.Coordinates.Length == 2)
                        {
                            ci.Latitude  = location.Point.Coordinates[0];
                            ci.Longitute = location.Point.Coordinates[1];
                        }
                    }

                    tReviews.Wait();
                    if (!tReviews.IsFaulted && tReviews.Result != null)
                    {
                        ci.Reviews = tReviews.Result;
                    }

                    currentCinemas[cinema.id] = ci;
                }

                tf.Wait();

                if (!tf.IsFaulted && tf.Result != null)
                {
                    List <FilmInfo> cFilms = new List <FilmInfo>();
                    foreach (var film in tf.Result.films)
                    {
                        if (!Films.ContainsKey(film.edi))
                        {
                            continue;
                        }

                        FilmInfo fi = new FilmInfo()
                        {
                            EDI = film.edi, Title = film.CleanTitle
                        };
                        fi.ShowingToday = true;

                        cFilms.Add(fi);
                    }
                    cinemaFilms[cinema.id] = cFilms;
                }
            }
        }