forked from equinor/flotilla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIsarTask.cs
73 lines (63 loc) · 1.94 KB
/
IsarTask.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
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
#nullable disable
namespace Api.Database.Models
{
[Owned]
public class IsarTask
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public string Id { get; set; }
[Required]
public string IsarTaskId { get; set; }
[Required]
public virtual Mission Mission { get; set; }
public string TagId { get; set; }
[Required]
public IsarTaskStatus TaskStatus { get; set; }
[Required]
public DateTimeOffset Time { get; set; }
[Required]
public IList<IsarStep> Steps { get; set; }
#nullable enable
public IsarStep? ReadIsarStepById(string isarStepId)
{
return Steps.FirstOrDefault(
step => step.IsarStepId.Equals(isarStepId, StringComparison.Ordinal)
);
}
#nullable disable
}
public enum IsarTaskStatus
{
Successful,
PartiallySuccessful,
NotStarted,
InProgress,
Failed,
Cancelled,
Paused,
}
public static class IsarTaskStatusMethods
{
public static IsarTaskStatus FromString(string status)
{
return status switch
{
"successful" => IsarTaskStatus.Successful,
"partially_successful" => IsarTaskStatus.PartiallySuccessful,
"not_started" => IsarTaskStatus.NotStarted,
"in_progress" => IsarTaskStatus.InProgress,
"failed" => IsarTaskStatus.Failed,
"cancelled" => IsarTaskStatus.Cancelled,
"paused" => IsarTaskStatus.Paused,
_
=> throw new ArgumentException(
$"Failed to parse mission status {status} as it's not supported"
)
};
}
}
}