DocSpace-buildtools/common/ASC.Common/Threading/DistributedTaskProgress.cs

42 lines
970 B
C#
Raw Normal View History

namespace ASC.Common.Threading;
2022-01-25 09:29:11 +00:00
using System.Threading.Tasks;
[Transient]
public class DistributedTaskProgress : DistributedTask
2020-09-30 10:54:49 +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
{
get => DistributedTaskCache.StepCount;
set => DistributedTaskCache.StepCount = value;
}
2020-09-30 10:54:49 +00:00
public void RunJob()
{
Percentage = 0;
Status = DistributedTaskStatus.Running;
DoJob();
}
2020-09-30 10:54:49 +00:00
protected virtual void DoJob() { }
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
PublishChanges();
2020-09-30 10:54:49 +00:00
}
2022-02-08 11:07:28 +00:00
}