Skip to content

Commit 7ed7501

Browse files
author
Thomas Fuchs
authored
Merge pull request #543 from dacky179/feature/GetTaskOfActivity
Add Activity- and ProcessExtensions
2 parents c1f2456 + 1ad2100 commit 7ed7501

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using Moryx.AbstractionLayer.Recipes;
6+
using Moryx.Workplans;
7+
8+
namespace Moryx.AbstractionLayer
9+
{
10+
/// <summary>
11+
/// Extensions for <see cref="Activity"/>
12+
/// </summary>
13+
public static class ActivityExtensions
14+
{
15+
/// <summary>
16+
/// Get the task of an <see cref="Activity"/>.
17+
/// Interface extension for more accessibility and less casting.
18+
/// </summary>
19+
/// <param name="activity">Must derive from <seealso cref="Activity"/>!</param>
20+
public static IWorkplanStep GetTask(this IActivity activity)
21+
{
22+
if (activity is not Activity cast)
23+
throw new ArgumentException("GetTask only works for Activity (IActivity is slightly not enough)!", nameof(activity));
24+
25+
if (activity.Process.Recipe is WorkplanRecipe workplanRecipe)
26+
{
27+
var step = workplanRecipe.Workplan.Steps.FirstOrDefault(s => s.Id == cast.StepId);
28+
return step;
29+
}
30+
return null;
31+
}
32+
}
33+
}

src/Moryx.AbstractionLayer/Process/ProcessExtensions.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,50 @@
1-
namespace Moryx.AbstractionLayer
1+
using System.Collections.Generic;
2+
3+
namespace Moryx.AbstractionLayer
24
{
35
/// <summary>
46
/// Extensions for <see cref="IProcess"/>
57
/// </summary>
68
public static class ProcessExtensions
79
{
810
/// <summary>
9-
/// Prepared activity that will be dispatched as soon as a ready to work was send.
11+
/// Get one prepared activity that will be dispatched as soon as a ready to work was send.
12+
/// Mention that, in case of parallel path in a workplan, a process could have multiple prepared activities!
13+
/// See also: <seealso cref="NextActivities"/>
1014
/// </summary>
15+
/// <returns>Last activity of the process that is prepared</returns>
1116
public static IActivity NextActivity(this IProcess process)
1217
{
1318
return process.GetActivity(ActivitySelectionType.LastOrDefault, activity => activity.Tracing?.Started == null);
1419
}
1520

1621
/// <summary>
17-
/// Current running activity
22+
/// Get all prepared activities that will be dispatched as soon as a ready to work was send.
23+
/// </summary>
24+
public static IEnumerable<IActivity> NextActivities(this IProcess process)
25+
{
26+
return process.GetActivities(activity => activity.Tracing?.Started == null);
27+
}
28+
29+
/// <summary>
30+
/// Get one of the current running activities of the process.
31+
/// Mention that, in case of parallel path in a workplan, a process could have multiple running activities!
32+
/// See also: <seealso cref="CurrentActivities"/>
1833
/// </summary>
34+
/// <returns>Last activity of the process that is running</returns>
1935
public static IActivity CurrentActivity(this IProcess process)
2036
{
2137
return process.GetActivity(ActivitySelectionType.LastOrDefault, activity => activity.Tracing?.Started != null && activity.Result == null);
2238
}
2339

40+
/// <summary>
41+
/// Get all current running activities of the process.
42+
/// </summary>
43+
public static IEnumerable<IActivity> CurrentActivities(this IProcess process)
44+
{
45+
return process.GetActivities(activity => activity.Tracing?.Started != null && activity.Result == null);
46+
}
47+
2448
/// <summary>
2549
/// Get last completed activity
2650
/// </summary>

0 commit comments

Comments
 (0)