美文网首页
创建Elsa Workflow Dashboard 和服务项目

创建Elsa Workflow Dashboard 和服务项目

作者: 寻找无名的特质 | 来源:发表于2022-04-12 05:46 被阅读0次

    首先创建一个空的Web 项目:dotnet new web -n "ElsaQuickstarts.Server.DashboardAndServer"
    进入这个项目目录,安装程序包:
    dotnet add package Elsa
    dotnet add package Elsa.Activities.Http
    dotnet add package Elsa.Activities.Temporal.Quartz
    dotnet add package Elsa.Persistence.EntityFramework.Sqlite
    dotnet add package Elsa.Server.Api
    dotnet add package Elsa.Designer.Components.Web

    打开program.cs文件,修改代码如下:

    using Elsa;
    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)
            .AddQuartzTemporalActivities()
            .AddWorkflowsFrom<Startup>()
        );
    
    // Elsa API endpoints.
    builder.Services.AddElsaApiEndpoints();
    
    // For Dashboard.
    builder.Services.AddRazorPages();
    
    var app = builder.Build();
    
    if (builder.Environment.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }
    
    app
        .UseStaticFiles() // For Dashboard.
        .UseHttpActivities()
        .UseRouting()
        .UseEndpoints(endpoints =>
        {
                        // Elsa API Endpoints are implemented as regular ASP.NET Core API controllers.
                        endpoints.MapControllers();
    
                        // For Dashboard.
                        endpoints.MapFallbackToPage("/_Host");
        });
    
    app.Run();
    

    修改appsettings.json文件:
    {
    "Elsa": {
    "Server": {
    "BaseUrl": "https://localhost:5001"
    }
    }
    }
    创建Pages目录,增加_Host.cshtml文件,修改页面代码如下:

    @page "/"
    @{
        var serverUrl = $"{Request.Scheme}://{Request.Host}";
    }
    <!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/Elsa.Designer.Components.Web/elsa-workflows-studio/assets/images/favicon-32x32.png">
        <link rel="icon" type="image/png" sizes="16x16" href="/_content/Elsa.Designer.Components.Web/elsa-workflows-studio/assets/images/favicon-16x16.png">
        <link rel="stylesheet" href="/_content/Elsa.Designer.Components.Web/elsa-workflows-studio/assets/fonts/inter/inter.css">
        <link rel="stylesheet" href="/_content/Elsa.Designer.Components.Web/elsa-workflows-studio/elsa-workflows-studio.css">
        <script src="/_content/Elsa.Designer.Components.Web/monaco-editor/min/vs/loader.js"></script>
        <script type="module" src="/_content/Elsa.Designer.Components.Web/elsa-workflows-studio/elsa-workflows-studio.esm.js"></script>
    </head>
    <body>
    <elsa-studio-root server-url="@serverUrl" monaco-lib-path="_content/Elsa.Designer.Components.Web/monaco-editor/min">
        <elsa-studio-dashboard></elsa-studio-dashboard>
    </elsa-studio-root>
    </body>
    </html>
    

    运行项目,可以创建编辑流程了。

    相关文章

      网友评论

          本文标题:创建Elsa Workflow Dashboard 和服务项目

          本文链接:https://www.haomeiwen.com/subject/ykqysrtx.html