// Discovery stream returned private void OnDiscoveryStreamReturned(object sender, GetDiscoveryStreamEventArgs e) { JObject rawJson = JObject.Parse(e.Response); JObject rootJson = (JObject)rawJson["photos"]; TotalDiscoveryPhotosCount = int.Parse(rootJson["total"].ToString()); int page = int.Parse(rootJson["page"].ToString()); int numPages = int.Parse(rootJson["pages"].ToString()); int perPage = int.Parse(rootJson["perpage"].ToString()); List<Photo> newPhotos = new List<Photo>(); foreach (var entry in rootJson["photo"]) { JObject json = (JObject)entry; Photo photo = PhotoFactory.PhotoWithJObject(json); if (!DiscoveryList.Contains(photo)) { DiscoveryList.Add(photo); newPhotos.Add(photo); } } // Dispatch event DiscoveryStreamUpdatedEventArgs args = new DiscoveryStreamUpdatedEventArgs(); args.Page = page; args.PageCount = numPages; args.PerPage = perPage; args.NewPhotos = newPhotos; DiscoveryStreamUpdated.DispatchEvent(this, args); }
// Discovery stream updated private void OnDiscoveryStreamUpdated(object sender, DiscoveryStreamUpdatedEventArgs e) { Dispatcher.BeginInvoke(() => { if (SystemTray.ProgressIndicator != null) SystemTray.ProgressIndicator.IsVisible = false; if (Cinderella.CinderellaCore.DiscoveryList.Count == 0) { StatusLabel.Visibility = Visibility.Visible; StatusLabel.Text = AppResources.GenericNoContentFound; ResultListView.Visibility = Visibility.Collapsed; } else { StatusLabel.Visibility = Visibility.Collapsed; ResultListView.Visibility = Visibility.Visible; } if (e.NewPhotos.Count == 0) return; foreach (var photo in e.NewPhotos) { if(!_photos.Contains(photo)) _photos.Add(photo); } }); }
// Discovery stream updated private void OnDiscoveryStreamUpdated(object sender, DiscoveryStreamUpdatedEventArgs e) { Dispatcher.BeginInvoke(() => { if (Cinderella.CinderellaCore.DiscoveryList.Count == 0) { StatusLabel.Text = "No photos available"; StatusLabel.Visibility = Visibility.Visible; PhotoStreamListView.Visibility = Visibility.Collapsed; return; } StatusLabel.Visibility = Visibility.Collapsed; PhotoStreamListView.Visibility = Visibility.Visible; if (e.NewPhotos.Count == 0) return; List<PhotoGroup> newGroups = null; if (PhotoCollection.Count >= 1 && PhotoCollection[0].IsHeadline) { newGroups = rendererFactory.GeneratePhotoGroups(e.NewPhotos); } else { newGroups = rendererFactory.GeneratePhotoGroupsWithHeadline(e.NewPhotos); } foreach (var group in newGroups) { PhotoCollection.Add(group); } UpdateStreamVisibility(); // Update live tiles var tilePhotos = new List<Photo>(); for (int i = 0; i < Math.Min(LiveTileUpdateService.MAX_TILE_IMAGE_COUNT, e.NewPhotos.Count); i++) { var photo = e.NewPhotos[i]; tilePhotos.Add(photo); } LiveTileUpdateService.Instance.StartNewRequests(tilePhotos); }); }