Philipp Heenemann a8b91f4ee6 Refactor C# code to imperative, top-level statements style
Updated the existing C# code into a more modern, imperative and top-level statements style. This involves shortening the code by removing unnecessary parts like additional brackets and explicit namespace declarations. It's done to improve clarity and readability.
2023-07-12 09:19:33 +02:00

33 lines
868 B
C#

using SPTInstaller.Interfaces;
using SPTInstaller.Models;
using System.Threading.Tasks;
namespace SPTInstaller.Installer_Tasks;
internal class TestTask : InstallerTaskBase
{
public static TestTask FromRandomName() => new TestTask($"Test Task #{new Random().Next(0, 9999)}");
public TestTask(string name) : base(name)
{
}
public async override Task<IResult> TaskOperation()
{
var total = 4;
var interval = TimeSpan.FromSeconds(1);
for(var i = 0; i < total; i++)
{
var count = i + 1;
var progressMessage = $"Running Task: {Name}";
var progress = (int)Math.Floor((double)count / total * 100);
SetStatus(progressMessage, $"Details: ({count}/{total})", progress);
await Task.Delay(interval);
}
return Result.FromSuccess();
}
}