forked from BAndysc/WoWDatabaseEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSyncTaskRunner.cs
42 lines (36 loc) · 1.19 KB
/
SyncTaskRunner.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using WDE.Common.Tasks;
namespace DatabaseTester;
public class SyncTaskRunner : ITaskRunner
{
private class DummyProgress : ITaskProgress
{
public TaskState State { get; set; }
public int CurrentProgress { get; set; }
public int MaxProgress { get; set; }
public string? CurrentTask { get; set; }
public void Report(int currentProgress, int maxProgress, string? currentTask) => Console.WriteLine(currentTask);
public void ReportFinished() { }
public void ReportFail() => throw new Exception("Task failed");
public event Action<ITaskProgress>? Updated;
}
public Task ScheduleTask(IThreadedTask threadedTask)
{
threadedTask.Run(new DummyProgress());
return Task.CompletedTask;
}
public Task ScheduleTask(IAsyncTask task)
{
task.Run(new DummyProgress()).Wait();
return Task.CompletedTask;
}
public Task ScheduleTask(string name, Func<ITaskProgress, Task> task)
{
task(new DummyProgress()).Wait();
return Task.CompletedTask;
}
public Task ScheduleTask(string name, Func<Task> task)
{
task().Wait();
return Task.CompletedTask;
}
}