Skip to content

Commit 1adfc8d

Browse files
committed
samples
1 parent c2e9a40 commit 1adfc8d

File tree

9 files changed

+133
-77
lines changed

9 files changed

+133
-77
lines changed

WorkflowCore.Sample09/ForEachWorkflow.cs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,17 @@ namespace WorkflowCore.Sample09
99
public class ForEachWorkflow : IWorkflow
1010
{
1111
public string Id => "Foreach";
12-
1312
public int Version => 1;
1413

1514
public void Build(IWorkflowBuilder<object> builder)
1615
{
1716
builder
18-
.StartWith(context =>
19-
{
20-
Console.WriteLine("Hello");
21-
return ExecutionResult.Next();
22-
})
17+
.StartWith<SayHello>()
2318
.ForEach(data => new List<int>() { 1, 2, 3, 4 })
2419
.Do(x => x
25-
.StartWith(context =>
26-
{
27-
Console.WriteLine($"iteration {context.Item}");
28-
return ExecutionResult.Next();
29-
})
30-
.Then(context =>
31-
{
32-
Console.WriteLine($"step2 {context.Item}");
33-
return ExecutionResult.Next();
34-
}))
35-
.Then(context =>
36-
{
37-
Console.WriteLine("bye");
38-
return ExecutionResult.Next();
39-
});
20+
.StartWith<DisplayContext>()
21+
.Then<DoSomething>())
22+
.Then<SayGoodbye>();
4023
}
41-
}
24+
}
4225
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using WorkflowCore.Interface;
5+
using WorkflowCore.Models;
6+
7+
namespace WorkflowCore.Sample09
8+
{
9+
public class DisplayContext : StepBody
10+
{
11+
public override ExecutionResult Run(IStepExecutionContext context)
12+
{
13+
Console.WriteLine($"Working on item {context.Item}");
14+
return ExecutionResult.Next();
15+
}
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using WorkflowCore.Interface;
5+
using WorkflowCore.Models;
6+
7+
namespace WorkflowCore.Sample09
8+
{
9+
public class DoSomething : StepBody
10+
{
11+
public override ExecutionResult Run(IStepExecutionContext context)
12+
{
13+
Console.WriteLine("Doing something...");
14+
return ExecutionResult.Next();
15+
}
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using WorkflowCore.Interface;
5+
using WorkflowCore.Models;
6+
7+
namespace WorkflowCore.Sample09
8+
{
9+
public class SayGoodbye : StepBody
10+
{
11+
public override ExecutionResult Run(IStepExecutionContext context)
12+
{
13+
Console.WriteLine("Goodbye");
14+
return ExecutionResult.Next();
15+
}
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using WorkflowCore.Interface;
5+
using WorkflowCore.Models;
6+
7+
namespace WorkflowCore.Sample09
8+
{
9+
public class SayHello : StepBody
10+
{
11+
public override ExecutionResult Run(IStepExecutionContext context)
12+
{
13+
Console.WriteLine("Hello");
14+
return ExecutionResult.Next();
15+
}
16+
}
17+
}

src/WorkflowCore/Interface/IStepBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public interface IStepBuilder<TData, TStepBody>
8585
/// Ends the workflow and marks it as complete
8686
/// </summary>
8787
/// <returns></returns>
88-
IStepBuilder<TData, TStepBody> EndWorkflow();
88+
//IStepBuilder<TData, TStepBody> EndWorkflow();
8989

9090
IParentStepBuilder<TData, Foreach> ForEach(Expression<Func<TData, IEnumerable>> collection);
9191

src/WorkflowCore/Services/StepBuilder.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ private WorkflowStep IterateParents(int id, string name)
141141
return null;
142142
}
143143

144-
public IStepBuilder<TData, TStepBody> EndWorkflow()
145-
{
146-
EndStep newStep = new EndStep();
147-
WorkflowBuilder.AddStep(newStep);
148-
Step.Outcomes.Add(new StepOutcome() { NextStep = newStep.Id });
149-
return this;
150-
}
144+
//public IStepBuilder<TData, TStepBody> EndWorkflow()
145+
//{
146+
// EndStep newStep = new EndStep();
147+
// WorkflowBuilder.AddStep(newStep);
148+
// Step.Outcomes.Add(new StepOutcome() { NextStep = newStep.Id });
149+
// return this;
150+
//}
151151

152152
public IParentStepBuilder<TData, Foreach> ForEach(Expression<Func<TData, IEnumerable>> collection)
153153
{
Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using FluentAssertions;
2+
using System;
23
using System.Collections.Generic;
34
using System.Text;
45
using WorkflowCore.Interface;
@@ -7,53 +8,57 @@
78

89
namespace WorkflowCore.IntegrationTests.Scenarios
910
{
10-
public class EndStepScenario : BaseScenario<EndStepScenario.ScenarioWorkflow, Object>
11-
{
12-
internal static int StartStepCounter = 0;
13-
internal static int Branch1Counter = 0;
14-
internal static int Branch2Counter = 0;
11+
//public class EndStepScenario : BaseScenario<EndStepScenario.ScenarioWorkflow, Object>
12+
//{
13+
// internal static int StartStepCounter = 0;
14+
// internal static int MidStepCounter = 0;
15+
// internal static int EndStepCounter = 0;
1516

16-
public class ScenarioWorkflow : IWorkflow
17-
{
18-
public string Id => "EndStepScenario";
19-
public int Version => 1;
20-
public void Build(IWorkflowBuilder<Object> builder)
21-
{
22-
var step1 = builder.StartWith(context =>
23-
{
24-
StartStepCounter++;
25-
return ExecutionResult.Outcome(1);
26-
});
17+
// public class ScenarioWorkflow : IWorkflow
18+
// {
19+
// public string Id => "EndStepScenario";
20+
// public int Version => 1;
21+
// public void Build(IWorkflowBuilder<Object> builder)
22+
// {
23+
// builder
24+
// .StartWith(context =>
25+
// {
26+
// StartStepCounter++;
27+
// return ExecutionResult.Next();
28+
// })
29+
// .While(x => true)
30+
// .Do(x => x
31+
// .StartWith(context =>
32+
// {
33+
// MidStepCounter++;
34+
// return ExecutionResult.Next();
35+
// }))
36+
// .EndWorkflow()
37+
// .Then(context =>
38+
// {
39+
// EndStepCounter++;
40+
// return ExecutionResult.Next();
41+
// });
42+
// }
43+
// }
2744

28-
step1
29-
.When(1)
30-
.Then(context => ExecutionResult.Next());
45+
// [Fact]
46+
// public void Scenario()
47+
// {
48+
// var workflowId = Host.StartWorkflow("EndStepScenario").Result;
49+
// var instance = PersistenceProvider.GetWorkflowInstance(workflowId).Result;
50+
// int counter = 0;
51+
// while ((instance.Status == WorkflowStatus.Runnable) && (counter < 300))
52+
// {
53+
// System.Threading.Thread.Sleep(100);
54+
// counter++;
55+
// instance = PersistenceProvider.GetWorkflowInstance(workflowId).Result;
56+
// }
3157

32-
step1
33-
.When(1)
34-
.Then(context =>
35-
{
36-
Branch1Counter++;
37-
return ExecutionResult.Next();
38-
});
39-
}
40-
}
41-
42-
//[Fact]
43-
public void Scenario()
44-
{
45-
var workflowId = Host.StartWorkflow("EndStepScenario").Result;
46-
var instance = PersistenceProvider.GetWorkflowInstance(workflowId).Result;
47-
int counter = 0;
48-
while ((instance.Status == WorkflowStatus.Runnable) && (counter < 300))
49-
{
50-
System.Threading.Thread.Sleep(100);
51-
counter++;
52-
instance = PersistenceProvider.GetWorkflowInstance(workflowId).Result;
53-
}
54-
55-
56-
}
57-
58-
}
58+
// instance.Status.Should().Be(WorkflowStatus.Complete);
59+
// StartStepCounter.Should().Be(1);
60+
// MidStepCounter.Should().Be(1);
61+
// EndStepCounter.Should().Be(0);
62+
// }
63+
//}
5964
}

0 commit comments

Comments
 (0)