/
BackgroundTask.cs
83 lines (70 loc) · 2.33 KB
/
BackgroundTask.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
namespace Raytha.Domain.Entities;
public class BackgroundTask : BaseEntity, IHasCreationTime, IHasModificationTime
{
public string Name { get; set; }
public string? Args { get; set; }
public string? ErrorMessage { get; set; }
public BackgroundTaskStatus Status { get; set; } = BackgroundTaskStatus.Enqueued;
public string? StatusInfo { get; set; }
public int PercentComplete { get; set; }
public int NumberOfRetries { get; set; }
public DateTime CreationTime { get; set; } = DateTime.UtcNow;
public DateTime? LastModificationTime { get; set; }
public DateTime? CompletionTime { get; set; }
public int TaskStep { get; set; }
}
public class BackgroundTaskStatus : ValueObject
{
static BackgroundTaskStatus()
{
}
public BackgroundTaskStatus()
{
}
private BackgroundTaskStatus(string label, string developerName)
{
Label = label;
DeveloperName = developerName;
}
public static BackgroundTaskStatus From(string developerName)
{
var type = SupportedTypes.FirstOrDefault(p => p.DeveloperName == developerName.ToLower());
if (type == null)
{
throw new SortOrderNotFoundException(developerName);
}
return type;
}
public static BackgroundTaskStatus Enqueued => new("Enqueued", "enqueued");
public static BackgroundTaskStatus Processing => new("Processing", "processing");
public static BackgroundTaskStatus Complete => new("Complete", "complete");
public static BackgroundTaskStatus Error => new("Error", "error");
public string Label { get; set; } = string.Empty;
public string DeveloperName { get; set; } = string.Empty;
public static implicit operator string(BackgroundTaskStatus scheme)
{
return scheme.DeveloperName;
}
public static explicit operator BackgroundTaskStatus(string type)
{
return From(type);
}
public override string ToString()
{
return Label;
}
public static IEnumerable<BackgroundTaskStatus> SupportedTypes
{
get
{
yield return Enqueued;
yield return Processing;
yield return Complete;
yield return Error;
}
}
protected override IEnumerable<object> GetEqualityComponents()
{
yield return DeveloperName;
}
}