| | | 1 | | using System.Reflection; |
| | | 2 | | using CShells.Features; |
| | | 3 | | using Elsa.WorkflowProviders.BlobStorage.Contracts; |
| | | 4 | | using Elsa.WorkflowProviders.BlobStorage.Handlers; |
| | | 5 | | using Elsa.WorkflowProviders.BlobStorage.Providers; |
| | | 6 | | using Elsa.Workflows.Runtime; |
| | | 7 | | using FluentStorage; |
| | | 8 | | using FluentStorage.Blobs; |
| | | 9 | | using JetBrains.Annotations; |
| | | 10 | | using Microsoft.Extensions.DependencyInjection; |
| | | 11 | | |
| | | 12 | | namespace Elsa.WorkflowProviders.BlobStorage.ShellFeatures; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// A feature that enables the FluentStorage workflow definition provider. |
| | | 16 | | /// </summary> |
| | | 17 | | [ShellFeature( |
| | | 18 | | DisplayName = "Blob Storage Workflow Provider", |
| | | 19 | | Description = "Provides workflow definitions from blob storage", |
| | | 20 | | DependsOn = ["WorkflowManagement"])] |
| | | 21 | | [UsedImplicitly] |
| | | 22 | | public class BlobStorageFeature : IShellFeature |
| | | 23 | | { |
| | | 24 | | /// <summary> |
| | | 25 | | /// The blob storage to use. |
| | | 26 | | /// </summary> |
| | 0 | 27 | | public Func<IServiceProvider, IBlobStorage> BlobStorage { get; set; } = _ => StorageFactory.Blobs.DirectoryFiles(Get |
| | | 28 | | |
| | | 29 | | public void ConfigureServices(IServiceCollection services) |
| | | 30 | | { |
| | 0 | 31 | | services.AddScoped<IBlobStorageProvider>(sp => new BlobStorageProvider(BlobStorage(sp))); |
| | | 32 | | |
| | | 33 | | // Register the JSON format handler (built-in support) |
| | 0 | 34 | | services.AddScoped<IBlobWorkflowFormatHandler, JsonBlobWorkflowFormatHandler>(); |
| | | 35 | | |
| | 0 | 36 | | services.AddScoped<BlobStorageWorkflowsProvider>(); |
| | 0 | 37 | | services.AddScoped<IWorkflowsProvider>(sp => sp.GetRequiredService<BlobStorageWorkflowsProvider>()); |
| | 0 | 38 | | } |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Gets the default workflows directory. |
| | | 42 | | /// </summary> |
| | | 43 | | public static string GetDefaultWorkflowsDirectory() |
| | | 44 | | { |
| | 0 | 45 | | var entryAssembly = Assembly.GetEntryAssembly(); |
| | 0 | 46 | | var entryAssemblyDir = entryAssembly != null |
| | 0 | 47 | | ? Path.GetDirectoryName(entryAssembly.Location) |
| | 0 | 48 | | : AppContext.BaseDirectory; |
| | 0 | 49 | | var directory = Path.Combine(entryAssemblyDir!, "Workflows"); |
| | 0 | 50 | | return directory; |
| | | 51 | | } |
| | | 52 | | } |
| | | 53 | | |