NetWorkflow 2.0.0

There is a newer version of this package available.
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                
#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                

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: Build Status

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 150 5/20/2023
2.0.0 414 10/13/2022
1.1.0 366 10/10/2022
1.0.1 383 10/8/2022
1.0.0 356 10/7/2022