private async Task InitializeExplorePage() { await DispatcherUtil.Dispatch(async() => { var exploreItems = new ObservableCollection <ExploreItem>(); try { var tsnList = new List <string> { "174371", "173420", "161061", "159785", "500028", "180130", "552304", "552303" }; ExploreGrid.SetBinding(ListView.ItemsSourceProperty, new Binding { Source = exploreItems }); foreach (var tsn in tsnList) { var newItem = new ExploreItem(); newItem.Loading = true; var record = await RequestManager.RequestFullRecord(tsn); newItem.Name = record.GetCommonName(); newItem.TSN = record.ScientificName.TSN; // var imageModelLow = await RequestManager.RequestWikispeciesImage(record.ScientificName.CombinedName, 50); // newItem.Image = new BitmapImage(new Uri(imageModelLow.GetThumbnail(), UriKind.Absolute)); var imageModel = await RequestManager.RequestWikispeciesImage(record.ScientificName.CombinedName, 400); newItem.Image = new BitmapImage(new Uri(imageModel.GetThumbnail(), UriKind.Absolute)); newItem.Loading = false; exploreItems.Add(newItem); } } catch (Exception e) { ContentDialog errorDialog = new ContentDialog { Title = "Error", Content = e.Message + " " + e.InnerException.ToString(), CloseButtonText = "Ok", }; ContentDialogResult result = await errorDialog.ShowAsync(); exploreItems.Clear(); Frame.Navigate(typeof(ErrorPage), null); } }); }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); var args = (TaxonPageNavigationArgs)e.Parameter; ProgressItem.IsActive = true; Task.Run(async() => { try { if (args == null) { await LoadRoot(); } else { await LoadTSN(args.TSN); } } catch { await DispatcherUtil.Dispatch(async() => { ContentDialog errorDialog = new ContentDialog { Title = "Error", Content = "The page could not be loaded", CloseButtonText = "Ok", }; ContentDialogResult result = await errorDialog.ShowAsync(); Frame.Navigate(typeof(ErrorPage), null); }); } finally { await DispatcherUtil.Dispatch(() => { ProgressItem.IsActive = false; }); } }); }
private async Task LoadTSN(string tsn) { var hierarchy = await RequestManager.RequestFullHierarchy(tsn); var currentTaxonHierarchy = hierarchy.HierarchyList.Where(x => x.TSN.Equals(tsn)).FirstOrDefault(); var currentTaxon = await RequestManager.RequestFullRecord(tsn); var image = await RequestManager.RequestWikispeciesImage(currentTaxonHierarchy.TaxonName); var imageSource = image.Query.Pages.FirstOrDefault().Value.Thumbnail?.Source; var children = new List <HierarchyItem>(); var ascending = new List <HierarchyItem>(); children = hierarchy.HierarchyList.Where(hierarchyItem => Rank.NumRankOf(currentTaxonHierarchy.RankName) < Rank.NumRankOf(hierarchyItem.RankName)).ToList(); ascending = hierarchy.HierarchyList.Where(hierarchyItem => Rank.NumRankOf(currentTaxonHierarchy.RankName) >= Rank.NumRankOf(hierarchyItem.RankName)).ToList(); await DispatcherUtil.Dispatch(() => { TheList.SetBinding(ListView.ItemsSourceProperty, new Binding { Source = children }); if (!children.Any()) { DescendingGrid.Visibility = Visibility.Collapsed; } TaxonName.Text = currentTaxonHierarchy.TaxonName; CommonName.Text = currentTaxon.GetCommonName(); RankName.Text = currentTaxonHierarchy.RankName; if (string.IsNullOrWhiteSpace(currentTaxon.Author.Authorship)) { AuthorshipLabel.Visibility = Visibility.Collapsed; AuthorshipEntry.Visibility = Visibility.Collapsed; } else { AuthorshipLabel.Visibility = Visibility.Visible; AuthorshipEntry.Visibility = Visibility.Visible; AuthorName.Text = currentTaxon.Author.Authorship; } if (imageSource != null) { TaxonImage.Source = new BitmapImage(new Uri(imageSource, UriKind.Absolute)); } var synonyms = currentTaxon.SynonymList.Synonyms .Where(x => x != null) .Select(x => new SynonymItem(x)); var synonymsCollection = new ObservableCollection <SynonymItem>(synonyms); if (synonymsCollection.Count == 0) { SynonymsList.Visibility = Visibility.Collapsed; SynonymsButton.Visibility = Visibility.Collapsed; } else { SynonymsList.Visibility = Visibility.Visible; SynonymsButton.Visibility = Visibility.Visible; SynonymsList.SetBinding(ListBox.ItemsSourceProperty, new Binding { Source = synonymsCollection }); } var pathItems = ascending.OrderBy(x => Rank.Ranks.ToList().IndexOf(x.RankName)).ToList(); TaxonPath.SetBinding(ListView.ItemsSourceProperty, new Binding { Source = pathItems }); var expertsList = currentTaxon.ExpertList.Experts.Where(x => x != null).ToList(); Experts.SetBinding(ListView.ItemsSourceProperty, new Binding { Source = expertsList }); if (expertsList.Any()) { ExpertsLabel.Visibility = Visibility.Visible; } var otherSourcesList = currentTaxon.OtherSourcesList.OtherSources.Where(x => x != null && !string.IsNullOrEmpty(x.SourceComment) && !string.IsNullOrEmpty(x.Source)).ToList(); OtherSources.SetBinding(ListView.ItemsSourceProperty, new Binding { Source = otherSourcesList }); if (otherSourcesList.Any()) { OtherSourcesLabel.Visibility = Visibility.Visible; OtherSources.Visibility = Visibility.Visible; } }); }