protected void ShowProgress(ProgressRecord progressRecord, ProgressReporter progressReporter)
        {
            foreach (var progressInfo in progressReporter.GetConsumingEnumerable())
            {
                progressRecord.CurrentOperation  = progressInfo.CurrentOperation;
                progressRecord.StatusDescription = $"Completed {progressInfo.CompletedItems} of {progressInfo.TotalItems} items";
                progressRecord.PercentComplete   = progressInfo.PercentComplete();
                WriteProgress(progressRecord);

                if (!string.IsNullOrEmpty(progressInfo.VerboseOutput))
                {
                    WriteVerbose(progressInfo.VerboseOutput);
                }
            }
        }
Example #2
0
        protected override void ProcessRecord()
        {
            var counter = 1;

            foreach (var category in Categories)
            {
                var record = CreateProgressRecord($"Downloading '{category}' images [Category {counter++} of {Categories.Length}]", "Waiting...");

                try
                {
                    var reporter = new ProgressReporter();
                    var task     = DownloadImages(category, reporter);
                    ShowProgress(record, reporter);
                    task.Wait();
                }
                finally
                {
                    HideProgress(record);
                }
            }
        }
Example #3
0
        private async Task DownloadImages(string category, ProgressReporter reporter)
        {
            var          html    = await _categories[category].GetStringAsync();
            const string regex   = @"https:\/\/kbdevstorage1\.blob\.core\.windows\.net\/asset-blobs\/[0-9A-Za-z_]+";
            var          urls    = Regex.Matches(html, regex).Cast <Match>().Select(x => x.Value).Distinct().ToList();
            var          counter = 1;

            foreach (var url in urls)
            {
                string fileName;
                string path;
                do
                {
                    fileName = $"{Guid.NewGuid().ToString().Split('-')[4]}.jpg";
                    path     = Path.Combine(OutDirectory, fileName);
                } while (File.Exists(path));

                reporter.UpdateProgress(url, urls.Count, counter++);
                var result = await url.DownloadFileAsync(OutDirectory, fileName);
            }

            reporter.CompleteAdding();
        }