public void Test_ExecuteAsync_With_AggregateCommand_Calls_AggregationService_AggregateAsync() { _commandHandler.ExecuteAsync("aggregate"); A.CallTo(() => _aggregationService.AggregateAsync()).MustHaveHappenedOnceExactly(); A.CallTo(() => _downloadService.DownloadAsync(A <string[]> ._)).MustNotHaveHappened(); A.CallTo(() => _importService.ImportAsync()).MustNotHaveHappened(); }
public async Task RunAsync(RecommendOptions opts, IConfiguration configuration) { var validator = await _validator.ValidateAsync(opts); if (!validator.IsValid) { _console.ErrorLine("Invalid gallery code."); return; } var responses = await _api.FetchRecommendedAsync(opts.Input.ToString()); var selection = responses.FilterByUserSelected(); // Initialise the Progress bar. using var progress = new ProgressBar(selection.Count, $"[task] recommend from id: {opts.Input}", ProgressBarConfiguration.BarOption); var useTachiyomiLayout = opts.UseTachiyomiLayout || bool.Parse(configuration["UseTachiyomiFolderStructure"]); foreach (var response in selection) { await _download.DownloadAsync(response, opts.Output, opts.Pack, useTachiyomiLayout, progress); progress.Tick(); } }
public async Task RunAsync(RandomOptions opts, IConfiguration configuration) { var totalNumbers = await _api.GetTotalGalleryCountAsync(); while (true) { var randomCode = new Random().Next(1, totalNumbers); var response = await _api.FetchSingleAsync(randomCode.ToString()); _console.WriteLine(response.ToReadable()); var prompt = Prompt.Confirm("Are you sure to download this one?", true); if (!prompt) { await Task.Delay(1000).ConfigureAwait(false); continue; } var useTachiyomiLayout = opts.UseTachiyomiLayout || bool.Parse(configuration["UseTachiyomiFolderStructure"]); await _download.DownloadAsync(response, opts.Output, opts.Pack, useTachiyomiLayout, null); break; } }
public virtual async Task ExecuteAsync(string command) { switch (command) { case "aggregate": await _aggregationService.AggregateAsync(); break; case "download": // TODO: config variable? user input? var cities = new[] { "des moines", "johnston", "norwalk", "cedar rapids", "council bluffs", "davenport", "fort dodge", "mason city", "sioux city", "altoona" }; await _downloadService.DownloadAsync(cities); break; case "import": await _importService.ImportAsync(); break; } }
public async Task RunAsync(SearchOptions opts, IConfiguration configuration) { var validationResult = await _validator.ValidateAsync(opts); if (!validationResult.IsValid) { foreach (var error in validationResult.Errors) { _console.ErrorLine($"Validation Failure: {error.ErrorMessage}"); } return; } // Construct search query var searchQueries = new List <string>(); searchQueries.AddRange(opts.Queries); searchQueries.AddRange(opts.Exclude.Select(q => $"-{q}")); searchQueries.AddRange(opts.DateRange.Select(d => $"uploaded:{d}")); searchQueries.AddRange(opts.PageRange.Select(p => $"pages:{p}")); var query = new SearchQuery { Queries = string.Join(" ", searchQueries), PageNumber = opts.Page, Sort = opts.Sort }; var responses = await _api.SearchAsync(query); if (responses.Count < 1) { _console.ErrorLine("No results found."); return; } var selection = responses.FilterByUserSelected(); // Initialise the Progress bar. using var progress = new ProgressBar(selection.Count, $"[task] search download", ProgressBarConfiguration.BarOption); var useTachiyomiLayout = opts.UseTachiyomiLayout || bool.Parse(configuration["UseTachiyomiFolderStructure"]); foreach (var response in selection) { await _download.DownloadAsync(response, opts.Output, opts.Pack, useTachiyomiLayout, progress); progress.Tick(); } }
private async Task <FileInfo> DownloadNewFilesAsync(CancellationToken cancellationToken) { var downloadsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Constants.SOLUTION_ENTRYPOINT_NAME, Constants.SOLUTION_DOWNLOADS_NAME); var downloadsDir = new DirectoryInfo(downloadsPath); if (!downloadsDir.Exists) { downloadsDir.Create(); } var progress = new Progress <int>(value => { UpdateStatus($"Downloading... {value}%"); progressBar.Value = value; }); var currentUpdaterModel = this.updaterModelBindingSource.Current as UpdaterModel; if (currentUpdaterModel == null) { progressBar.Value = 100; return(null); } var downloadName = Path.Combine(downloadsDir.FullName, currentUpdaterModel.NewVersionModel.FileName); var downloadFileInfo = new FileInfo(downloadName); if (cancellationToken.IsCancellationRequested) { return(downloadFileInfo); } if (!downloadFileInfo.Exists) { await Task.Run(async() => await _downloadService.DownloadAsync(currentUpdaterModel.NewVersionModel, downloadFileInfo.FullName, progress, cancellationToken)); } else { progressBar.Value = 100; } return(downloadFileInfo); }
public async Task RunAsync(FileCommandOptions opts, IConfiguration configuration) { if (!File.Exists(opts.FilePath)) { _console.ErrorLine("File doesn't exist."); return; } if (IsFileExceedingToFileSizeLimit(opts.FilePath)) { _console.ErrorLine("The file size is exceeding 5MB file size limit."); return; } var textFile = await File.ReadAllLinesAsync(opts.FilePath, Encoding.UTF8) .ConfigureAwait(false); var validUrls = FilterValidUrls(textFile); if (validUrls.Count == 0) { _console.ErrorLine("No valid URLs found."); return; } using var progress = new ProgressBar( validUrls.Count, "downloading from text file...", ProgressBarConfiguration.BarOption); var useTachiyomiLayout = opts.UseTachiyomiLayout || bool.Parse(configuration["UseTachiyomiFolderStructure"]); foreach (var url in validUrls) { var code = Regex.Match(url, @"\d+").Value; var response = await _api.FetchSingleAsync(code); await _download.DownloadAsync(response, opts.Output, opts.Pack, useTachiyomiLayout, progress); progress.Tick(); } }
public async Task RunAsync(GetOptions opts, IConfiguration configuration) { var validationResult = await _validator.ValidateAsync(opts); if (!validationResult.IsValid) { _console.ErrorLine("Invalid gallery code."); return; } var response = await _api.FetchSingleAsync(opts.Input.ToString()); _console.WriteLine(response.ToReadable()); if (opts.ReadOnly) { return; } var useTachiyomiLayout = opts.UseTachiyomiLayout || bool.Parse(configuration["UseTachiyomiFolderStructure"]); await _download.DownloadAsync(response, opts.Output, opts.Pack, useTachiyomiLayout, null); }