Skip to content

Commit 3112793

Browse files
committed
samples
1 parent 2c16cda commit 3112793

File tree

7 files changed

+119
-1
lines changed

7 files changed

+119
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ There are several persistence providers available as separate Nuget packages.
106106

107107
* [Parallel Tasks](src/samples/WorkflowCore.Sample13)
108108

109+
* [Scheduled Background Tasks](src/samples/WorkflowCore.Sample16)
110+
111+
* [Recurring Background Tasks](src/samples/WorkflowCore.Sample14)
112+
109113
* [Dependency Injection](src/samples/WorkflowCore.Sample15)
110114

111115
* [Deferred execution & re-entrant steps](src/samples/WorkflowCore.Sample05)

WorkflowCore.sln

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26730.16
4+
VisualStudioVersion = 15.0.27004.2008
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{EF47161E-E399-451C-BDE8-E92AAD3BD761}"
77
EndProject
@@ -99,6 +99,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Docker.Testify", "test\Dock
9999
EndProject
100100
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorkflowCore.Sample15", "src\samples\WorkflowCore.Sample15\WorkflowCore.Sample15.csproj", "{9B7811AC-68D6-4D19-B1E9-65423393ED83}"
101101
EndProject
102+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WorkflowCore.Sample16", "src\samples\WorkflowCore.Sample16\WorkflowCore.Sample16.csproj", "{0C9617A9-C8B7-45F6-A54A-261A23AC881B}"
103+
EndProject
102104
Global
103105
GlobalSection(SolutionConfigurationPlatforms) = preSolution
104106
Debug|Any CPU = Debug|Any CPU
@@ -253,6 +255,10 @@ Global
253255
{9B7811AC-68D6-4D19-B1E9-65423393ED83}.Debug|Any CPU.Build.0 = Debug|Any CPU
254256
{9B7811AC-68D6-4D19-B1E9-65423393ED83}.Release|Any CPU.ActiveCfg = Release|Any CPU
255257
{9B7811AC-68D6-4D19-B1E9-65423393ED83}.Release|Any CPU.Build.0 = Release|Any CPU
258+
{0C9617A9-C8B7-45F6-A54A-261A23AC881B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
259+
{0C9617A9-C8B7-45F6-A54A-261A23AC881B}.Debug|Any CPU.Build.0 = Debug|Any CPU
260+
{0C9617A9-C8B7-45F6-A54A-261A23AC881B}.Release|Any CPU.ActiveCfg = Release|Any CPU
261+
{0C9617A9-C8B7-45F6-A54A-261A23AC881B}.Release|Any CPU.Build.0 = Release|Any CPU
256262
EndGlobalSection
257263
GlobalSection(SolutionProperties) = preSolution
258264
HideSolutionNode = FALSE
@@ -298,6 +304,7 @@ Global
298304
{0E3C1496-8E7C-411A-A536-C7C9CE4EED4E} = {5080DB09-CBE8-4C45-9957-C3BB7651755E}
299305
{EC497168-5347-4E70-9D9E-9C2F826C1CDF} = {E6CEAD8D-F565-471E-A0DC-676F54EAEDEB}
300306
{9B7811AC-68D6-4D19-B1E9-65423393ED83} = {5080DB09-CBE8-4C45-9957-C3BB7651755E}
307+
{0C9617A9-C8B7-45F6-A54A-261A23AC881B} = {5080DB09-CBE8-4C45-9957-C3BB7651755E}
301308
EndGlobalSection
302309
GlobalSection(ExtensibilityGlobals) = postSolution
303310
SolutionGuid = {DC0FA8D3-6449-4FDA-BB46-ECF58FAD23B4}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Recur sample
2+
3+
Illustrates how to run a set of recurring background steps within your workflow, until a certain condition is met
4+
5+
6+
```c#
7+
builder
8+
.StartWith(context => Console.WriteLine("Hello"))
9+
.Recur(data => TimeSpan.FromSeconds(5), data => data.Counter > 5).Do(recur => recur
10+
.StartWith(context => Console.WriteLine("Doing recurring task"))
11+
)
12+
.Then(context => Console.WriteLine("Carry on"));
13+
```
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using Microsoft.Extensions.Logging;
3+
using System;
4+
using WorkflowCore.Interface;
5+
6+
namespace WorkflowCore.Sample16
7+
{
8+
class Program
9+
{
10+
static void Main(string[] args)
11+
{
12+
var serviceProvider = ConfigureServices();
13+
14+
//start the workflow host
15+
var host = serviceProvider.GetService<IWorkflowHost>();
16+
host.RegisterWorkflow<ScheduleWorkflow>();
17+
host.Start();
18+
19+
Console.WriteLine("Starting workflow...");
20+
var workflowId = host.StartWorkflow("schedule-sample").Result;
21+
22+
Console.ReadLine();
23+
host.Stop();
24+
}
25+
26+
private static IServiceProvider ConfigureServices()
27+
{
28+
//setup dependency injection
29+
IServiceCollection services = new ServiceCollection();
30+
services.AddLogging();
31+
services.AddWorkflow();
32+
33+
var serviceProvider = services.BuildServiceProvider();
34+
35+
//config logging
36+
var loggerFactory = serviceProvider.GetService<ILoggerFactory>();
37+
//loggerFactory.AddDebug(LogLevel.Debug);
38+
return serviceProvider;
39+
}
40+
}
41+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Schedule sample
2+
3+
Illustrates how to schedule a future set of steps to run asynchronously in the background within your workflow.
4+
5+
6+
```c#
7+
builder
8+
.StartWith(context => Console.WriteLine("Hello"))
9+
.Schedule(data => TimeSpan.FromSeconds(5)).Do(schedule => schedule
10+
.StartWith(context => Console.WriteLine("Doing scheduled tasks"))
11+
)
12+
.Then(context => Console.WriteLine("Doing normal tasks"));
13+
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using WorkflowCore.Interface;
5+
6+
namespace WorkflowCore.Sample16
7+
{
8+
class ScheduleWorkflow : IWorkflow
9+
{
10+
public string Id => "schedule-sample";
11+
public int Version => 1;
12+
13+
public void Build(IWorkflowBuilder<object> builder)
14+
{
15+
builder
16+
.StartWith(context => Console.WriteLine("Hello"))
17+
.Schedule(data => TimeSpan.FromSeconds(5)).Do(schedule => schedule
18+
.StartWith(context => Console.WriteLine("Doing scheduled tasks"))
19+
)
20+
.Then(context => Console.WriteLine("Doing normal tasks"));
21+
}
22+
}
23+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="1.1.0" />
10+
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.2" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\..\WorkflowCore\WorkflowCore.csproj" />
15+
</ItemGroup>
16+
17+
</Project>

0 commit comments

Comments
 (0)