EasySignWorkFlow 1.0.6
dotnet add package EasySignWorkFlow --version 1.0.6
NuGet\Install-Package EasySignWorkFlow -Version 1.0.6
<PackageReference Include="EasySignWorkFlow" Version="1.0.6" />
paket add EasySignWorkFlow --version 1.0.6
#r "nuget: EasySignWorkFlow, 1.0.6"
// Install EasySignWorkFlow as a Cake Addin #addin nuget:?package=EasySignWorkFlow&version=1.0.6 // Install EasySignWorkFlow as a Cake Tool #tool nuget:?package=EasySignWorkFlow&version=1.0.6
EasySignWorkFlow
EasySignWorkFlow is a C# library designed to provide a flexible and easy-to-use workflow management system. It allows you to define and manage state transitions, perform actions during transitions, and set custom rules for workflows. With features like state validation, transition conditions, and customizable behaviors, EasySignWorkFlow is perfect for implementing approval processes, request management, or any workflow-based application.
Features
- State Management: Define states and manage transitions seamlessly.
- Flexible Conditions: Add conditional logic to transitions with
If
andIfAsync
methods. - Custom Actions: Execute custom logic during transitions.
- Extensibility: Easily extend and customize workflows with user-defined states and transitions.
- Date Providers: Use
DateTimeProvider
to control how dates are handled (UTC or local). - Database Integration: Works well with EF Core to persist requests and their states.
Installation
To install the library, add the following package to your project:
Install-Package EasySignWorkFlow
Or use the .NET CLI:
dotnet add package EasySignWorkFlow
Getting Started
Define Your Request
Create a class that implements the IRequest<TKey, TStatus>
interface:
public class TestRequest : IRequest<Guid, TestStatus>
{
public Guid Id { get; set; }
public string? Title { get; set; }
public bool Flag { get; set; }
public List<State<Guid, TestStatus>> Statuses { get; } = new();
public State<Guid, TestStatus>? CurrentState { get; set; }
}
Configure Your Workflow
Use the FlowMachine
class to define states and transitions:
public class TestRequestService
{
private readonly FlowMachine<TestRequest, Guid, TestStatus> _flowMachine;
private readonly DemoDBContext _context;
public TestRequestService(DemoDBContext context)
{
_context = context;
_flowMachine = FlowMachine<TestRequest, Guid, TestStatus>
.Create(TestStatus.Draft, (request, current, next) =>
{
Console.WriteLine($"Transitioning from {current} to {next}");
return Task.CompletedTask;
});
_flowMachine.SetCancelState(TestStatus.Canceled)
.SetRefuseState(TestStatus.Refused)
.SetDateTimeProvider(DateTimeProvider.Now);
// Define transitions
_flowMachine.When(TestStatus.Draft)
.If(request => request.Flag)
.Set(TestStatus.WaitingForManager1)
.SetNextUsers((request, _) => new List<Guid> { Guid.NewGuid() })
.OnExecute((request, current, next, nextUserIds) =>
{
Console.WriteLine($"{request.Title} moved from {current} to {next}");
});
_flowMachine.When(TestStatus.WaitingForManager1)
.If(request => !request.Flag)
.Set(TestStatus.Accepted)
.OnExecute((request, current, next, nextUserIds) =>
{
Console.WriteLine($"{request.Title} moved from {current} to {next}");
});
}
public string PrintWorkflow() => _flowMachine.ToString();
}
Workflow in Action
Execute the workflow by calling the FireAsync
method:
var request = new TestRequest
{
Id = Guid.NewGuid(),
Title = "Sample Request",
Flag = true
};
var isSuccess = await _flowMachine.FireAsync(request, TestStatus.Draft);
if (isSuccess)
{
Console.WriteLine("Transition successful.");
}
else
{
Console.WriteLine("Transition failed.");
}
Example Use Case
Database Integration
You can integrate EasySignWorkFlow with EF Core to persist requests and their states:
public class DemoDBContext : DbContext
{
public DemoDBContext(DbContextOptions<DemoDBContext> options) : base(options) { }
public DbSet<TestRequest> TestRequests { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ConfigureRequest<TestRequest, Guid, TestStatus>();
base.OnModelCreating(modelBuilder);
}
}
Querying States
Fetch requests based on their current state:
public async Task<List<TestRequest>> GetDraftRequests()
{
return await _context.TestRequests
.Where(r => r.CurrentState.Status == TestStatus.Draft)
.ToListAsync();
}
Key Classes
IRequest<TKey, TStatus>
Defines a request with a collection of states and a current state.
FlowMachine<TRequest, TKey, TStatus>
The core class for defining and managing workflows.
Transition<TRequest, TKey, TStatus>
Handles individual state transitions, including conditions and custom actions.
State<TKey, TStatus>
Represents a state in the workflow, including metadata like date and user.
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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 is compatible. 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. |
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.12)
-
net9.0
- Microsoft.EntityFrameworkCore (>= 9.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on EasySignWorkFlow:
Package | Downloads |
---|---|
EasySignWorkFlow.EFCore
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
1.0.6 | 69 | 1/27/2025 | |
1.0.4 | 1,732 | 5/2/2024 | |
1.0.3 | 136 | 4/29/2024 | |
1.0.2 | 2,295 | 4/20/2024 | |
1.0.1 | 126 | 4/20/2024 | |
1.0.1-zeta | 115 | 4/17/2024 | |
1.0.1-beta | 161 | 4/11/2024 | |
1.0.1-alpha | 11,666 | 11/5/2023 | |
1.0.0 | 236 | 10/6/2023 | |
1.0.0-beta | 126 | 9/23/2023 |