Skip to content

Commit 2e46c11

Browse files
authored
Merge pull request #838 from alimozdemir/master
ActivityName as expression. It solves #542 issue. (Activity Compound Key)
2 parents 27114c0 + 078acc0 commit 2e46c11

File tree

4 files changed

+111
-0
lines changed

4 files changed

+111
-0
lines changed

src/WorkflowCore/Interface/IWorkflowModifier.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,15 @@ IContainerStepBuilder<TData, Recur, TStepBody> Recur(Expression<Func<TData, Time
152152
IStepBuilder<TData, Activity> Activity(string activityName, Expression<Func<TData, object>> parameters = null,
153153
Expression<Func<TData, DateTime>> effectiveDate = null, Expression<Func<TData, bool>> cancelCondition = null);
154154

155+
/// <summary>
156+
/// Wait here until an external activity is complete
157+
/// </summary>
158+
/// <param name="activityName">The name used to identify the activity to wait for</param>
159+
/// <param name="parameters">The data to pass the external activity worker</param>
160+
/// <param name="effectiveDate">Listen for events as of this effective date</param>
161+
/// <param name="cancelCondition">A conditon that when true will cancel this WaitFor</param>
162+
/// <returns></returns>
163+
IStepBuilder<TData, Activity> Activity(Expression<Func<TData, IStepExecutionContext, string>> activityName, Expression<Func<TData, object>> parameters = null,
164+
Expression<Func<TData, DateTime>> effectiveDate = null, Expression<Func<TData, bool>> cancelCondition = null);
155165
}
156166
}

src/WorkflowCore/Services/FluentBuilders/StepBuilder.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,5 +522,24 @@ public IStepBuilder<TData, Activity> Activity(string activityName, Expression<Fu
522522
Step.Outcomes.Add(new ValueOutcome { NextStep = newStep.Id });
523523
return stepBuilder;
524524
}
525+
526+
public IStepBuilder<TData, Activity> Activity(Expression<Func<TData, IStepExecutionContext, string>> activityName, Expression<Func<TData, object>> parameters = null, Expression<Func<TData, DateTime>> effectiveDate = null, Expression<Func<TData, bool>> cancelCondition = null)
527+
{
528+
var newStep = new WorkflowStep<Activity>();
529+
newStep.CancelCondition = cancelCondition;
530+
531+
WorkflowBuilder.AddStep(newStep);
532+
var stepBuilder = new StepBuilder<TData, Activity>(WorkflowBuilder, newStep);
533+
stepBuilder.Input((step) => step.ActivityName, activityName);
534+
535+
if (parameters != null)
536+
stepBuilder.Input((step) => step.Parameters, parameters);
537+
538+
if (effectiveDate != null)
539+
stepBuilder.Input((step) => step.EffectiveDate, effectiveDate);
540+
541+
Step.Outcomes.Add(new ValueOutcome { NextStep = newStep.Id });
542+
return stepBuilder;
543+
}
525544
}
526545
}

src/WorkflowCore/Services/FluentBuilders/WorkflowBuilder.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ public IStepBuilder<TData, Activity> Activity(string activityName, Expression<Fu
271271
{
272272
return Start().Activity(activityName, parameters, effectiveDate, cancelCondition);
273273
}
274+
public IStepBuilder<TData, Activity> Activity(Expression<Func<TData, IStepExecutionContext, string>> activityName, Expression<Func<TData, object>> parameters = null, Expression<Func<TData, DateTime>> effectiveDate = null, Expression<Func<TData, bool>> cancelCondition = null)
275+
{
276+
return Start().Activity(activityName, parameters, effectiveDate, cancelCondition);
277+
}
274278

275279
private IStepBuilder<TData, InlineStepBody> Start()
276280
{
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using System;
2+
using WorkflowCore.Interface;
3+
using WorkflowCore.Models;
4+
using Xunit;
5+
using FluentAssertions;
6+
using System.Linq;
7+
using WorkflowCore.Testing;
8+
9+
namespace WorkflowCore.IntegrationTests.Scenarios
10+
{
11+
/*
12+
* DISABLED for bug on build pipeline
13+
public class ActivityScenario2 : WorkflowTest<ActivityScenario2.ActivityWorkflow, ActivityScenario2.MyDataClass>
14+
{
15+
public class MyDataClass
16+
{
17+
public object ActivityInput { get; set; }
18+
public object ActivityOutput { get; set; }
19+
}
20+
21+
public class ActivityInput
22+
{
23+
public string Value1 { get; set; }
24+
public int Value2 { get; set; }
25+
}
26+
27+
public class ActivityOutput
28+
{
29+
public string Value1 { get; set; }
30+
public int Value2 { get; set; }
31+
}
32+
33+
public class ActivityWorkflow : IWorkflow<MyDataClass>
34+
{
35+
public string Id => "ActivityWorkflow";
36+
public int Version => 1;
37+
public void Build(IWorkflowBuilder<MyDataClass> builder)
38+
{
39+
builder
40+
.StartWith(context => ExecutionResult.Next())
41+
.Activity((_, context) => "act-1-" + context.Workflow.Id, data => data.ActivityInput)
42+
.Output(data => data.ActivityOutput, step => step.Result);
43+
}
44+
}
45+
46+
public ActivityScenario2()
47+
{
48+
Setup();
49+
}
50+
51+
[Fact]
52+
public void Scenario()
53+
{
54+
// compound key
55+
var workflowId = StartWorkflow(new MyDataClass { ActivityInput = new ActivityInput { Value1 = "a", Value2 = 1 } });
56+
var activity = Host.GetPendingActivity("act-1-" + workflowId, "worker1", TimeSpan.FromSeconds(30)).Result;
57+
58+
if (activity != null)
59+
{
60+
var actInput = (ActivityInput)activity.Parameters;
61+
Host.SubmitActivitySuccess(activity.Token, new ActivityOutput
62+
{
63+
Value1 = actInput.Value1 + "1",
64+
Value2 = actInput.Value2 + 1
65+
});
66+
}
67+
68+
WaitForWorkflowToComplete(workflowId, TimeSpan.FromSeconds(30));
69+
GetStatus(workflowId).Should().Be(WorkflowStatus.Complete);
70+
UnhandledStepErrors.Count.Should().Be(0);
71+
GetData(workflowId).ActivityOutput.Should().BeOfType<ActivityOutput>();
72+
var outData = (GetData(workflowId).ActivityOutput as ActivityOutput);
73+
outData.Value1.Should().Be("a1");
74+
outData.Value2.Should().Be(2);
75+
}
76+
}*/
77+
78+
}

0 commit comments

Comments
 (0)