2022-02-03 15:26:44 +00:00
|
|
|
|
namespace ASC.Common.Threading;
|
2022-01-25 09:29:11 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2022-02-03 15:26:44 +00:00
|
|
|
|
|
|
|
|
|
[Transient]
|
|
|
|
|
public class DistributedTaskProgress : DistributedTask
|
2020-09-30 10:54:49 +00:00
|
|
|
|
{
|
2022-02-03 15:26:44 +00:00
|
|
|
|
public double Percentage
|
|
|
|
|
{
|
|
|
|
|
get => Math.Min(100.0, Math.Max(0, DistributedTaskCache.Percentage));
|
|
|
|
|
set => DistributedTaskCache.Percentage = value;
|
|
|
|
|
}
|
|
|
|
|
public bool IsCompleted
|
|
|
|
|
{
|
|
|
|
|
get => DistributedTaskCache.IsCompleted;
|
|
|
|
|
set => DistributedTaskCache.IsCompleted = value;
|
|
|
|
|
}
|
|
|
|
|
protected int StepCount
|
2020-09-30 10:54:49 +00:00
|
|
|
|
{
|
2022-02-03 15:26:44 +00:00
|
|
|
|
get => DistributedTaskCache.StepCount;
|
|
|
|
|
set => DistributedTaskCache.StepCount = value;
|
|
|
|
|
}
|
2020-09-30 10:54:49 +00:00
|
|
|
|
|
2022-02-03 15:26:44 +00:00
|
|
|
|
public void RunJob()
|
|
|
|
|
{
|
|
|
|
|
Percentage = 0;
|
|
|
|
|
Status = DistributedTaskStatus.Running;
|
2022-02-01 14:51:29 +00:00
|
|
|
|
|
2022-02-03 15:26:44 +00:00
|
|
|
|
DoJob();
|
|
|
|
|
}
|
2020-09-30 10:54:49 +00:00
|
|
|
|
|
2022-02-03 15:26:44 +00:00
|
|
|
|
protected virtual void DoJob() { }
|
2022-02-01 14:51:29 +00:00
|
|
|
|
|
2022-02-03 15:26:44 +00:00
|
|
|
|
protected void StepDone()
|
|
|
|
|
{
|
2022-02-08 11:07:28 +00:00
|
|
|
|
if (StepCount > 0)
|
|
|
|
|
{
|
|
|
|
|
Percentage += 100.0 / StepCount;
|
|
|
|
|
}
|
2020-09-30 10:54:49 +00:00
|
|
|
|
|
2022-02-03 15:26:44 +00:00
|
|
|
|
PublishChanges();
|
2020-09-30 10:54:49 +00:00
|
|
|
|
}
|
2022-02-08 11:07:28 +00:00
|
|
|
|
}
|