├── .github
└── workflows
│ └── dotnet.yml
├── .gitignore
├── LICENSE
├── NetWorkflow.Extensions
├── Extensions.cs
└── NetWorkflow.Extensions.csproj
├── NetWorkflow.Tests
├── Examples
│ ├── ConditionalParallelWorkflow.cs
│ ├── ConditionalStopWorkflow.cs
│ ├── ConditionalThrowWorkflow.cs
│ ├── ConditionalWorkflow.cs
│ ├── HelloWorldWorkflow.cs
│ ├── ParallelWorkflow.cs
│ └── RetryExample.cs
├── NetWorkflow.Tests.csproj
├── Usings.cs
├── WorkflowScheduler_Tests.cs
├── WorkflowTime_Tests.cs
└── Workflow_Tests.cs
├── NetWorkflow.sln
├── NetWorkflow
├── Exceptions
│ ├── WorkflowInvalidValueException.cs
│ ├── WorkflowMaxRetryException.cs
│ ├── WorkflowNoConditionMetException.cs
│ └── WorkflowStoppedException.cs
├── Executors
│ ├── WorkflowConditionalExecutor.cs
│ ├── WorkflowMoveNextExecutor.cs
│ ├── WorkflowParallelExecutor.cs
│ ├── WorkflowStepAsyncExecutor.cs
│ └── WorkflowStepExecutor.cs
├── Interfaces
│ ├── IWorkflow.cs
│ ├── IWorkflowBuilder.cs
│ ├── IWorkflowBuilderConditional.cs
│ ├── IWorkflowBuilderConditionalFinal.cs
│ ├── IWorkflowBuilderConditionalFinalAggregate.cs
│ ├── IWorkflowBuilderConditionalNext.cs
│ ├── IWorkflowBuilderNext.cs
│ ├── IWorkflowExecutor.cs
│ └── IWorkflowStep.cs
├── NetWorkflow.csproj
├── Scheduler
│ ├── WorkflowScheduler.cs
│ ├── WorkflowSchedulerConfiguration.cs
│ └── WorkflowTime.cs
├── Workflow.cs
├── WorkflowBuilder.cs
├── WorkflowOptions.cs
└── WorkflowResult.cs
└── README.md
/.github/workflows/dotnet.yml:
--------------------------------------------------------------------------------
1 | name: .NET
2 |
3 | on: [ push, pull_request ]
4 |
5 | jobs:
6 | build-job:
7 | runs-on: ubuntu-latest
8 | steps:
9 | - uses: actions/checkout@v2
10 | - name: Setup .NET 7.x
11 | uses: actions/setup-dotnet@v1
12 | with:
13 | dotnet-version: 7.x
14 | - name: Restore dependencies
15 | run: dotnet restore
16 | - name: Build
17 | run: |
18 | dotnet build NetWorkflow.sln \
19 | -c Release
20 | - name: Test net7.0
21 | run: |
22 | dotnet test NetWorkflow.Tests/NetWorkflow.Tests.csproj \
23 | -c Release --no-build --no-restore \
24 | -f net7.0 \
25 | -v normal \
26 | --filter "TestCategory!=very.slow"
27 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist
3 | .vs
4 | obj
5 | bin
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Travis Arndt
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/NetWorkflow.Extensions/Extensions.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.DependencyInjection;
2 | using NetWorkflow.Scheduler;
3 |
4 | namespace NetWorkflow.Extensions
5 | {
6 | public static class Extensions
7 | {
8 | ///
9 | /// Adds a transient Workflow of type TWorkflow to the IOC container
10 | ///
11 | /// The type of Workflow to register.
12 | /// The IServiceCollection to register the Workflow to.
13 | public static IServiceCollection AddWorkflow(this IServiceCollection services, Func func)
14 | where TWorkflow : class, IWorkflow
15 | {
16 | return services.AddTransient(x => func.Invoke());
17 | }
18 |
19 | ///
20 | /// Adds a transient Workflow of type TWorkflow with an implementation of TImplementation to the IOC container
21 | ///
22 | /// The type of Workflow to register.
23 | /// The implementation Workflow type to resolve to.
24 | /// The IServiceCollection to register the Workflow to.
25 | public static IServiceCollection AddWorkflow(this IServiceCollection services, Func func)
26 | where TWorkflow : class, IWorkflow
27 | where TImplementation : class, TWorkflow
28 | {
29 | return services.AddTransient(x => func.Invoke());
30 | }
31 |
32 | ///
33 | /// Adds a transient WorkflowScheduler to the IOC container
34 | ///
35 | /// The type of Workflow the WorkflowScheduler uses.
36 | /// The IServiceCollection to register the WorkflowScheduler to.
37 | public static IServiceCollection AddWorkflowScheduler(this IServiceCollection services, Func> func)
38 | where TWorkflow : class, IWorkflow
39 | {
40 | return services.AddTransient(x => func.Invoke());
41 | }
42 | }
43 | }
--------------------------------------------------------------------------------
/NetWorkflow.Extensions/NetWorkflow.Extensions.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Travis Arndt
5 | net6.0
6 | enable
7 | disable
8 | NetWorkflow.Extensions
9 | NetWorklow.Extensions extends the NetWorkflow library.
10 | https://github.com/Tmarndt1/NetWorkflow
11 | https://github.com/Tmarndt1/NetWorkflow
12 | LICENSE
13 | Fluent;NetWorkflow;Net;Workflow;Extensions;
14 | 3.0.0
15 |
16 |
17 |
18 |
19 | True
20 | \
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/NetWorkflow.Tests/Examples/ConditionalParallelWorkflow.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace NetWorkflow.Tests.Examples
3 | {
4 | public class ConditionalParallelWorkflow : Workflow
5 | {
6 | public override IWorkflowBuilder Build(IWorkflowBuilder builder) =>
7 | builder
8 | .StartWith(() => new FirstStep())
9 | .Parallel(() => new IWorkflowStepAsync[]
10 | {
11 | new Step2(50),
12 | new Step2(100),
13 | })
14 | .Then(() => new FlattenStep())
15 | .If(x => x.Contains(","))
16 | .Do(() => new ConditionalStep(1))
17 | .ElseIf(x => x == "Failed")
18 | .Do(() => new ConditionalStep(-1))
19 | .EndIf()
20 | .ThenAsync(() => new FinalStepAsync());
21 |
22 |
23 | private class Step2 : IWorkflowStepAsync
24 | {
25 | private readonly int _delay;
26 |
27 | public Step2(int delay)
28 | {
29 | _delay = delay;
30 | }
31 |
32 | public Task RunAsync(string args, CancellationToken token = default)
33 | {
34 | return Task.Run(() =>
35 | {
36 | Thread.Sleep(_delay);
37 |
38 | return $"{nameof(Step2)} ran";
39 | }, token);
40 | }
41 | }
42 |
43 | private class FirstStep : IWorkflowStep
44 | {
45 | public string Run(CancellationToken token = default)
46 | {
47 | return "Failed";
48 | }
49 | }
50 | private class FlattenStep : IWorkflowStep, string>
51 | {
52 | public string Run(IEnumerable args, CancellationToken token = default)
53 | {
54 | return string.Join(", ", args);
55 | }
56 | }
57 |
58 | private class ConditionalStep : IWorkflowStep
59 | {
60 | private readonly int _result;
61 |
62 | public ConditionalStep(int result)
63 | {
64 | _result = result;
65 | }
66 |
67 | public int Run(string args, CancellationToken token = default)
68 | {
69 | return _result;
70 | }
71 | }
72 |
73 | private class FinalStepAsync : IWorkflowStepAsync