Example #1
0
        async Task GetMonkeysAsync()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;
            try
            {
                var client = new HttpClient();
                var json   = await client.GetStringAsync("https://montemagno.com/monkeys.json");

                var all = Monkey.FromJson(json);
                Monkeys.ReplaceRange(all);
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Something is wrong",
                                                                "OH MY GOODNESS! :(", "OK");
            }
            finally
            {
                IsBusy = false;
            }
        }
Example #2
0
        async Task GetMonkeysAsync()
        {
            if (IsBusy)
            {
                return;
            }
            try
            {
                IsBusy = true;
                var monkeys = await DataService.GetMonkeysAsync();

                Monkeys.ReplaceRange(monkeys);

                Title = $"Monkey Finder ({Monkeys.Count})";
            }
            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;
            }
        }
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
        private async Task FindMonkeyClosestToCurrentLocation()
        {
            if (IsBusy || Monkeys.Count == 0)
            {
                return;
            }

            IsBusy = true;

            try
            {
                var location = await Geolocation.GetLastKnownLocationAsync() ?? await Geolocation.GetLocationAsync(new GeolocationRequest()
                {
                    DesiredAccuracy = GeolocationAccuracy.Medium,
                    Timeout         = TimeSpan.FromSeconds(GpsLocationPingTimeoutInSeconds)
                });

                var firstClosestMonkey = Monkeys.OrderBy(monkey =>
                                                         location.CalculateDistance(new Location(monkey.Latitude, monkey.Longitude), DistanceUnits.Kilometers))
                                         .First();

                await Application.Current.MainPage.DisplayAlert("Closest Monkey", $"{firstClosestMonkey.Name} at {firstClosestMonkey.Location}", "OK");
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Unable to query location: {ex.Message}");
                await Application.Current.MainPage.DisplayAlert("Error!", ex.Message, "OK");
            }
            finally
            {
                IsBusy = false;
            }
        }
		public ImagesCollectionViewController (UICollectionViewLayout layout) : base (layout)
		{
			CollectionView.ContentSize = UIScreen.MainScreen.Bounds.Size;
			CollectionView.BackgroundColor = UIColor.White;

			monkeys = Monkeys.Instance;
		}
 public MonkeysViewModel()
 {
     CreateMonkeyCollection();
     ThreeMonkeys  = Monkeys.Take(3).ToList();
     ExpandCommand = new Command <Monkey>(Expand);
     IsExpanded    = true;
 }
Example #8
0
        private void GenerateMonkeys(int amountOfMonkeys)
        {
            Random r = new Random();

            if (Id % 2 == 0)
            {
                NameList.Reverse();
            }
            for (int i = 1; i < amountOfMonkeys + 1; i++)
            {
                int    rand = r.Next(Trees.Count - 1);
                Monkey m    = new Monkey(MonkeyCounter++, NameList[i]);
                if (this.Trees[rand].Monkey != null)
                {
                    i--;
                }
                else
                {
                    m.VisitedTrees.Add(m.Hops, Trees[rand]);
                    Trees[rand].Monkey = m;
                    Monkeys.Add(m);
                    Console.WriteLine($"[{Id}]: Placing new monkey {m.Naam} with ID {m.Id} in Tree: {Trees[rand].Id}");
                    Global.Log.WriteMonkeyToImage(this, Trees[rand]);
                }
            }
        }
 void RemoveMonkey(Monkey monkey)
 {
     if (Monkeys.Contains(monkey))
     {
         Monkeys.Remove(monkey);
     }
 }
Example #10
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 #11
0
 void RemoveMonkey(Issue8833Model monkey)
 {
     if (Monkeys.Contains(monkey))
     {
         Monkeys.Remove(monkey);
     }
 }
        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;
            }
        }
        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;
            }
        }
        async Task GetClosestAsync()
        {
            if (IsBusy || Monkeys.Count == 0)
            {
                return;
            }
            try
            {
                var location = await Geolocation.GetLastKnownLocationAsync();

                if (location == null)
                {
                    location = await Geolocation.GetLocationAsync(new GeolocationRequest
                    {
                        DesiredAccuracy = GeolocationAccuracy.Medium,
                        Timeout         = TimeSpan.FromSeconds(30)
                    });
                }

                var first = Monkeys.OrderBy(m => location.CalculateDistance(
                                                new Location(m.Latitude, m.Longitude), DistanceUnits.Miles))
                            .FirstOrDefault();

                await Application.Current.MainPage.DisplayAlert("", first.Name + " " +
                                                                first.Location, "OK");
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Unable to query location: {ex.Message}");
                await Application.Current.MainPage.DisplayAlert("Error!", ex.Message, "OK");
            }
        }
        public MonkeysViewModel()
        {
            source = new List <Monkey>();
            CreateMonkeyCollection();

            selectedMonkey = Monkeys.Skip(3).FirstOrDefault();
            MonkeySelectionChanged();
        }
Example #16
0
        public Issue7924ViewModel()
        {
            _source = new List <Issue7924Model>();
            CreateMonkeyCollection();

            CurrentItem = Monkeys.Skip(3).FirstOrDefault();
            OnPropertyChanged("CurrentItem");
        }
        public MonkeysViewModel()
        {
            source = new List <Monkey>();
            CreateMonkeyCollection();

            CurrentItem = Monkeys.Skip(3).FirstOrDefault();
            OnPropertyChanged("CurrentItem");
            Position = 3;
            OnPropertyChanged("Position");
        }
        public MonkeyCollectionViewModel()
        {
            MonkeyList = new ObservableCollection <Monkey>();
            Monkeys monkeys = new Monkeys();

            foreach (Monkey m in monkeys.MonkeyList)
            {
                MonkeyList.Add(m);
            }
        }
        private void Refresh()
        {
            MonkeyList.Clear();
            Monkeys monkeys = new Monkeys();

            foreach (Monkey m in monkeys.MonkeyList)
            {
                MonkeyList.Add(m);
            }
            IsRefresh = false;
        }
        public MonkeysViewModel()
        {
            source = new List <Monkey>();
            CreateMonkeyCollection();

            selectedMonkey = Monkeys.Skip(3).FirstOrDefault();
            MonkeySelectionChanged();

            SelectedMonkeys = new ObservableCollection <object>()
            {
                Monkeys[1], Monkeys[3], Monkeys[4]
            };
        }
Example #21
0
        async void OnListViewItemTapped(object sender, SelectedItemChangedEventArgs e)
        {
            ListView lv = (ListView)sender;

            //// this assumes your List is bound to a List<Club>
            Monkeys.Add(new Monkey {
                Url = this.ToString()
            });
            Monkey monkeys = (Monkey)lv.SelectedItem;


            await Navigation.PushAsync(new MyPageDisplay(monkeys.Url.ToString(), monkeys.Name.ToString()));
        }
        private void CreateNewMonkey()
        {
            int Id = Monkeys.Count + 1;

            if (Id < MonkeyNames.Count)
            {
                Monkeys.Add(new Monkey(Id, MonkeyNames[Id]));
            }
            else
            {
                Monkeys.Add(new Monkey(Id, $"Monkey{Id}"));
            }
        }
Example #23
0
        private void AddMonkey()
        {
            var rnd = new Random();

            Monkeys.Add(new Monkey
            {
                Name     = "Monkey " + rnd.Next(1000),
                Location = new Location {
                    Latitude = 34.0 + rnd.NextDouble() / 10.0, Longitude = -118.3 + rnd.NextDouble() / 10.0
                },
                Details  = "The squirrel monkeys are the New World monkeys of the genus Saimiri. They are the only genus in the subfamily Saimirinae. The name of the genus Saimiri is of Tupi origin, and was also used as an English name by early researchers.",
                ImageUrl = "http://upload.wikimedia.org/wikipedia/commons/thumb/2/20/Saimiri_sciureus-1_Luc_Viatour.jpg/220px-Saimiri_sciureus-1_Luc_Viatour.jpg"
            });
        }
Example #24
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 #25
0
        void FilterItems(string filter)
        {
            var filteredItems = _source.Where(monkey => monkey.Name.ToLower().Contains(filter.ToLower())).ToList();

            foreach (var monkey in _source)
            {
                if (!filteredItems.Contains(monkey))
                {
                    Monkeys.Remove(monkey);
                }
                else
                {
                    if (!Monkeys.Contains(monkey))
                    {
                        Monkeys.Add(monkey);
                    }
                }
            }
        }
Example #26
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;
        }
Example #27
0
        void AddMonkeyAtPosition(SCNVector3 worldPos, nfloat rotation)
        {
            if (Monkeys == null)
            {
                Monkeys = new List <MonkeyCharacter> ();
            }

            SCNNode palmTree = CreateMonkeyPalmTree();

            palmTree.Position = worldPos;
            palmTree.Rotation = new SCNVector4(0f, 1f, 0f, rotation);
            RootNode.AddChildNode(palmTree);

            MonkeyCharacter monkey = (MonkeyCharacter)palmTree.FindChildNode("monkey", true);

            if (monkey != null)
            {
                Monkeys.Add(monkey);
            }
        }
        private void LoadItems(int pageSize = 10)
        {
            IsBusy = true;

            if (Monkeys == null)
            {
                Monkeys = new ObservableCollection <Monkey>();
            }

            for (int i = CurrentPage; i < CurrentPage + pageSize; i++)
            {
                Monkeys.Add(new Monkey()
                {
                    MonkeyId = i + 1,
                    Name     = string.Format("Monkey {0}", i + 1)
                });
            }

            CurrentPage = Monkeys.Count;
            IsBusy      = false;
        }
Example #29
0
        private void LoadMonkeys()
        {
            Monkeys.Add(new Monkey {
                Name     = "Baboon",
                Location = new Location {
                    Latitude = 34.027897, Longitude = -118.301869
                },
                Details  = "Baboons are African and Arabian Old World monkeys belonging to the genus Papio, part of the subfamily Cercopithecinae.",
                ImageUrl = "http://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/Papio_anubis_%28Serengeti%2C_2009%29.jpg/200px-Papio_anubis_%28Serengeti%2C_2009%29.jpg"
            });

            Monkeys.Add(new Monkey {
                Name     = "Capuchin Monkey",
                Location = new Location {
                    Latitude = 34.047797, Longitude = -118.321869
                },
                Details  = "The capuchin monkeys are New World monkeys of the subfamily Cebinae. Prior to 2011, the subfamily contained only a single genus, Cebus.",
                ImageUrl = "http://upload.wikimedia.org/wikipedia/commons/thumb/4/40/Capuchin_Costa_Rica.jpg/200px-Capuchin_Costa_Rica.jpg"
            });

            Monkeys.Add(new Monkey {
                Name     = "Blue Monkey",
                Location = new Location {
                    Latitude = 34.007897, Longitude = -118.300069
                },
                Details  = "The blue monkey or diademed monkey is a species of Old World monkey native to Central and East Africa, ranging from the upper Congo River basin east to the East African Rift and south to northern Angola and Zambia",
                ImageUrl = "http://upload.wikimedia.org/wikipedia/commons/thumb/8/83/BlueMonkey.jpg/220px-BlueMonkey.jpg"
            });


            Monkeys.Add(new Monkey {
                Name     = "Squirrel Monkey",
                Location = new Location {
                    Latitude = 34.107897, Longitude = -118.292869
                },
                Details  = "The squirrel monkeys are the New World monkeys of the genus Saimiri. They are the only genus in the subfamily Saimirinae. The name of the genus Saimiri is of Tupi origin, and was also used as an English name by early researchers.",
                ImageUrl = "http://upload.wikimedia.org/wikipedia/commons/thumb/2/20/Saimiri_sciureus-1_Luc_Viatour.jpg/220px-Saimiri_sciureus-1_Luc_Viatour.jpg"
            });
        }
        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
            });
        }