Inheritance: PagedPhotoCollection, IFlickrParsable
        private PhotosetPhotoCollection GetPhotosetPhotos(string photosetID, Flickr flickr)
        {
            PhotosetPhotoCollection photos = new PhotosetPhotoCollection();

            PhotoSearchOptions options = GetPhotoSearchOptions();

            Flickr.CacheDisabled = true;

            photos = flickr.PhotosetsGetPhotos(photosetID);

            return photos;
        }
Exemplo n.º 2
0
        public DomainPhotos Convert(PhotosetPhotoCollection photosetPhotos)
        {
            if (photosetPhotos == null)
                return null;

            var domainPhotos = photosetPhotos
                .Select(photo => new DomainPhoto(
                                     photo.PhotoId, photo.UserId, photo.OwnerName, string.IsNullOrEmpty(photo.PathAlias) ? photo.UserId : photo.PathAlias,
                                     photo.Title, photo.WebUrl,
                                     photo.SmallUrl, photo.SmallWidth ?? 240, photo.SmallHeight ?? 240,
                                     IsLicensed(photo)))
                .ToList();
            return new DomainPhotos(domainPhotos, photosetPhotos.Page, photosetPhotos.Pages);
        }
Exemplo n.º 3
0
        public DomainPhotos Convert(PhotosetPhotoCollection photosetPhotos)
        {
            if (photosetPhotos == null)
                return null;

            var domainPhotos = photosetPhotos
                .Select(photo => new DomainPhoto(
                                     photo.PhotoId, photo.UserId, photo.OwnerName, string.IsNullOrEmpty(photo.PathAlias) ? photo.UserId : photo.PathAlias,
                                     photo.Title, photo.WebUrl,
                                     photo.Medium640Url, photo.Medium640Width ?? 640, photo.Medium640Width ?? 640,
                                     photo.IsLicensed(), photo.DateTaken, photo.Views))
                .ToList();

            return new DomainPhotos(domainPhotos, photosetPhotos.Page, photosetPhotos.Pages);
        }
Exemplo n.º 4
0
        // Background worker task to search selected photosets.
        private void BGDownloadPhotosets(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = (BackgroundWorker)sender;

            worker.ReportProgress(0, "Connecting");

            PhotoList = new SortableBindingList <Photo>();

            // Count the number of enabled photosets, so we can do an estimate of percent complete;
            int enabledPhotosets = 0;

            foreach (Photoset photoset in PhotosetList)
            {
                if (photoset.EnableSearch)
                {
                    enabledPhotosets++;
                }
            }

            if (enabledPhotosets == 0)
            {
                // No photosets are enabled. We are done.
                return;
            }

            try
            {
                int indexPhotoset = 0;

                FlickrNet.Flickr f = FlickrManager.GetFlickrAuthInstance();
                if (f == null)
                {
                    BGErrorMessage = "You must authenticate before you can download data from Flickr.";
                    return;
                }

                // Iterate over the photosets and get the photos from each set.
                FlickrNet.PhotosetPhotoCollection photoCollection = new FlickrNet.PhotosetPhotoCollection();

                foreach (Photoset photoset in PhotosetList)
                {
                    if (worker.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }

                    if (photoset.EnableSearch)
                    {
                        int    percent     = indexPhotoset * 100 / enabledPhotosets;
                        string description = "Searching Album " + photoset.Title;
                        worker.ReportProgress(percent, description);

                        int page    = 1;
                        int perpage = 500;
                        do
                        {
                            if (worker.CancellationPending) // See if cancel button was pressed.
                            {
                                e.Cancel = true;
                                return;
                            }

                            photoCollection = f.PhotosetsGetPhotos(photoset.PhotosetId, SearchExtras, page, perpage);
#if false
                            // It is not clear from the documentation whether the limit of 4000 photos per search applies
                            // to album searches. If an album has more than 4000 photos, is the result of GetPhotos
                            // accurate? I'm going to assume for now that it is. If not, you can enable this code.
                            if (photoCollection.Total > 3999)
                            {
                                BGErrorMessage = $"Too many photos: {photoCollection.Total}";
                                return;
                            }
#endif
                            foreach (FlickrNet.Photo flickrPhoto in photoCollection)
                            {
                                AddPhotoToList(f, flickrPhoto, photoset);
                            }
                            // Calculate percent complete based on both how many photo sets we have completed,
                            // plus how many pages we have read
                            percent = (indexPhotoset * 100 + page * 100 / photoCollection.Pages) / enabledPhotosets;
                            worker.ReportProgress(percent, description);
                            page = photoCollection.Page + 1;
                        }while (page <= photoCollection.Pages);

                        indexPhotoset++;
                    }
                }
            }
            catch (FlickrNet.FlickrException ex)
            {
                BGErrorMessage = "Search failed. Error: " + ex.Message;
                return;
            }

            DownloadFiles(sender, e);
        }