private void OnPhotoSetPhotosReturned(object sender, GetPhotoSetPhotosEventArgs e)
        {
            if (!Cinderella.CinderellaCore.PhotoSetCache.ContainsKey(e.PhotoSetId))
                return;

            PhotoSet photoset = Cinderella.CinderellaCore.PhotoSetCache[e.PhotoSetId];

            JObject rawJson = JObject.Parse(e.Response);
            JObject rootJson = (JObject)rawJson["photoset"];
            int TotalCount = 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 (!photoset.Photos.Contains(photo))
                {
                    photoset.Photos.Add(photo);
                    newPhotos.Add(photo);
                }
            }

            // Dispatch event
            PhotoSetPhotosUpdatedEventArgs evt = new PhotoSetPhotosUpdatedEventArgs();
            evt.PhotoSetId = photoset.ResourceId;
            evt.Page = page;
            evt.PageCount = numPages;
            evt.PerPage = perPage;
            evt.NewPhotos = newPhotos;
            PhotoSetPhotosUpdated.DispatchEvent(this, evt);
        }
Exemplo n.º 2
0
        // Photo stream updated
        private void OnPhotoStreamUpdated(object sender, PhotoSetPhotosUpdatedEventArgs e)
        {
            Dispatcher.BeginInvoke(() => {
                if (e.PhotoSetId != PhotoSetSource.ResourceId)
                    return;

                SystemTray.ProgressIndicator.IsVisible = false;

                if (PhotoSetSource.Photos.Count == 0)
                {
                    StatusLabel.Text = AppResources.GenericNoContentFound;
                    StatusLabel.Visibility = Visibility.Visible;
                    PhotoStreamListView.Visibility = Visibility.Collapsed;
                }
                else
                {
                    StatusLabel.Visibility = Visibility.Collapsed;
                    PhotoStreamListView.Visibility = Visibility.Visible;

                    List<PhotoGroup> newGroups = null;
                    if (PhotoCollection.Count >= 1 && PhotoCollection[0].IsHeadline)
                    {
                        newGroups = rendererFactory.GeneratePhotoGroups(e.NewPhotos);
                    }
                    else
                    {
                        newGroups = rendererFactory.GeneratePhotoGroupsWithHeadline(e.NewPhotos, PhotoSetSource.PrimaryPhoto);
                    }

                    foreach (var group in newGroups)
                    {
                        PhotoCollection.Add(group);
                    }
                }
            });
        }
        // Photo stream updated
        private void OnPhotoStreamUpdated(object sender, PhotoSetPhotosUpdatedEventArgs e)
        {
            Dispatcher.BeginInvoke(() =>
            {
                if (e.PhotoSetId != PhotoSetSource.ResourceId)
                    return;

                if (e.NewPhotos.Count == 0 && PhotoCollection.Count != 0)
                    return;

                foreach (var photo in e.NewPhotos)
                {
                    PhotoCollection.Add(photo);
                }
            });
        }