-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
26 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,27 @@ | ||
namespace ReliableDownloader; | ||
using ReliableDownloader; | ||
|
||
internal class Program | ||
var exampleUrl = args.Length > 0 | ||
? args[0] | ||
// If this url 404's, you can get a live one from https://installer.demo.accurx.com/chain/latest.json. | ||
: "https://installer.demo.accurx.com/chain/4.22.50587.0/accuRx.Installer.Local.msi"; | ||
|
||
var exampleFilePath = args.Length > 1 | ||
? args[1] | ||
: Path.Combine(Directory.GetCurrentDirectory(), "myfirstdownload.msi"); | ||
|
||
using var cts = new CancellationTokenSource(); | ||
|
||
if (args.Length > 2) | ||
{ | ||
public static async Task Main(string[] args) | ||
{ | ||
// If this url 404's, you can get a live one from https://installer.demo.accurx.com/chain/latest.json. | ||
var exampleUrl = "https://installer.demo.accurx.com/chain/4.22.50587.0/accuRx.Installer.Local.msi"; | ||
var exampleFilePath = Path.Combine(Directory.GetCurrentDirectory(), "myfirstdownload.msi"); | ||
var fileDownloader = new FileDownloader(); | ||
var didDownloadSuccessfully = await fileDownloader.TryDownloadFile( | ||
exampleUrl, | ||
exampleFilePath, | ||
progress => Console.WriteLine($"Percent progress is {progress.ProgressPercent}"), | ||
CancellationToken.None); | ||
Console.WriteLine($"File download ended! Success: {didDownloadSuccessfully}"); | ||
} | ||
} | ||
cts.CancelAfter(TimeSpan.FromMilliseconds(int.Parse(args[2]))); | ||
} | ||
|
||
var fileDownloader = new FileDownloader(); | ||
|
||
var didDownloadSuccessfully = await fileDownloader.TryDownloadFile( | ||
exampleUrl, | ||
exampleFilePath, | ||
progress => Console.WriteLine($"Percent progress is {progress.ProgressPercent}"), | ||
cts.Token); | ||
|
||
Console.WriteLine($"File download ended! Success: {didDownloadSuccessfully}"); |