NetWorkflow 2.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package NetWorkflow --version 2.0.0
NuGet\Install-Package NetWorkflow -Version 2.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NetWorkflow" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetWorkflow --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NetWorkflow, 2.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NetWorkflow as a Cake Addin #addin nuget:?package=NetWorkflow&version=2.0.0 // Install NetWorkflow as a Cake Tool #tool nuget:?package=NetWorkflow&version=2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
NetWorkflow
NetWorkflow is a light weight C# .NET Workflow library that leverages the fluent syntax and allows a user to explicitly define their WorkflowSteps in a single location with compile time validation with the arguments passed between steps.
main:
Give a Star! ⭐
If you like or are using this project please give it a star. Thanks!
HelloWorld Workflow Example
using NetWorkflow;
public class HelloWorldWorkflow : Workflow<bool>
{
private const string _helloWorld = "HelloWorld";
public override IWorkflowBuilder<bool> Build(IWorkflowBuilder builder) =>
builder
.StartWith(() => new HelloWorld())
.Then(() => new GoodbyeWorld());
private class HelloWorld : IWorkflowStep<string>
{
public string Run(CancellationToken token = default)
{
return _helloWorld;
}
}
private class GoodbyeWorld : IWorkflowStep<string, bool>
{
public bool Run(string args, CancellationToken token = default)
{
return args == _helloWorld;
}
}
}
Conditional Workflow Example
using NetWorkflow;
public class ConditionalWorkflow : Workflow<int>
{
private readonly string _message;
public ConditionalWorkflow(string message)
{
_message = message;
}
public override IWorkflowBuilder<int> Build(IWorkflowBuilder builder) =>
builder
.StartWith(() => new FirstStep(_message))
.If(x => x == "Success")
.Do(() => new ConditionalStep())
.ElseIf(x => x == "Failed")
.Do(() => new ConditionalStep())
.Else()
.Retry(TimeSpan.FromSeconds(10), 2) // Max retry 2 times
.EndIf()
.Then(() => new FinalStep());
// Example WorkflowStep
private class FirstStep : IWorkflowStep<string>
{
private readonly string _message;
internal FirstStep(string message)
{
_message = message;
}
public string Run(CancellationToken token = default)
{
return _message;
}
}
// Other WorkflowSteps are omitted to simplify example!
}
// Implicit cast to an int
int result = new ConditionalWorkflow().Run();
Parallel Workflow Example
using NetWorkflow;
public class ParallelWorkflow : Workflow<string[]>
{
public override IWorkflowBuilder<string[]> Build(IWorkflowBuilder builder) =>
builder
.StartWith(() => new Step1())
.Parallel(() => new IWorkflowStepAsync<Guid, string>[]
{
new AsyncStep1(),
new AsyncStep2()
})
.ThenAsync(() => new AsyncStep3())
.ThenAsync(() => AsyncStep4());
// Example Async WorkflowStep
private class AsyncStep1 : IWorkflowStepAsync<Guid, string[]>
{
public Task<string[]> RunAsync(Guid args, CancellationToken token = default)
{
return Task.Delay(500, token).ContinueWith(t => new string[]
{
"Hello",
"World"
}, token);
}
}
// Other WorkflowSteps are omitted to simplify example!
}
// Implicit cast to a string array
string[] results = new ParallelWorkflow()
.Run(new CancellationTokenSource().Token);
WorkflowScheduler AtFrequency Example
using NetWorkflow.Scheduler;
var scheduler = new WorkflowScheduler<HelloWorldWorkflow>()
.Use(() => new HelloWorldWorkflow()) // Will call the factory method on when scheduled
.Configure(options =>
{
// Schedules the Workflow to be kicked off every 30 seconds
options.ExecuteAt = WorkflowTime.AtFrequency(TimeSpan.FromSeconds(30));
});
await scheduler.StartAsync();
WorkflowScheduler AtDateTime Example
using NetWorkflow.Scheduler;
var scheduler = new WorkflowScheduler<HelloWorldWorkflow>()
.Use(() => new HelloWorldWorkflow()) // Will call the factory method on when scheduled
.Configure(options =>
{
// Schedules the Workflow to be kicked off at midnight everyday
options.ExecuteAt = WorkflowTime.AtHour(0).Repeat();
});
await scheduler.StartAsync();
Authors
- Travis Arndt
License
This project is licensed under the MIT License - LICENSE.md
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- System.Linq.Expressions (>= 4.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.