Ejemplo n.º 1
0
        private Album GetAlbum()
        {
            AlbumsResource.ListRequest request  = service.Albums.List();
            ListAlbumsResponse         response = request.Execute();

            if (response.Albums != null && response.Albums.Count > 0)
            {
                bool morePages = true;

                while (response.Albums != null && response.Albums.Count > 0 && morePages)
                {
                    foreach (var album in response.Albums)
                    {
                        string alternateAlbumTitle = albumTitle.Replace("&", "&");

                        if (album.Title.Equals(albumTitle) || album.Title.Equals(alternateAlbumTitle))
                        {
                            return(album);
                        }
                    }

                    if (response.NextPageToken != null)
                    {
                        request.PageToken = response.NextPageToken;
                        response          = request.Execute();
                    }
                    else
                    {
                        morePages = false;
                    }
                }
            }

            return(null);
        }
        /// <summary>
        /// Get the existing Google Photos Album entry.
        /// Sets the class variable 'album' as well.
        /// </summary>
        /// <returns>Album that exists, null otherwise</returns>
        private Album SetAlbum()
        {
            if (album != null)
            {
                return(album);
            }

            AlbumsResource.ListRequest request = service.Albums.List();
            //request.PageSize = 10; //Uncommenting. Let Google decide the page size.
            ListAlbumsResponse response = request.Execute();

            string alternateAlbumTitle = albumTitle.Replace("&", "&amp;");

            while (response.Albums != null && response.Albums.Count > 0)
            {
                foreach (var albumresponse in response.Albums)
                {
                    if (albumresponse != null && albumresponse.Title != null)
                    {
                        if (albumresponse.Title.Equals(albumTitle) || albumresponse.Title.Equals(alternateAlbumTitle))
                        {
                            album = albumresponse;
                            return(albumresponse);
                        }
                    }
                }

                //Fetch next page of Albums
                if (response.NextPageToken != null)
                {
                    request.PageToken = response.NextPageToken;
                    response          = request.Execute();
                }
                else
                {
                    break;
                }
            }

            return(null);
        }