-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathActivity.cs
147 lines (121 loc) · 3.94 KB
/
Activity.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Copyright (c) 2023, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0
using System;
using Moryx.AbstractionLayer.Capabilities;
using Moryx.Tools;
namespace Moryx.AbstractionLayer
{
/// <summary>
/// Base class for all <see cref="IActivity"/>
/// </summary>
public abstract class Activity : IActivity
{
#region Activity definition
///
public abstract ProcessRequirement ProcessRequirement { get; }
///
public abstract ICapabilities RequiredCapabilities { get; }
/// <summary>
/// Untyped parameters object
/// </summary>
public IParameters Parameters { get; set; }
#endregion
#region Members
///
public long Id { get; set; }
///
public IProcess Process { get; set; }
///
public Tracing Tracing { get; set; }
///
public ActivityResult Result { get; set; }
/// <summary>
/// Name of the activity
/// </summary>
public string Name { get; set; }
/// <summary>
/// Id of the corresponding workplan step
/// </summary>
public long StepId { get; set; }
#endregion
/// <summary>
/// Initialize activity with <see cref="Tracing"/>
/// </summary>
internal Activity()
{
Tracing = new Tracing();
var displayName = GetType().GetDisplayName();
Name = string.IsNullOrEmpty(displayName) ? GetType().Name : displayName;
}
/// <inheritdoc />
public ActivityResult Complete(long resultNumber)
{
return Result = CreateResult(resultNumber);
}
/// <inheritdoc />
public ActivityResult Fail()
{
return Result = CreateFailureResult();
}
/// <summary>
/// Create a typed result object for this result number
/// </summary>
protected abstract ActivityResult CreateResult(long resultNumber);
/// <summary>
/// Create a typed result object for a technical failure.
/// </summary>
protected abstract ActivityResult CreateFailureResult();
/// <seealso cref="IDisposable.Dispose"/>
public virtual void Dispose()
{
}
/// <seealso cref="object.ToString"/>
public override string ToString()
{
return $"{GetType().Name} - Process = {Process?.Id ?? 0}";
}
}
/// <summary>
/// Base class for all <see cref="IActivity"/> with parameters and tracing
/// </summary>
/// <typeparam name="TParam">
/// Type of the parameters object.
/// Use <see cref="NullActivityParameters"/> if your activity does not require parameters
/// </typeparam>
/// <typeparam name="TTracing">Type of the tracing object.</typeparam>
public abstract class Activity<TParam, TTracing> : Activity, IActivity<TParam>
where TParam : IParameters
where TTracing : Tracing, new()
{
/// <summary>
/// Creates a new instance of <see cref="Activity{TParam,TTracing}"/>
/// </summary>
protected Activity()
{
Tracing = new TTracing();
}
///
public new TParam Parameters
{
get => (TParam)base.Parameters;
set => base.Parameters = value;
}
///
public new TTracing Tracing
{
get => (TTracing) base.Tracing;
set => base.Tracing = value;
}
}
/// <summary>
/// Base class for all <see cref="IActivity"/> with parameters
/// </summary>
/// <typeparam name="TParam">
/// Type of the parameters object.
/// Use <see cref="NullActivityParameters"/> if your activity does not require parameters
/// </typeparam>
public abstract class Activity<TParam> : Activity<TParam, Tracing>
where TParam : IParameters
{
}
}