예제 #1
0
        /// <summary>
        /// Downloads a list of images asynchronously.
        /// </summary>
        /// <param name="uris">Uri list of the images.</param>
        /// <param name="progress">Progress object tied to the progress bar.</param>
        /// <returns>A list of properties of the images downloaded.</returns>
        public List <LightshotImage> DownloadImagesAsync(List <Uri> uris, ProgressBar progress)
        {
            var images = new List <LightshotImage>();
            int count  = 0;

            foreach (var uri in uris)
            {
                count++;
                _image = new LightshotImage(uri);

                if (IsImageValid() && !DoesImageExist())
                {
                    images.Add(DownloadImage(uri));
                    progress.Report((count * 100) / uris.Count, _image);
                    continue;
                }

                string message = !IsImageValid() ?
                                 $"\rImage {_image.Name} does not exist on the site!                               " :
                                 $"\rImage {_image.Name} already exists in the selected directory!                         ";

                Console.WriteLine(message);
                progress.DrawCurrentProgressBar();
            }

            return(images);
        }
예제 #2
0
        /// <summary>
        /// Downloads an image.
        /// </summary>
        /// <param name="uri">An image's uri.</param>
        /// <returns>The image's properties.</returns>
        public LightshotImage DownloadImage(Uri uri)
        {
            _image = new LightshotImage(uri);

            if (IsImageValid())
            {
                return(SaveImage());
            }
            return(null);
        }
예제 #3
0
        /// <summary>
        /// Retports a successfull pass and updates the loading bar.
        /// </summary>
        /// <param name="percentage">Percentage to set the progress bar to.</param>
        /// <param name="image">Properties of an image.</param>
        public void Report(double percentage, LightshotImage image)
        {
            _image      = image;
            _percentage = (int)percentage;
            double leftOver      = (double)_blockCount / 10;
            double blockInterval = Math.Round(10 / leftOver, 2);

            if (_percentage >= blockInterval)
            {
                _loadedBlocks = (int)((_percentage - (_percentage % blockInterval)) / blockInterval);
            }

            UpdateText();
        }