Skip to content

Commit

Permalink
feat: Parameterise console app
Browse files Browse the repository at this point in the history
  • Loading branch information
HansJonus committed Apr 17, 2024
1 parent ad26823 commit 14a19ee
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
3 changes: 1 addition & 2 deletions dot-net/ReliableDownloader.Tests/Tests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using NUnit.Framework;
using NUnit.Framework;

namespace ReliableDownloader.Tests;

Expand Down
41 changes: 25 additions & 16 deletions dot-net/ReliableDownloader/Program.cs
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}");

0 comments on commit 14a19ee

Please sign in to comment.