Skip to content

Commit 5eb93eb

Browse files
authored
Merge pull request #279 from aspnetzero/issues-#5073
Documentation updated to be compatible with Elsa's latest version.
2 parents 79cd799 + abc7b29 commit 5eb93eb

File tree

1 file changed

+78
-5
lines changed

1 file changed

+78
-5
lines changed

blog-posts/en/integrating-elsa-with-asp.net-zero.md

+78-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
[Elsa](https://elsa-workflows.github.io/elsa-core/) is a great open source .NET Standard workflows library. Elsa allows creation of workflows by code, by JSON definition or by its workflow designer UI. In this document, we will basically integrate Elsa with ASP.NET Zero and create a simple workflow following official [Elsa Dashboard + Server](https://elsa-workflows.github.io/elsa-core/docs/next/quickstarts/quickstarts-aspnetcore-server-dashboard-and-api-endpoints) document.
44

5-
Fully integrated Elsa sample project can be found on [GitHub](https://github.com/aspnetzero/aspnet-zero-samples/tree/master/ElsaDemo).
5+
Fully integrated Elsa sample project can be found on [GitHub](https://github.com/aspnetzero/aspnet-zero-samples/tree/master/ElsaMvcDemo).
66

77
## Create Project
88

9-
In order to start integrating Elsa with ASP.NET Zero, first follow ASP.NET Zero's [Getting Started](Getting-Started-Core.md) document and create a new project.
9+
In order to start integrating Elsa with ASP.NET Zero, first follow ASP.NET Zero's [Getting Started](https://docs.aspnetzero.com/en/aspnet-core-mvc/latest/Getting-Started-Core) document and create a new project.
1010

1111
## Adding Elsa Packages
1212

@@ -100,7 +100,7 @@ elsa.UseAutoMapper(() => { });
100100

101101
Both Elsa and ASP.NET Boilerplate creates a `MapperConfiguration` and uses it to create an `IMapper`. Because of this, if we don't add this line to Elsa configuration, the app will only use Elsa's **AutoMapper** configuration. But, after making this configuration, we need to configure Elsa's AutoMapper mappings in our app manually. In order to do this, go to `*WebMvcModule` and add below lines to its `PreInitialize` method.
102102

103-
```
103+
```c#
104104
// ELSA AutoMapper
105105
Configuration.Modules.AbpAutoMapper().Configurators.Add(config =>
106106
{
@@ -116,12 +116,13 @@ Configuration.Modules.AbpAutoMapper().Configurators.Add(config =>
116116
// CloningProfile
117117
config.CreateMap<WorkflowDefinition, WorkflowDefinition>();
118118
config.CreateMap<WorkflowInstance, WorkflowInstance>();
119+
config.CreateMap<WorkflowDefinition, WorkflowDefinitionVersionModel>();
119120
});
120121
```
121122

122123
#### API Versioning
123124

124-
```
125+
```c#
125126
services.AddElsaApiEndpoints();
126127
services.Configure<ApiVersioningOptions>(options =>
127128
{
@@ -343,11 +344,80 @@ In order to add Elsa Dashboard into ASP.NET Zero, create a folder named `Pages`
343344
<script type="module" src="/_content/Elsa.Designer.Components.Web/elsa-workflows-studio/elsa-workflows-studio.esm.js"></script>
344345
</head>
345346
<body class="h-screen" style="background-size: 30px 30px; background-image: url(/_content/Elsa.Designer.Components.Web/elsa-workflows-studio/assets/images/tile.png); background-color: #FBFBFB;">
346-
<elsa-studio-root server-url="@serverUrl" monaco-lib-path="_content/Elsa.Designer.Components.Web/monaco-editor/min"></elsa-studio-root>
347+
<elsa-studio-root server-url="@serverUrl" monaco-lib-path="_content/Elsa.Designer.Components.Web/monaco-editor/min">
348+
<elsa-studio-dashboard></elsa-studio-dashboard>
349+
</elsa-studio-root>
347350
</body>
348351
</html>
349352
```
350353

354+
This helper class, named `CurrentDirectoryHelpers`, is crucial for resolving issues related to embedded static files, specifically when using ASP.NET Zero with Elsa's dashboard styles and scripts.
355+
356+
357+
```c#
358+
public class CurrentDirectoryHelpers
359+
{
360+
internal const string AspNetCoreModuleDll = "aspnetcorev2_inprocess.dll";
361+
362+
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
363+
private static extern IntPtr GetModuleHandle(string lpModuleName);
364+
365+
[System.Runtime.InteropServices.DllImport(AspNetCoreModuleDll)]
366+
private static extern int http_get_application_properties(ref IISConfigurationData iiConfigData);
367+
368+
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
369+
private struct IISConfigurationData
370+
{
371+
public IntPtr pNativeApplication;
372+
373+
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.BStr)]
374+
public string pwzFullApplicationPath;
375+
376+
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.BStr)]
377+
public string pwzVirtualApplicationPath;
378+
379+
public bool fWindowsAuthEnabled;
380+
381+
public bool fBasicAuthEnabled;
382+
383+
public bool fAnonymousAuthEnable;
384+
}
385+
386+
public static void SetCurrentDirectory()
387+
{
388+
try
389+
{
390+
// Check if physical path was provided by ANCM
391+
var sitePhysicalPath = Environment.GetEnvironmentVariable("ASPNETCORE_IIS_PHYSICAL_PATH");
392+
if (string.IsNullOrEmpty(sitePhysicalPath))
393+
{
394+
// Skip if not running ANCM InProcess
395+
if (GetModuleHandle(AspNetCoreModuleDll) == IntPtr.Zero)
396+
{
397+
return;
398+
}
399+
400+
IISConfigurationData configurationData = default(IISConfigurationData);
401+
if (http_get_application_properties(ref configurationData) != 0)
402+
{
403+
return;
404+
}
405+
406+
sitePhysicalPath = configurationData.pwzFullApplicationPath;
407+
}
408+
409+
Environment.CurrentDirectory = sitePhysicalPath;
410+
}
411+
catch
412+
{
413+
// ignore
414+
}
415+
}
416+
}
417+
```
418+
419+
420+
351421
ASP.NET Zero uses `WebHostBuilder` in its Program.cs but it has some problems with embedded static files. Elsa provides styles and scripts of its dashboard as static files. In order to load Elsa's static files, change the `Program.cs` as shown below;
352422

353423
```c#
@@ -375,6 +445,9 @@ public class Program
375445
}
376446
```
377447

448+
449+
450+
378451
## UserManager
379452

380453
During the integration of Elsa, we faced an error of Serialization and Deserialization of `IdentityOptions` in UserManager's `InitializeOptionsAsync` method. To overcome this problem, you should override the related method in `UserManager.cs` as shown below;

0 commit comments

Comments
 (0)