1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Elsa Workflows工作流引擎项目构建

Elsa Workflows工作流引擎项目构建

时间:2024-03-11 05:29:58

相关推荐

Elsa Workflows工作流引擎项目构建

.NET Elsa工作流框架的搭建

1、新建项目 (Elsa Server)2、新建项目 (Elsa Dashboard)

注:本文主要采用.NET 6和Elsa工作引擎进行编写

附.NET 6下载链接:/zh-cn/download/visual-studio-sdks?cid=getdotnetsdk

Elsa官方地址:https://elsa-workflows.github.io/elsa-core/

1、新建项目 (Elsa Server)

选择Core 空,将项目命名为 ElsaServer,去掉配置HTTPS(H)选项,目标框架选择.NET 6.0

2.添加以下程序包

dotnet add package Elsadotnet add package Elsa.Activities.Httpdotnet add package Elsa.Activities.Temporal.Quartzdotnet add package Elsa.Persistence.EntityFramework.Sqlitedotnet add package Elsa.Server.Api

3.在Program.cs中 添加以下代码

using Elsa.Persistence.EntityFramework.Core.Extensions;using Elsa.Persistence.EntityFramework.Sqlite;var builder = WebApplication.CreateBuilder(args);var elsaSection = builder.Configuration.GetSection("Elsa");// Elsa services.builder.Services.AddElsa(elsa => elsa.UseEntityFrameworkPersistence(ef => ef.UseSqlite()).AddConsoleActivities().AddHttpActivities(elsaSection.GetSection("Server").Bind).AddJavaScriptActivities());// Elsa API endpoints.builder.Services.AddElsaApiEndpoints();// Allow arbitrary client browser apps to access the API.// In a production environment, make sure to allow only origins you trust.builder.Services.AddCors(cors => cors.AddDefaultPolicy(policy => policy.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin().WithExposedHeaders("Content-Disposition")));var app = builder.Build();app.UseCors().UseHttpActivities().UseRouting().UseEndpoints(endpoints =>{// Elsa API Endpoints are implemented as regular Core API controllers.endpoints.MapControllers();}).UseWelcomePage();app.Run();

4、运行ElsaServer项目,如图所示

2、新建项目 (Elsa Dashboard)

1.如新建项目 (Elsa Server)所示,选择Core 空,将项目命名为 ElsaDashboard,去掉配置HTTPS(H)选项,目标框架选择.NET 6.0

2.添加以下程序包

dotnet add package ponents.Web

3、添加看板页面

新增一个空的Pages文件夹,添加_ViewImports.cshtml_Host.cshtml两个Rozar页面

_ViewImports.cshtml 添加以下内容

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

_Host.cshtml 添加以下内容

其中server-urlElsaServer项目的运行后的Url地址

@page "/"<!DOCTYPE html><html lang="en"><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Elsa Workflows</title><link rel="icon" type="image/png" sizes="32x32" href="/_content/ponents.Web/elsa-workflows-studio/assets/images/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/_content/ponents.Web/elsa-workflows-studio/assets/images/favicon-16x16.png"><link rel="stylesheet" href="/_content/ponents.Web/elsa-workflows-studio/assets/fonts/inter/inter.css"><link rel="stylesheet" href="/_content/ponents.Web/elsa-workflows-studio/elsa-workflows-studio.css"><script src="/_content/ponents.Web/monaco-editor/min/vs/loader.js"></script><script type="module" src="/_content/ponents.Web/elsa-workflows-studio/elsa-workflows-studio.esm.js"></script></head><body><elsa-studio-root server-url="http://localhost:5254/" monaco-lib-path="_content/ponents.Web/monaco-editor/min"><elsa-studio-dashboard></elsa-studio-dashboard></elsa-studio-root></body></html>

4、在Program.cs中 添加以下代码

var builder = WebApplication.CreateBuilder(args);// Add services to the container.builder.Services.AddRazorPages();var app = builder.Build();app.UseStaticFiles();app.UseRouting();app.UseEndpoints(endpoints => {endpoints.MapFallbackToPage("/_Host"); });app.Run();

5、设置多个启动项目

最终运行结果,如图所示

恭喜你已经学会了如何搭建Elsa工作流,后续文章的更新多多支持!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。