JobStep.cs
2.8 KB
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
using Common;
using System;
namespace DeviceLib.Model.AGV
{
public class JobStep<T> where T : Enum
{
private T step;
private T preStep;
public string Msg
{
get; set;
}
public string WarnMsg
{
get; set;
}
public DateTime StartTime { get; set; } = DateTime.Now;
public DateTime EndTime { get; set; } = DateTime.Now;
public string RunTime { get { return FormUtil.GetSpanStr(EndTime - StartTime); } }
public JobStep(T initStep)
{
this.step = initStep;
this.preStep = initStep;
}
/// <summary>
/// 当前步骤是否是某个步骤
/// </summary>
/// <param name="step"></param>
/// <returns></returns>
public bool IsStep(T step)
{
return this.step.Equals(step);
}
/// <summary>
/// 是否超时(秒)
/// </summary>
/// <param name="timeOutValue"></param>
/// <returns></returns>
public bool IsTimeOut(double timeOutSeconds, out double timeOutValue)
{
TimeSpan span = DateTime.Now - StartTime;
timeOutValue = span.TotalSeconds;
if (span.TotalSeconds > timeOutSeconds)
{
return true;
}
return false;
}
public bool IsTimeOut(double timeOutSeconds, out TimeSpan timeOutValue)
{
timeOutValue = DateTime.Now - StartTime;
if (timeOutValue.TotalSeconds > timeOutSeconds)
{
return true;
}
return false;
}
public bool IsTimeOut(double timeOutSeconds)
{
TimeSpan span = DateTime.Now - StartTime;
if (span.TotalSeconds > timeOutSeconds)
{
return true;
}
return false;
}
/// <summary>
/// 当前步骤结束
/// </summary>
public void StepFinish()
{
EndTime = DateTime.Now;
}
/// <summary>
/// 进入下一个步骤
/// </summary>
/// <param name="nextStep"></param>
public void ToNextStep(T nextStep, string msg)
{
WarnMsg = "";
Msg = msg;
preStep = step;
step = nextStep;
StartTime = DateTime.Now;
}
public T CurStep
{
get { return step; }
}
public string CurStepStr
{
get { return step.ToString(); }
}
public T PreStep
{
get { return preStep; }
}
public string PreStepStr
{
get { return preStep.ToString(); }
}
}
}