XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEWorkflow

【WinUI】XFE基于windows的工作流

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Text.Json;
using System.Text.Json.Nodes;
using XFEWorkflow.Abstractions;

namespace XFEWorkflow.Plugins.Sample;

public sealed class EchoPlugin : IWorkflowPlugin
{
    public void Register(IPluginRegistry registry)
    {
        var manifest = JsonSerializer.Deserialize<PluginManifest>(File.ReadAllText(Path.Combine(Path.GetDirectoryName(typeof(EchoPlugin).Assembly.Location)!, "plugin.json")), WorkflowJson.Options)!;
        registry.RegisterAction(manifest.Capabilities.Single(), () => new EchoAction());
    }
    private sealed class EchoAction : IWorkflowAction
    {
        public async ValueTask<JsonObject> ExecuteAsync(JsonObject inputs, IWorkflowContext context, CancellationToken cancellationToken)
        {
            var text = inputs.String("text"); await context.LogAsync("示例插件:" + text, cancellationToken);
            // Other plugins are called through context.InvokeAsync("plugin.id.action", ..., cancellationToken).
            return new() { ["text"] = text };
        }
    }
}