当前位置: 首页 > news >正文

使用.net 构建 Elsa Workflow

对接过蓝凌OA 也基于泛微OA数据库原型重新研发上线过产品,自研的开源的也上线过 每个公司对OA流程引擎介绍 都不一样的, 比如Elsa 这款微软MVP开源组件,基于跨平台开发的技术含量高,专门做OA的同行推过对应文章。 直接看怎么用吧。

开发环境 net6

一章 简单使用

官方文档

using Elsa.Extensions;
using Elsa.Workflows.Core.Activities;
using Elsa.Workflows.Core.Contracts;
using Microsoft.Extensions.DependencyInjection;namespace ConsoleApp1demo
{internal class Program{static async Task Main(string[] args){{//ServiceCollection services = new ServiceCollection();nuget: Elsa//services.AddElsa();// 注册Elsa服务到容器定义一个工作流程,就只有一个工作环节 //ServiceProvider serviceprovider = services.BuildServiceProvider();//WriteLine workflow = new WriteLine("Hello, World!");//IWorkflowRunner workflowRunner = serviceprovider.GetRequiredService<IWorkflowRunner>();//await workflowRunner.RunAsync(workflow);    //Console.WriteLine("Hello, World!");}{ServiceCollection services = new ServiceCollection();//nuget: Elsaservices.AddElsa();// 注册Elsa服务到容器定义一个工作流程,就只有一个工作环节 ServiceProvider serviceprovider = services.BuildServiceProvider();var workflow = new Sequence(){Activities = {new WriteLine("Hello world"),new WriteLine("Goodbye 66666")}};IWorkflowRunner workflowRunner = serviceprovider.GetRequiredService<IWorkflowRunner>();await workflowRunner.RunAsync(workflow);}}}
}

二章 改成API 使用的预发行版本 即还没有成为正式发布的版本!!!QAQ

官方文档

不兼容swagger? 先注释

改造成支持httpjson

using Elsa.Http;
using Elsa.Workflows.Core.Activities;
using Elsa.Workflows.Core.Contracts;
using Microsoft.AspNetCore.Mvc;namespace Zhaoxi.Elsa.Server_Project.Controllers
{[ApiController][Route("[controller]")]public class RunWorkflowController : ControllerBase{//工作流执行着private readonly IWorkflowRunner _workflowRunner;public RunWorkflowController(IWorkflowRunner workflowRunner){_workflowRunner = workflowRunner;}[HttpGet]public async Task Post(){await _workflowRunner.RunAsync(new WriteLine("Hello ASP.NET world!")); await _workflowRunner.RunAsync(new WriteHttpResponse(){ Content = new("Hello ASP.NET world!")});}}
}

三章 开始用用核心点的东西了

好多前潜规则 丢

注册  //配置支持某一个端点 

//Elsa 作为一个端点
builder.Services.AddElsa(elsa =>
{elsa.UseWorkflowRuntime(runtime =>{//配置支持某一个端点 runtime.AddWorkflow<CustomWorkflow>();});elsa.UseHttp();
});

跟swagger  AddControllers 冲突 需要注释掉

使用

app.UseWorkflows();

命名 类似于控制的后缀 workflows 微软风格

http://localhost:5191/workflows/hello-word

第四章 Exposing the REST API

  <PackageReference Include="Elsa" Version="3.0.0-preview.727" /><PackageReference Include="Elsa.Http" Version="3.0.0-preview.727" /><PackageReference Include="Elsa.Workflows.Api" Version="3.0.0-preview.727" /><PackageReference Include="Elsa.Identity" Version="3.0.0-preview.727" />

授权 使用

访问

然后就潜规则 官网居然 直接就 下一页 不告诉怎么搞了 哈哈哈哈

---分割线------------------------

//----------------------------------------------------------------------------//curl--location GET 'http://localhost:5031/elsa/api/workflow-definitions'//--header 'Authorization: ApiKey 00000000-0000-0000-0000-000000000000'     访问不到  token不对//----------------------------------------------------------------------------//要请求访问令牌,我们可以向端点发送以下请求/identity/login://curl--location--request POST 'http://localhost:5031/elsa/api/identity/login' //--header 'Content-Type: application/json' //--data - raw '{//    "username": "admin",//    "password": "password"//}'//----------------------------------------------------------------------------//要使用访问令牌向 API 端点发出经过身份验证的请求,我们可以包含访问令牌,如下所示:// curl--location GET 'http://localhost:5031/elsa/api/workflow-definitions'// --header 'Authorization: Bearer {access_token}'

 http://localhost:5032/elsa/api/workflow-definitions

访问不到  token不对
 

  //--header 'Authorization: ApiKey 00000000-0000-0000-0000-000000000000'   

能访问了是通的

开始拿token

  //----------------------------------------------------------------------------
  //要请求访问令牌,我们可以向端点发送以下请求/identity/login:
  //curl--location--request POST 'http://localhost:5031/elsa/api/identity/login' 
  //--header 'Content-Type: application/json' 
  //--data - raw '{
  //    "username": "admin",
  //    "password": "password"
  //}'

默认账号密码就是这

鉴权 颁发token

改成别的就没有数据 鉴权可用

原来的还能用

随便改个值

凭证不对访问 问不了

已知的是1用这个就能拿到token了还要其他干啥

2如何活动的接口也带上token

先用到这里吧

http://www.lryc.cn/news/227446.html

相关文章:

  • open clip论文阅读摘要
  • Vue3像Vue2一样在prototype(原型)上挂载数据
  • API接口自动化测试
  • 基于springboot实现驾校管理系统项目【项目源码】
  • 稀疏数组的保存优化(java版本)
  • Git GUI、SSH协议和IDEA中的Git使用详解
  • Linux下C++调用python脚本实现LDAP协议通过TNLM认证连接到AD服务器
  • 计算机毕业设计选题推荐-校园交流平台微信小程序/安卓APP-项目实战
  • FlinK之检查点与保存点机制
  • UE5 新特性 Nanite 开启
  • 仿写知乎日报第四周
  • MySQL join原理及优化
  • js案例:打地鼠游戏(打灰太狼)
  • 删除杀软回调 bypass EDR 研究
  • Ansible自动化部署工具-组件及语法介绍
  • postgresql实现job的六种方法
  • layui 表格(table)合计 取整数
  • 深入理解 TCP;场景复现,掌握鲜为人知的细节
  • 【MySQL系列】 第二章 · SQL(中)
  • IBM Qiskit量子机器学习速成(一)
  • 音视频基础知识
  • ida81输入密码验证算法分析以及破解思路
  • C语言——贪吃蛇
  • Android sqlite 使用简介
  • UE地形系统材质混合实现和Shader生成分析(UE5 5.2)
  • Git分支与Git标签的介绍及其场景应用
  • Three.js——基于原生WebGL封装运行的三维引擎
  • 第八章认识Express框架
  • 【K8s集群离线安装-kubeadm】
  • python工具CISCO ASA设备任意文件读取