forked from equinor/flotilla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMission.cs
78 lines (64 loc) · 2 KB
/
Mission.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
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
#nullable disable
namespace Api.Database.Models
{
public class Mission
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Required]
public string Id { get; set; }
public string AssetCode { get; set; }
[Required]
public virtual Robot Robot { get; set; }
[MaxLength(128)]
public string IsarMissionId { get; set; }
[MaxLength(128)]
[Required]
public int EchoMissionId { get; set; }
[Required]
public MissionStatus MissionStatus { get; set; }
[Required]
public DateTimeOffset StartTime { get; set; }
public DateTimeOffset EndTime { get; set; }
[Required]
public IList<IsarTask> Tasks { get; set; }
[Required]
public IList<PlannedTask> PlannedTasks { get; set; }
#nullable enable
public IsarTask? ReadIsarTaskById(string isarTaskId)
{
return Tasks.FirstOrDefault(
task => task.IsarTaskId.Equals(isarTaskId, StringComparison.Ordinal)
);
}
#nullable disable
public static MissionStatus MissionStatusFromString(string status)
{
return status switch
{
"completed" => MissionStatus.Successful,
"not_started" => MissionStatus.Pending,
"in_progress" => MissionStatus.Ongoing,
"failed" => MissionStatus.Failed,
"cancelled" => MissionStatus.Cancelled,
"paused" => MissionStatus.Paused,
_
=> throw new ArgumentException(
$"Failed to parse mission status '{status}' as it's not supported"
)
};
}
}
public enum MissionStatus
{
Pending,
Ongoing,
Paused,
Aborted,
Cancelled,
Failed,
Successful
}
}