public void LoadRestaurants()
        {
            ClearMap();
            ProgressBarVisibility = Visibility.Visible;
            Restaurants.Clear();

            Deployment.Current.Dispatcher.BeginInvoke(async() =>
            {
                Geolocator geolocator = new Geolocator();
                geolocator.DesiredAccuracyInMeters = 100;

                try
                {
                    Geoposition geoPosition = await geolocator.GetGeopositionAsync(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(60));
                    _gpsLocation            = new GeoCoordinate(geoPosition.Coordinate.Latitude, geoPosition.Coordinate.Longitude);

                    _googleApiService.SendGetPlacesRequest(geoPosition.Coordinate.Latitude, geoPosition.Coordinate.Longitude, 2000, "pizza,pizzeria");
                }
                catch (Exception)
                {
                    ProgressBarVisibility = Visibility.Collapsed;
                    MessageBox.Show("Błąd podczas pobierania lokalizacji. Sprawdź ustawienia telefonu.");
                }
            });
        }
        async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Restaurants.Clear();
                var restaurants = await DataStore.GetItemsAsync(true);

                foreach (var restaurant in restaurants)
                {
                    Restaurants.Add(restaurant);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
示例#3
0
 private static void LoadRestsFromFile()
 {
     Restaurants.Clear();
     try
     {
         Restaurants =
             JsonConvert.DeserializeObject <ObservableCollection <Restaurant> >(File.ReadAllText(RestsDB, Encoding.Default))
             ?? new ObservableCollection <Restaurant>();
     }
     catch (JsonReaderException)
     {
         new Alert("Неверный формат файла", "Файл должен быть в формате JSON").Show();
         RestsDB = Path.Combine(Environment.CurrentDirectory, "data\\rests.txt");
     }
 }
示例#4
0
 public async Task DisplayResults()
 {
     var source = _cancellationTokens.AddAndReturn(new CancellationTokenSource());
     await Task.Factory.StartNew(() =>
     {
         _dataService.CuisineType = CuisineType;
         var restaurants          = _dataService.listOfRestaurants().Result;
         if (!source.Token.IsCancellationRequested)
         {
             DispatcherWrapper.Current().Dispatch(() =>
             {
                 Restaurants.Clear();
                 foreach (var restaurant in restaurants)
                 {
                     Restaurants.Add(restaurant);
                 }
             });
         }
     }, source.Token);
 }
示例#5
0
        //public override async Task OnNavigatedToAsync(object parameter, navigationmode mode, idictionary<string, object> state)
        //{
        //    // defaults
        //    price1checked = true;
        //    price2checked = true;
        //    star2checked = true;
        //    star3checked = true;
        //    selectedcuisine = "indian";
        //    distance = 1;
        //    await searchasync();
        //}

        public async Task SearchAsync()
        {
            var source = _cancellationTokens.AddAndReturn(new CancellationTokenSource());
            await Task.Factory.StartNew(async() =>
            {
                // TODO: convert distance number to kilos
                var restaurants = await _dataService.GetReataurantsAsync();
                if (!source.Token.IsCancellationRequested)
                {
                    DispatcherWrapper.Current().Dispatch(() =>
                    {
                        Restaurants.Clear();
                        foreach (var restaurant in restaurants)
                        {
                            Restaurants.Add(restaurant);
                        }
                    });
                }
            }, source.Token);
        }