コード例 #1
0
        //renvoie les images des favoris de l'utilsateur

        /**
         * Return favorite pictures of the user
         */
        public async Task <ImageContainer> createImageContainerFromFavorites()
        {
            ImageContainer imageContainer = new ImageContainer();
            var            client_fav     = new ImgurClient(client_id, imgur_token);
            var            endpoint       = new AccountEndpoint(client_fav);
            var            favourites     = await endpoint.GetAccountFavoritesAsync();

            for (int i = 0; i < favourites.Count(); i++)
            {
                if (favourites.ElementAt(i).GetType().ToString() == "Imgur.API.Models.Impl.GalleryImage")
                {
                    GalleryImage galleryImage = (GalleryImage)(favourites.ElementAt(i));
                    Windows.UI.Xaml.Controls.Image imgImgur = new Windows.UI.Xaml.Controls.Image();
                    imgImgur.Source = new BitmapImage(new Uri(galleryImage.Link, UriKind.Absolute));
                    imgImgur.Name   = galleryImage.Id;
                    imageContainer.AddImageSource(imgImgur);
                }
                else if (favourites.ElementAt(i).GetType().ToString() == "Imgur.API.Models.Impl.GalleryAlbum")
                {
                    GalleryAlbum galleryAlbum = (GalleryAlbum)(favourites.ElementAt(i));
                    Windows.UI.Xaml.Controls.Image imgImgur = new Windows.UI.Xaml.Controls.Image();
                    foreach (var image in galleryAlbum.Images)
                    {
                        imgImgur.Source = new BitmapImage(new Uri(image.Link, UriKind.Absolute));
                        imgImgur.Name   = image.Id;
                        imageContainer.AddImageSource(imgImgur);
                    }
                }
            }

            return(imageContainer);
        }
コード例 #2
0
        //renvoie les images associées au tag envoyé

        /**
         * This method extract images with a certain tag
         * @param tag the tag's name
         * @param nb_photos the number of pictures.
         */
        public async Task <ImageContainer> createImageContainerFromTag(string tag, int nb_photos)
        {
            ImageContainer  imageContainer  = new ImageContainer();
            GalleryEndpoint galleryEndpoint = new GalleryEndpoint(client);
            var             galleries       = await galleryEndpoint.SearchGalleryAsync(tag);

            for (int i = 0; i < nb_photos && i < galleries.Count(); i++)
            {
                if (galleries.ElementAt(i).GetType().ToString() != "Imgur.API.Models.Impl.GalleryImage")
                {
                    GalleryAlbum galleryAlbum = (GalleryAlbum)(galleries.ElementAt(i));

                    Windows.UI.Xaml.Controls.Image imgImgur = new Windows.UI.Xaml.Controls.Image();
                    if (galleryAlbum.Images.Count() > 0)
                    {
                        imgImgur.Source = new BitmapImage(new Uri(galleryAlbum.Images.ElementAt(0).Link, UriKind.Absolute));
                        imgImgur.Name   = galleryAlbum.Images.ElementAt(0).Id;
                        imageContainer.AddImageSource(imgImgur);
                    }
                }
                else
                {
                    nb_photos++;
                }
            }
            return(imageContainer);
        }
コード例 #3
0
        //IMGUR - voir ses posts
        public async void Imgur_GetPostsClick(object sender, RoutedEventArgs e)
        {
            if (ImgurApi.isConnected())
            {
                ImageContainer imgContainerImgur = await ImgurApi.createImageContainerFromPosts();

                ListViewTag_Imgur.ItemsSource = imgContainerImgur.GetImages();
                setTextBoxWarning("");
            }
            else
            {
                setTextBoxWarning("Vous n'êtes pas connecté à Imgur !");
            }
        }
コード例 #4
0
        //renvoie les images postées par l'utilisateur

        /**
         * Return pictures posted from the user
         */
        public async Task <ImageContainer> createImageContainerFromPosts()
        {
            ImageContainer imageContainer = new ImageContainer();
            var            client_fav     = new ImgurClient(client_id, imgur_token);
            var            endpoint       = new AccountEndpoint(client_fav);
            var            favourites     = await endpoint.GetImagesAsync();

            for (int i = 0; i < favourites.Count(); i++)
            {
                Imgur.API.Models.Impl.Image    galleryImage = (Imgur.API.Models.Impl.Image)(favourites.ElementAt(i));
                Windows.UI.Xaml.Controls.Image imgImgur     = new Windows.UI.Xaml.Controls.Image();
                imgImgur.Source = new BitmapImage(new Uri(galleryImage.Link, UriKind.Absolute));
                imgImgur.Name   = galleryImage.Id;
                imageContainer.AddImageSource(imgImgur);
            }
            return(imageContainer);
        }
コード例 #5
0
        /**
         * This method extract images with a certain tag
         * @param tag the tag's name
         * @param nb_photos the number of pictures.
         */
        public async Task <ImageContainer> createImageContainerFromTag(string tag, int nb_photos)
        {
            var options = new PhotoSearchOptions {
                Tags = tag, PerPage = nb_photos, Page = 1
            };
            PhotoCollection photos = await flickr.PhotosSearchAsync(options);

            ImageContainer imageContainer = new ImageContainer();

            foreach (Photo photo in photos)
            {
                Image img = new Image();
                img.Source = new BitmapImage(new Uri(photo.LargeUrl));
                img.Name   = photo.PhotoId;
                imageContainer.AddImageSource(img);
            }

            return(imageContainer);
        }
コード例 #6
0
        //boutton pour rechercher sur les 2 sites en fonction d'un tag
        public async void SearchTagClick(object sender, RoutedEventArgs e)
        {
            string tag       = "";
            int    nb_photos = 1;

            if (TextBoxTag.Text != "")
            {
                tag = TextBoxTag.Text;
            }
            if (TextBoxNb.Text != "")
            {
                nb_photos = Int32.Parse(TextBoxNb.Text);
            }
            ImageContainer imgContainerFlickr = await FlickrApi.createImageContainerFromTag(tag, nb_photos);

            ImageContainer imgContainerImgur = await ImgurApi.createImageContainerFromTag(tag, nb_photos);

            ListViewTag_Imgur.ItemsSource  = imgContainerImgur.GetImages();
            ListViewTag_Flickr.ItemsSource = imgContainerFlickr.GetImages();
        }