예제 #1
0
        public static RedisList <Restaurant> ImportResturantData(string connectionString)
        {
            store = new RedisStore(connectionString);
            var redis = store.GetDatabase();

            var resturantsData       = File.ReadAllText("restaurants-data.json");
            var resturantsCollection = JsonConvert.DeserializeObject <Restaurant[]>(resturantsData);

            redis.KeyDelete("resturants", CommandFlags.FireAndForget);
            var redisCollection = new RedisList <Restaurant>("resturants", redis);

            double latitude  = 0;
            double longitude = 0;

            foreach (var resutarant in resturantsCollection)
            {
                if (!string.IsNullOrEmpty(resutarant.geolocation))
                {
                    var latLong = resutarant.geolocation.Split(';');
                    latitude  = double.Parse(latLong[0]);
                    longitude = double.Parse(latLong[1]);
                }

                resutarant.ResturantGeo.Latitude  = latitude;
                resutarant.ResturantGeo.Longitude = longitude;

                redisCollection.Add(resutarant);
            }

            return(redisCollection);
        }
예제 #2
0
        private static List <Restaurant> SearchResturantsWithInSpecifiedMiles(RedisList <Restaurant> restaurants, int miles)
        {
            var boundaries          = new CoordinateBoundaries(Latitude, Longitude, miles);
            var filteredRestaurants = new List <Restaurant>();

            Parallel.ForEach(restaurants, (restaurant) => {
                if ((restaurant.ResturantGeo.Latitude >= boundaries.Latitude &&
                     restaurant.ResturantGeo.Latitude <= boundaries.Latitude) &&
                    (restaurant.ResturantGeo.Longitude >= boundaries.Longitude &&
                     restaurant.ResturantGeo.Longitude <= boundaries.Longitude))
                {
                    filteredRestaurants.Add(restaurant);
                }
            });

            return(filteredRestaurants);
        }