2020-07-14 13:24:07 +00:00
|
|
|
using System;
|
2020-12-26 11:21:08 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Elsa.Builders;
|
2020-01-15 20:26:44 +00:00
|
|
|
using Elsa.Caching;
|
2021-03-30 08:46:50 +00:00
|
|
|
using Elsa.Dispatch;
|
2020-12-26 11:21:08 +00:00
|
|
|
using Elsa.Models;
|
2020-12-12 13:07:17 +00:00
|
|
|
using Elsa.Persistence;
|
|
|
|
|
using Elsa.Persistence.InMemory;
|
2020-10-17 18:19:44 +00:00
|
|
|
using Elsa.Serialization;
|
2020-11-20 22:24:48 +00:00
|
|
|
using Elsa.Services;
|
2020-01-15 20:26:44 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-10-17 18:19:44 +00:00
|
|
|
using Newtonsoft.Json;
|
2021-03-31 12:18:37 +00:00
|
|
|
using NodaTime;
|
2020-01-15 20:26:44 +00:00
|
|
|
using Rebus.Persistence.InMem;
|
|
|
|
|
using Rebus.Transport.InMem;
|
2020-10-23 12:20:52 +00:00
|
|
|
using Storage.Net;
|
|
|
|
|
using Storage.Net.Blobs;
|
2020-01-15 20:26:44 +00:00
|
|
|
|
|
|
|
|
namespace Elsa
|
|
|
|
|
{
|
2020-12-26 11:21:08 +00:00
|
|
|
public class ElsaOptions
|
2020-01-15 20:26:44 +00:00
|
|
|
{
|
2021-04-07 10:45:34 +00:00
|
|
|
internal ElsaOptions()
|
2020-01-15 20:26:44 +00:00
|
|
|
{
|
2020-12-14 16:15:39 +00:00
|
|
|
WorkflowDefinitionStoreFactory = sp => ActivatorUtilities.CreateInstance<InMemoryWorkflowDefinitionStore>(sp);
|
|
|
|
|
WorkflowInstanceStoreFactory = sp => ActivatorUtilities.CreateInstance<InMemoryWorkflowInstanceStore>(sp);
|
2020-12-21 16:08:32 +00:00
|
|
|
WorkflowExecutionLogStoreFactory = sp => ActivatorUtilities.CreateInstance<InMemoryWorkflowExecutionLogStore>(sp);
|
2021-01-29 15:16:45 +00:00
|
|
|
WorkflowTriggerStoreFactory = sp => ActivatorUtilities.CreateInstance<InMemoryBookmarkStore>(sp);
|
2021-03-30 08:46:50 +00:00
|
|
|
WorkflowDefinitionDispatcherFactory = sp => ActivatorUtilities.CreateInstance<QueuingWorkflowDispatcher>(sp);
|
|
|
|
|
WorkflowInstanceDispatcherFactory = sp => ActivatorUtilities.CreateInstance<QueuingWorkflowDispatcher>(sp);
|
|
|
|
|
CorrelatingWorkflowDispatcherFactory = sp => ActivatorUtilities.CreateInstance<QueuingWorkflowDispatcher>(sp);
|
2020-10-23 12:20:52 +00:00
|
|
|
StorageFactory = sp => Storage.Net.StorageFactory.Blobs.InMemory();
|
2020-01-15 20:26:44 +00:00
|
|
|
SignalFactory = sp => new Signal();
|
2020-11-20 22:24:48 +00:00
|
|
|
JsonSerializerConfigurer = (sp, serializer) => { };
|
2021-04-07 10:45:34 +00:00
|
|
|
DistributedLockingOptions = new DistributedLockingOptions();
|
2020-11-20 22:24:48 +00:00
|
|
|
ConfigureServiceBusEndpoint = ConfigureInMemoryServiceBusEndpoint;
|
|
|
|
|
|
2020-10-17 18:19:44 +00:00
|
|
|
CreateJsonSerializer = sp =>
|
|
|
|
|
{
|
2020-10-20 21:17:08 +00:00
|
|
|
var serializer = DefaultContentSerializer.CreateDefaultJsonSerializer();
|
2020-10-17 18:19:44 +00:00
|
|
|
JsonSerializerConfigurer(sp, serializer);
|
|
|
|
|
return serializer;
|
|
|
|
|
};
|
2020-01-15 20:26:44 +00:00
|
|
|
}
|
2021-04-07 10:45:34 +00:00
|
|
|
|
2020-12-26 11:21:08 +00:00
|
|
|
public ServiceFactory<IActivity> ActivityFactory { get; } = new();
|
|
|
|
|
public ServiceFactory<IWorkflow> WorkflowFactory { get; } = new();
|
2021-04-07 11:10:31 +00:00
|
|
|
public IEnumerable<Type> ActivityTypes => ActivityFactory.Types;
|
2021-04-07 10:45:34 +00:00
|
|
|
|
|
|
|
|
public IList<Type> WorkflowTypes { get; } = new List<Type>();
|
|
|
|
|
public IList<Type> MessageTypes { get; } = new List<Type>();
|
2021-01-08 10:14:00 +00:00
|
|
|
public ServiceBusOptions ServiceBusOptions { get; } = new();
|
2021-04-07 10:45:34 +00:00
|
|
|
public DistributedLockingOptions DistributedLockingOptions { get; }
|
2021-01-08 10:14:00 +00:00
|
|
|
|
2021-03-31 12:18:37 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// The amount of time to wait before giving up on trying to acquire a lock.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Duration DistributedLockTimeout { get; set; } = Duration.FromHours(1);
|
|
|
|
|
|
2020-10-23 12:20:52 +00:00
|
|
|
internal Func<IServiceProvider, IBlobStorage> StorageFactory { get; set; }
|
2020-12-12 13:07:17 +00:00
|
|
|
internal Func<IServiceProvider, IWorkflowDefinitionStore> WorkflowDefinitionStoreFactory { get; set; }
|
|
|
|
|
internal Func<IServiceProvider, IWorkflowInstanceStore> WorkflowInstanceStoreFactory { get; set; }
|
2020-12-21 16:08:32 +00:00
|
|
|
internal Func<IServiceProvider, IWorkflowExecutionLogStore> WorkflowExecutionLogStoreFactory { get; set; }
|
2021-01-29 15:16:45 +00:00
|
|
|
internal Func<IServiceProvider, IBookmarkStore> WorkflowTriggerStoreFactory { get; set; }
|
2021-04-07 10:45:34 +00:00
|
|
|
internal Func<IServiceProvider, ISignal> SignalFactory { get; set; }
|
|
|
|
|
internal Func<IServiceProvider, JsonSerializer> CreateJsonSerializer { get; set; }
|
|
|
|
|
internal Action<IServiceProvider, JsonSerializer> JsonSerializerConfigurer { get; set; }
|
2021-03-30 08:46:50 +00:00
|
|
|
internal Func<IServiceProvider, IWorkflowDefinitionDispatcher> WorkflowDefinitionDispatcherFactory { get; set; }
|
|
|
|
|
internal Func<IServiceProvider, IWorkflowInstanceDispatcher> WorkflowInstanceDispatcherFactory { get; set; }
|
2021-03-31 12:18:37 +00:00
|
|
|
internal Func<IServiceProvider, IWorkflowDispatcher> CorrelatingWorkflowDispatcherFactory { get; set; }
|
2021-04-07 10:45:34 +00:00
|
|
|
internal Action<ServiceBusEndpointConfigurationContext> ConfigureServiceBusEndpoint { get; set; }
|
2021-01-01 16:58:08 +00:00
|
|
|
|
2021-04-07 10:45:34 +00:00
|
|
|
private static void ConfigureInMemoryServiceBusEndpoint(ServiceBusEndpointConfigurationContext context)
|
2020-11-20 22:24:48 +00:00
|
|
|
{
|
|
|
|
|
var serviceProvider = context.ServiceProvider;
|
|
|
|
|
var transport = serviceProvider.GetService<InMemNetwork>();
|
|
|
|
|
var store = serviceProvider.GetRequiredService<InMemorySubscriberStore>();
|
|
|
|
|
var queueName = context.QueueName;
|
|
|
|
|
|
|
|
|
|
context.Configurer
|
|
|
|
|
.Subscriptions(s => s.StoreInMemory(store))
|
2021-01-30 19:39:08 +00:00
|
|
|
.Transport(t => t.UseInMemoryTransport(transport, queueName));
|
2020-01-15 20:26:44 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|