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