async Task GetMonkeysAsync()
        {
            if (IsBusy)
            {
                return;
            }

            try
            {
                IsBusy = true;

                var monkeys = await DataService.GetMonkeysAsync();

                Monkeys.Clear();
                foreach (var monkey in monkeys)
                {
                    Monkeys.Add(monkey);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Unable to get monkeys: {ex.Message}");
                await Application.Current.MainPage.DisplayAlert("Error!", ex.Message, "OK");
            }
            finally
            {
                IsBusy = false;
            }
        }
        private async Task GetMonkeysAsync()
        {
            if (IsBusy)
            {
                return;
            }

            try
            {
                IsBusy = true;

                var json = await Client.GetStringAsync("https://montemagno.com/monkeys.json");

                var monkeys = Monkey.FromJson(json);

                Monkeys.Clear();
                foreach (var monkey in monkeys)
                {
                    Monkeys.Add(monkey);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Unable to get monkeys: {ex.Message}");
                await Application.Current.MainPage.DisplayAlert("Error!", ex.Message, "OK");
            }
            finally
            {
                IsBusy = false;
            }
        }
        async Task GetMonkeysAsync()
        {
            if (IsBusy)
            {
                return;
            }

            try
            {
                IsBusy = true;

                var json = await Client.GetStringAsync("https://montemagno.com/monkeys.json");

                var monkeys = Monkey.FromJson(json);

                //var result = await Data.ListAsync<Monkey>(DefaultPartitions.AppDocuments);
                //var monkeys = result.CurrentPage.Items.Select(m => m.DeserializedValue);

                Monkeys.Clear();
                foreach (var monkey in monkeys)
                {
                    Monkeys.Add(monkey);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Unable to get monkeys: {ex.Message}");
                await Application.Current.MainPage.DisplayAlert("Error!", ex.Message, "OK");
            }
            finally
            {
                IsBusy = false;
            }
        }
Example #4
0
        private async Task GetMonkeysAsync()
        {
            if (IsBusy)
            {
                return;
            }

            try
            {
                IsBusy = true;

                var result = await Data.ListAsync <Monkey>(DefaultPartitions.AppDocuments);

                var monkeys = result.CurrentPage.Items.Select(monkey => monkey.DeserializedValue);

                Monkeys.Clear();

                monkeys.Aggregate(Monkeys, (collection, monkey) =>
                {
                    collection.Add(monkey);
                    return(collection);
                });

                Monkeys.Add(Monkey.GenerateGoofyMonkey());
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Unable to get monkeys: {ex.Message}");
                await Application.Current.MainPage.DisplayAlert("Error!", ex.Message, "OK");
            }
            finally
            {
                IsBusy = false;
            }
        }
Example #5
0
        public async Task GetMonkeysAsync()
        {
            if (IsBusy)
            {
                return;
            }

            try
            {
                IsBusy = true;
                Monkeys.Clear();

                IDataStore service = DependencyService.Get <IDataStore>();
                var        list    = await service.GetMonkeysAsync();

                foreach (var item in list)
                {
                    Monkeys.Add(item);
                }
            }
            catch (Exception ex)
            {
                MessagingCenter.Send(ex, "error");
            }
            finally
            {
                IsBusy = false;
            }
        }
Example #6
0
        async Task AzureSearch(string text)
        {
            Monkeys.Clear();

            var searchResults = await indexClient.Documents.SearchAsync <Monkey>(text);

            foreach (SearchResult <Monkey> result in searchResults.Results)
            {
                Monkeys.Add(new Monkey
                {
                    Name     = result.Document.Name,
                    Location = result.Document.Location,
                    Details  = result.Document.Details,
                    ImageUrl = result.Document.ImageUrl
                });
            }
        }
Example #7
0
        public async Task LoadMonkeys()
        {
            IsBusy = true;
            Monkeys.Clear();

            var dataManager = App.MonkeyDataManager;

            var monkeys = await dataManager.GetMonkeysAsync();

            foreach (var item in monkeys)
            {
                var imageFiles = await dataManager.GetImageFiles(item);

                // Display only the photo files
                if (imageFiles != null && imageFiles.Count() > 0)
                {
                    var monkeyVm = new MonkeyViewModel(item);
                    monkeyVm.PhotoUrl = fileHelper.GetLocalFilePath(
                        item.Id, imageFiles.First().Name);

                    Monkeys.Add(monkeyVm);
                }
                IsBusy = false;
            }

            //var collection = new ObservableCollection<MonkeyViewModel>();

            //collection.Add(new MonkeyViewModel(new Models.Monkey
            //{
            //    UserName = "******",
            //    Status = "Chilling out in Malaysia",
            //    PhotoUrl = "http://photos1.meetupstatic.com/photos/event/8/f/d/6/600_343476822.jpeg"
            //}));
            //collection.Add(new MonkeyViewModel(new Models.Monkey
            //{
            //    UserName = "******",
            //    Status = "Wooh! Got boxed",
            //    PhotoUrl = "http://photos1.meetupstatic.com/photos/event/8/f/d/6/600_343476822.jpeg"
            //}));

            // monkeys = collection;
        }
        private void RefreshData()
        {
            IsRefreshing = true;

            ServicePointManager.ServerCertificateValidationCallback +=
                (sender, certificate, chain, sslPolicyErrors) => true;

            var API_URL = "https://localhost:5001/monkeys";
            var client  = new RestClient(API_URL)
            {
                Timeout = -1
            };
            var request = new RestRequest(Method.GET);

            IRestResponse response = client.Execute(request);

            List <Monkey> remoteMonkeys = JsonConvert.DeserializeObject <List <Monkey> >(response.Content);

            Monkeys.Clear();

            remoteMonkeys.ForEach(monkey => Monkeys.Add(monkey));

            IsRefreshing = false;
        }
        void UpdateData()
        {
            Monkeys.Clear();

            Monkeys.Add(new Monkey
            {
                Index    = "0",
                Name     = "Howler Monkey",
                Location = "South America",
                Details  = "Howler monkeys are among the largest of the New World monkeys. Fifteen species are currently recognised. Previously classified in the family Cebidae, they are now placed in the family Atelidae.",
                Image    = "http://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Alouatta_guariba.jpg/200px-Alouatta_guariba.jpg",
                Color    = Color.Aqua
            });

            Monkeys.Add(new Monkey
            {
                Index    = "1",
                Name     = "Japanese Macaque",
                Location = "Japan",
                Details  = "The Japanese macaque, is a terrestrial Old World monkey species native to Japan. They are also sometimes known as the snow monkey because they live in areas where snow covers the ground for months each",
                Image    = "http://upload.wikimedia.org/wikipedia/commons/thumb/c/c1/Macaca_fuscata_fuscata1.jpg/220px-Macaca_fuscata_fuscata1.jpg",
                Color    = Color.OrangeRed
            });
        }
 void ClearData() => Monkeys.Clear();