forked from equinor/flotilla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInspection.cs
131 lines (112 loc) · 4.01 KB
/
Inspection.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Api.Controllers.Models;
using Api.Services.Models;
using Microsoft.EntityFrameworkCore;
#pragma warning disable CS8618
namespace Api.Database.Models
{
[Owned]
public class Inspection
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public string Id { get; set; }
[MaxLength(200)]
// ReSharper disable once AutoPropertyCanBeMadeGetOnly.Local
public string? IsarStepId { get; private set; } = Guid.NewGuid().ToString();
private InspectionStatus _status;
[Required]
public InspectionStatus Status
{
get { return _status; }
set
{
_status = value;
if (IsCompleted && EndTime is null)
EndTime = DateTimeOffset.UtcNow;
if (_status is InspectionStatus.InProgress && StartTime is null)
StartTime = DateTimeOffset.UtcNow;
}
}
public bool IsCompleted =>
_status
is InspectionStatus.Cancelled
or InspectionStatus.Successful
or InspectionStatus.Failed;
[Required]
public InspectionType InspectionType { get; set; }
public float? VideoDuration { get; set; }
[MaxLength(250)]
public string? AnalysisTypes { get; set; }
[MaxLength(250)]
public string? InspectionUrl { get; set; }
public DateTimeOffset? StartTime { get; private set; }
public DateTimeOffset? EndTime { get; private set; }
public Inspection()
{
InspectionType = InspectionType.Image;
Status = InspectionStatus.NotStarted;
}
public Inspection(EchoInspection echoInspection)
{
InspectionType = echoInspection.InspectionType;
VideoDuration = echoInspection.TimeInSeconds;
Status = InspectionStatus.NotStarted;
}
public Inspection(CustomInspectionQuery inspectionQuery)
{
InspectionType = inspectionQuery.InspectionType;
VideoDuration = inspectionQuery.VideoDuration;
AnalysisTypes = inspectionQuery.AnalysisTypes;
Status = InspectionStatus.NotStarted;
}
public void UpdateWithIsarInfo(IsarStep isarStep)
{
UpdateStatus(isarStep.StepStatus);
InspectionType = isarStep.StepType switch
{
IsarStepType.RecordAudio => InspectionType.Audio,
IsarStepType.TakeImage => InspectionType.Image,
IsarStepType.TakeThermalImage => InspectionType.ThermalImage,
IsarStepType.TakeVideo => InspectionType.Video,
IsarStepType.TakeThermalVideo => InspectionType.ThermalVideo,
_
=> throw new ArgumentException(
$"ISAR step type '{isarStep.StepType}' not supported for inspections"
)
};
}
public void UpdateStatus(IsarStepStatus isarStatus)
{
Status = isarStatus switch
{
IsarStepStatus.NotStarted => InspectionStatus.NotStarted,
IsarStepStatus.InProgress => InspectionStatus.InProgress,
IsarStepStatus.Successful => InspectionStatus.Successful,
IsarStepStatus.Cancelled => InspectionStatus.Cancelled,
IsarStepStatus.Failed => InspectionStatus.Failed,
_
=> throw new ArgumentException(
$"ISAR step status '{isarStatus}' not supported for inspection status"
)
};
}
}
public enum InspectionStatus
{
Successful,
InProgress,
NotStarted,
Failed,
Cancelled
}
public enum InspectionType
{
Image,
ThermalImage,
Video,
ThermalVideo,
Audio
}
}