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

41 lines
839 B
C#
Raw Normal View History

namespace ASC.Common.Threading;
[Transient]
2022-03-25 16:15:28 +00:00
[ProtoContract(IgnoreUnknownSubTypes = true)]
public class DistributedTaskProgress : DistributedTask
2020-09-30 10:54:49 +00:00
{
2022-03-25 16:15:28 +00:00
[ProtoMember(1)]
private double _percentage;
public double Percentage
{
2022-03-25 16:15:28 +00:00
get => Math.Min(100.0, Math.Max(0, _percentage));
set => _percentage = value;
}
2020-09-30 10:54:49 +00:00
2022-03-25 16:15:28 +00:00
[ProtoMember(2)]
public bool IsCompleted { get; set; }
[ProtoMember(3)]
protected int StepCount { get; set; }
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
}