private async Task DownloadInner(string s, string ext = "tmp") { string path = string.Empty; try { var client = new DirectWebClient(); path = Path.ChangeExtension(Path.GetTempFileName(), ext); await client.DownloadFileAsync(s, path); Assert.IsTrue(File.Exists(path)); } catch (Exception e) { Assert.Fail(e.Message); } finally { if (File.Exists(path)) { File.Delete(path); } } }
static async Task <Exception> DownloadFile(string link, string filePath, string beginText) { try { Console.WriteLine(beginText); Console.WriteLine(); var options = new ProgressBarOptions { FilledCharColour = ConsoleColor.Green, FilledChar = '█', MaximumValue = 100, NumberOfSquares = 50, ShowBorders = false, ShowPercentage = true, UnfilledChar = ' ', UnfilledCharColour = ConsoleColor.Red, }; var bar = new ProgressBar(options); var client = new DirectWebClient(); client.DownloadProgressChanged += (sender, args) => { bar.Report(args.ProgressPercentage); }; client.DownloadFileCompleted += (sender, args) => { bar.Report(100); }; await client.DownloadFileAsync(link, filePath); return(null); } catch (Exception e) { return(e); } finally { Console.WriteLine(); } }