Exemple #1
0
        private static void UploadFromWebTest(ImgurUtils imgur)
        {
            try
            {
                Console.WriteLine("\n=================================================\n" +
                                  "    Upload an image from the web" +
                                  "\n=================================================\n");

                Console.WriteLine("Please type the URL for the direct link:");
                var link = Console.ReadLine();

                Console.WriteLine("\nPlease give the image a title:");
                var title = Console.ReadLine();

                Console.WriteLine("\nPlease give the image a description:");
                var desc = Console.ReadLine();

                Console.WriteLine("\nType an album ID if you want to add it to an album:");
                var albId = Console.ReadLine();

                DumpImageInfo(imgur.UploadImageFromWeb(link, title, desc, albId));
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nERROR: " + ex.Message);
            }
        }
Exemple #2
0
        private static void UploadFromFileTest(ImgurUtils imgur)
        {
            try
            {
                Console.WriteLine("\n===============================================\n" +
                                  "    Upload an image from a file" +
                                  "\n===============================================\n");

                Console.WriteLine("Please type the file path for the image:");
                var path = Console.ReadLine();

                Console.WriteLine("\nPlease give the image a title:");
                var title = Console.ReadLine();

                Console.WriteLine("\nPlease give the image a description:");
                var desc = Console.ReadLine();

                Console.WriteLine("\nType an album ID if you want to add it to an album:");
                var albId = Console.ReadLine();

                DumpImageInfo(imgur.UploadImageFromFile(path, title, desc, albId));
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nERROR: " + ex.Message);
            }
        }
Exemple #3
0
        private static void CreateAlbumTest(ImgurUtils imgur)
        {
            try
            {
                Console.WriteLine("\n=================================================\n" +
                                  "    Create an Imgur Album" +
                                  "\n=================================================\n");
                Console.WriteLine("Give the album a title: ");
                var title = Console.ReadLine();

                Console.WriteLine("\nGive the album a description: ");
                var desc = Console.ReadLine();

                Console.WriteLine("\nSet the album's privacy (public, hidden, secret): ");
                var priv = Console.ReadLine();

                Console.WriteLine("\nSet the album's layout (blog, grid, horizontal, vertical): ");
                var lay = Console.ReadLine();

                DumpAlbumInfo(imgur.CreateAlbum(title, desc, priv, lay));
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nERROR: " + ex.Message);
            }
        }
Exemple #4
0
        private async void btnUpload_Click(object sender, RoutedEventArgs e)
        {
            if (!"".Equals(tbPath.Text))
            {
                lbStatus.Dispatcher.Invoke(() => lbStatus.Content = "Đang upload...");
                string link = await ImgurUtils.UploadImage(tbPath.Text);

                var owner = (Owner as RoomWindow);
                owner.Dispatcher.Invoke(() => owner.SetTextBox(link));
                Dispatcher.Invoke(() => this.Close());
            }
        }
Exemple #5
0
 private static void GetAlbumTest(ImgurUtils imgur)
 {
     try
     {
         Console.WriteLine("\n=================================================\n" +
                           "    Get information about an existing album" +
                           "\n=================================================\n");
         Console.WriteLine("Please type an album ID: ");
         DumpAlbumInfo(imgur.GetAlbum(Console.ReadLine()));
     }
     catch (Exception ex)
     {
         Console.WriteLine("\nERROR: " + ex.Message);
     }
 }
Exemple #6
0
 private static void GetCommentTest(ImgurUtils imgur)
 {
     try
     {
         Console.WriteLine("\n=================================================\n" +
                           "    Get information about a comment" +
                           "\n=================================================\n");
         Console.WriteLine("Please type a comment ID: ");
         DumpCommentInfo(imgur.GetComment(Console.ReadLine(), true));
     }
     catch (Exception ex)
     {
         Console.WriteLine("\nERROR: " + ex.Message);
     }
 }
Exemple #7
0
 private static void GetAccountTest(ImgurUtils imgur)
 {
     try
     {
         Console.WriteLine("\n=================================================\n" +
                           "    Get information about an existing account" +
                           "\n=================================================\n");
         Console.WriteLine("Please type an account username: "******"\nERROR: " + ex.Message);
     }
 }
Exemple #8
0
 private static void DeleteImageTest(ImgurUtils imgur)
 {
     try
     {
         Console.WriteLine("\n=================================================\n" +
                           "    Delete an existing image" +
                           "\n=================================================\n");
         Console.WriteLine("Please type the delete hash: ");
         imgur.DeleteImage(Console.ReadLine());
     }
     catch (Exception ex)
     {
         Console.WriteLine("\nERROR: " + ex.Message);
     }
 }
        public void TestImgurParseAlbum()
        {
            List <string> imageUrls = ImgurUtils.ParseAlbum(new Uri("http://imgur.com/gallery/qLp4E"));

            Assert.AreEqual(10, imageUrls.Count);
            Assert.IsTrue(imageUrls.Contains("http://i.imgur.com/zUDXxa9.jpg"));
            Assert.IsTrue(imageUrls.Contains("http://i.imgur.com/S4em4Pr.jpg"));
            Assert.IsTrue(imageUrls.Contains("http://i.imgur.com/3YxxHZG.jpg"));
            Assert.IsTrue(imageUrls.Contains("http://i.imgur.com/tAw2DK1.jpg"));
            Assert.IsTrue(imageUrls.Contains("http://i.imgur.com/CiBlYyN.jpg"));
            Assert.IsTrue(imageUrls.Contains("http://i.imgur.com/i5FWfzA.jpg"));
            Assert.IsTrue(imageUrls.Contains("http://i.imgur.com/zP7P6pg.jpg"));
            Assert.IsTrue(imageUrls.Contains("http://i.imgur.com/TrYBtzx.jpg"));
            Assert.IsTrue(imageUrls.Contains("http://i.imgur.com/hCjiuQd.jpg"));
            Assert.IsTrue(imageUrls.Contains("http://i.imgur.com/rvw7Esb.jpg"));
        }
        /// <summary>
        /// Event handler for the "Find Images" button.  Fetches image URL's based on the field values in
        /// the first tab, and uses that information to set field values in the second tab.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FindImagesButton_Click(object sender, RoutedEventArgs e)
        {
            MainTabControl.SelectedItem = DownloadImagesTabItem;

            // TODO:  Refactor, and make this asynchronous so it doesn't block the main UI thread

            // Get user input from XAML fields
            string       entity = EntityTextBox.Text;
            RedditEntity type   = (UserEntityType.IsChecked == true) ? RedditEntity.User : RedditEntity.Subreddit;
            int          maxPages;

            if (!int.TryParse(MaxPagesTextBox.Text, out maxPages))
            {
                maxPages = 1;
            }

            // Parse Imgur image and album URL's for the given Reddit user or subuser, stopping when we
            // either run out of pages or else hit the maximum page count
            HashSet <string> imageUrls      = new HashSet <string>();
            HashSet <string> albumUrls      = new HashSet <string>();
            string           nextPageCursor = "";
            int pageCount = 1;

            for ( ; pageCount <= maxPages && nextPageCursor != null; pageCount++)
            {
                Console.WriteLine("Processing page {0} for {1} {2}", pageCount, type.ToString().ToLower(), entity);
                Uri redditUrl = RedditUtils.BuildUrl(entity, type, "".Equals(nextPageCursor) ? null : nextPageCursor);
                RedditUtils.ParsePage(redditUrl, ref imageUrls, ref albumUrls, out nextPageCursor);
                if (nextPageCursor != null)
                {
                    Console.WriteLine("nextPageCursor == {0}", nextPageCursor);
                }
            }
            Console.WriteLine("Parsed {0} image URL's and {1} album URL's from {2} pages", imageUrls.Count, albumUrls.Count, pageCount);

            // Parse out image URL's from the albums
            var imagesFromAlbums = albumUrls.SelectMany(albumUrl => ImgurUtils.ParseAlbum(new Uri(albumUrl)));

            imageUrls.UnionWith(imagesFromAlbums);
            Console.WriteLine("There are {0} total images after extracting {1} from albums", imageUrls.Count, imagesFromAlbums.ToList().Count);

            PageCountLabel.Content     = pageCount;
            ImagesCountLabel.Content   = imageUrls.Count;
            ImagesDataGrid.ItemsSource = imageUrls.Select(imageUrl => new ImgurUrl {
                URL = imageUrl
            });
        }
        /// <summary>
        ///     Load the complete history of the imgur uploads, with the corresponding information
        /// </summary>
        private async Task LoadHistory(CancellationToken cancellationToken = default)
        {
            bool saveNeeded = false;

            // Load the ImUr history
            foreach (string hash in ImgurConfiguration.ImgurUploadHistory.Keys)
            {
                if (ImgurConfiguration.RuntimeImgurHistory.ContainsKey(hash))
                {
                    // Already loaded, only add it to the view
                    ImgurHistory.Add(ImgurConfiguration.RuntimeImgurHistory[hash]);
                    continue;
                }
                try
                {
                    var imgurInfo = await ImgurUtils.RetrieveImgurInfoAsync(hash, ImgurConfiguration.ImgurUploadHistory[hash], cancellationToken);

                    if (imgurInfo != null)
                    {
                        await ImgurUtils.RetrieveImgurThumbnailAsync(imgurInfo, cancellationToken);

                        ImgurConfiguration.RuntimeImgurHistory.Add(hash, imgurInfo);
                        // Already loaded, only add it to the view
                        ImgurHistory.Add(imgurInfo);
                    }
                    else
                    {
                        Log.Debug().WriteLine("Deleting not found ImgUr {0} from config.", hash);
                        ImgurConfiguration.ImgurUploadHistory.Remove(hash);
                        saveNeeded = true;
                    }
                }
                catch (Exception e)
                {
                    Log.Error().WriteLine(e, "Problem loading ImgUr history for hash {0}", hash);
                }
            }
            if (saveNeeded)
            {
                // Save needed changes
                // IniConfig.Save();
            }
        }
Exemple #12
0
        private static void GetImageThumbnailTest(ImgurUtils imgur)
        {
            try
            {
                Console.WriteLine("\n=================================================\n" +
                                  "    Get the link for an image's thumbnail" +
                                  "\n=================================================\n");
                Console.WriteLine("Please type an image ID: ");
                var id = Console.ReadLine();

                Console.WriteLine("\nWhat size thumbnail? (small, medium, large, huge, small square, big square)");
                var thumb = Console.ReadLine();

                Console.WriteLine("\n" + imgur.GetImage(id).GetThumbnail(ThumbSizes[thumb]));
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nERROR: " + ex.Message);
            }
        }
Exemple #13
0
        static void Main(string[] args)
        {
            Console.WriteLine("\n=================================================\n" +
                              "    Welcome to ImgurDotNetTest! Below you will\n" +
                              "    find a list of valid commands to test the\n" +
                              "    ImgurDotNet APIs." +
                              "\n=================================================");
            Console.WriteLine("    Get Album Info:              ga" +
                              "\n    Get Image Info:              gi" +
                              "\n    Get Image Thumbnail Link:    git" +
                              "\n    Get Account Info:            gac" +
                              "\n    Get Comment Info:            gc" +
                              "\n    Create an Album:             ca" +
                              "\n    Delete an Album:             da" +
                              "\n    Upload Image From Web:       uiw" +
                              "\n    Upload Image from File:      uif" +
                              "\n    Delete an Image:             di" +
                              "\n    Quit:                        quit" +
                              "\n=================================================");

            Console.WriteLine("\nFirst, please type your Client ID:");
            var clientId = Console.ReadLine();

            var command    = "continue";
            var imgurTools = new ImgurUtils(clientId);

            while (command != "quit")
            {
                Console.WriteLine("\nNext Command: ");
                command = Console.ReadLine();

                switch (command)
                {
                case "ga":
                    GetAlbumTest(imgurTools);
                    break;

                case "gi":
                    GetImageTest(imgurTools);
                    break;

                case "git":
                    GetImageThumbnailTest(imgurTools);
                    break;

                case "gac":
                    GetAccountTest(imgurTools);
                    break;

                case "gc":
                    GetCommentTest(imgurTools);
                    break;

                case "ca":
                    CreateAlbumTest(imgurTools);
                    break;

                case "da":
                    DeleteAlbumTest(imgurTools);
                    break;

                case "uiw":
                    UploadFromWebTest(imgurTools);
                    break;

                case "uif":
                    UploadFromFileTest(imgurTools);
                    break;

                case "di":
                    DeleteImageTest(imgurTools);
                    break;

                case "quit":
                    Console.WriteLine("\nClosing application...");
                    Thread.Sleep(2000);
                    break;

                default:
                    Console.WriteLine("\nSorry, that command isn't recognized.");
                    break;
                }
            }
        }
 public async Task Delete()
 {
     await ImgurUtils.DeleteImgurImageAsync(SelectedImgur);
 }