FlowMaker.SourceGenerator 0.1.0-preview1

This is a prerelease version of FlowMaker.SourceGenerator.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package FlowMaker.SourceGenerator --version 0.1.0-preview1                
NuGet\Install-Package FlowMaker.SourceGenerator -Version 0.1.0-preview1                
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="FlowMaker.SourceGenerator" Version="0.1.0-preview1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FlowMaker.SourceGenerator --version 0.1.0-preview1                
#r "nuget: FlowMaker.SourceGenerator, 0.1.0-preview1"                
#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 FlowMaker.SourceGenerator as a Cake Addin
#addin nuget:?package=FlowMaker.SourceGenerator&version=0.1.0-preview1&prerelease

// Install FlowMaker.SourceGenerator as a Cake Tool
#tool nuget:?package=FlowMaker.SourceGenerator&version=0.1.0-preview1&prerelease                

FlowMaker

FlowMaker是一个基于.NET8的流程编辑执行框架

为您提供简洁API, 方便的中间件开发体验

流程

FlowManager,可进行初始化,执行,停止,发送事件等操作。

IFlowProvider,可以对流程序列进行保存和读取。

步骤

  1. 无参数步骤
public partial class MyClass : IStep
{
    public static string Category => "类别";

    public static string Name => "名称";

    public Task Run(StepContext stepContext, CancellationToken cancellationToken)
    {
        throw new NotImplementedException();
    }
}
	//注册相关步骤
	hostApplicationBuilder.Services.AddFlowStep<MyClass>();
  1. 有输入输出的步骤
public partial class MyClass : IStep
{
    public static string Category => "Test1";

    public static string Name => "输入输出各一个";

    [Input]
    public int Input { get; set; }
    [Output]
    public int Output { get; set; }
    
    public Task Run( StepContext stepContext, CancellationToken cancellationToken)
    {
        Output = Input * 2;
        return Task.CompletedTask;
    }
}

输入参数可以添加多种特性标签

    [DefaultValue("3")]
    [Description("属性2")]
    [Option("三", "3")]
    [Option("四", "4")]
    public int Prop2 { get; set; }
  1. 将整个类转换为步骤,上下文和取消令牌分别为第一个参数与最后一个参数,如果不需要可以不填写。
    [Steps("Category")]
    public class AllStepMode
    {
        [Description("算法A")]//通过特性标签改变显示名称
        public (int, string) Test(int ss = 3, CancellationToken cancellationToken = default)
        {
            return (ss, "ss");
        }

        public int Test2(StepContext stepContext, DayOfWeek ss, CancellationToken cancellationToken)
        {
            return 1;
        }
    }
	//注册相关步骤
	hostApplicationBuilder.Services.AddScoped<AllStepMode>();
	hostApplicationBuilder.Services.AddAllStepModeFlowStep();
  1. 将接口转换为步骤,与将整个类转换为步骤类似,但是输入中会多出配置具体实现的参数。
 [Steps("FFF")]
 public interface ITestStep
 {
     Task<int> Test(StepContext stepContext, int ss = 2);
 }
    //注册相关步骤
	hostApplicationBuilder.Services.AddITestStepFlowStep();
    hostApplicationBuilder.Services.AddKeyedScoped<ITestStep, TestStep1>("Test1");
    hostApplicationBuilder.Services.AddKeyedScoped<ITestStep, TestStep2>("Test2");
	//配置选项
    hostApplicationBuilder.Services.Configure<ITestStepInstanceOption>(c =>
    {
        c.Instances.Add(new FlowMaker.NameValue("Test1", "Test1"));
        c.Instances.Add(new FlowMaker.NameValue("Test2", "Test2"));
    });
  1. 选项提供类,提供可变化的参数选项下拉框
    public partial class PortProvider : IOptionProvider<string>
    {
        public static string DisplayName => "串口";

        public async Task<IEnumerable<NameValue>> GetOptions()
        {
            await Task.CompletedTask;
            return [new("oo", "22"), new("oo22", "2211")];
        }
    }
	//注册选项提供类
	hostApplicationBuilder.Services.AddFlowOption<PortProvider>();

转换器

配置流程时可以对输入输出的信息进行加工,此时需要用到转换器,实现方式于步骤类似,但是根据转换器的类型有固定的返回类型

public partial class ValueConverter : IDataConverter<int>
{
    public static string Category => "Test1";

    public static string Name => "转换器1";

    [Input]
    public int Prop1 { get; set; }
    [Input]
    public int Prop2 { get; set; }

    public Task<int> Convert(FlowContext? context, CancellationToken cancellationToken)
    {
        return Task.FromResult(Prop1 + Prop2);
    }
}
	//注册转换器
	hostApplicationBuilder.Services.AddFlowConverter<ValueConverter>();

中间件

提供了5种中间件

  1. IFlowMiddleware 流程的开始与结束
  2. IStepMiddleware 步骤的开始与结束
  3. IStepOnceMiddleware 步骤的单次执行时的开始与结束(如重复与重试)
  4. IEventMiddleware 事件触发时
  5. ILogMiddleware 记录日志时
public interface IFlowMiddleware
{
    Task OnExecuting(FlowContext flowContext, FlowState runnerState, CancellationToken cancellationToken);
    Task OnExecuted(FlowContext flowContext, FlowState runnerState, Exception? exception, CancellationToken cancellationToken);
}
public interface IStepMiddleware
{
    Task OnExecuting(FlowContext flowContext, FlowStep flowStep, StepStatus step, CancellationToken cancellationToken);
    Task OnExecuted(FlowContext flowContext, FlowStep flowStep, StepStatus step, Exception? exception, CancellationToken cancellationToken);
}
public interface IStepOnceMiddleware
{
    Task OnExecuting(FlowContext flowContext, FlowStep flowStep, StepStatus step, StepOnceStatus stepOnceStatus, CancellationToken cancellationToken);
    Task OnExecuted(FlowContext flowContext, FlowStep flowStep, StepStatus step, StepOnceStatus stepOnceStatus, Exception? exception, CancellationToken cancellationToken);
}
public interface IEventMiddleware
{
    Task OnExecuting(FlowContext flowContext, string eventName, string? eventData, CancellationToken cancellationToken);
}

public interface ILogMiddleware
{
    Task OnLog(FlowContext flowContext, FlowStep flowStep, StepStatus step, StepOnceStatus stepOnceStatus, LogInfo logInfo, CancellationToken cancellationToken);
}

待完善内容

  • 对一个类中的方法生成为步骤,可以使用Scope域实现一个流程过程中的状态保持。自动解析输入输出参数
    • 方法生成步骤是需要匹配参数, 将FlowContext等加进去.
    • 从代码备注中获取更多信息
    • 对接口生成的步骤添加可选实例的参数
  • 实现流程内的分组功能
  • 子流程的日志问题
  • 对日志进行分类显示与保存
  • 优化流程编辑方式
  • 优化代码编辑流程的API(需要设置项过多,延后)
  • 完善文档
  • 测试
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

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
0.1.0-preview3 60 5/9/2024
0.1.0-preview2 61 5/7/2024
0.1.0-preview1 64 5/6/2024