2022-02-03 15:26:44 +00:00
|
|
|
|
namespace ASC.Common.Threading;
|
|
|
|
|
|
|
|
|
|
[Transient]
|
2022-03-25 16:15:28 +00:00
|
|
|
|
[ProtoContract(IgnoreUnknownSubTypes = true)]
|
2022-02-03 15:26:44 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2022-02-03 15:26:44 +00:00
|
|
|
|
public double Percentage
|
|
|
|
|
{
|
2022-03-25 16:15:28 +00:00
|
|
|
|
get => Math.Min(100.0, Math.Max(0, _percentage));
|
|
|
|
|
set => _percentage = value;
|
2022-02-03 15:26:44 +00:00
|
|
|
|
}
|
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; }
|
|
|
|
|
|
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
|
|
|
|
}
|