2023-10-15 11:58:44 +00:00
|
|
|
using System.Text.Json;
|
2023-06-28 20:44:51 +00:00
|
|
|
using Elsa.Features.Abstractions;
|
|
|
|
|
using Elsa.Features.Services;
|
2023-07-14 17:19:41 +00:00
|
|
|
using Elsa.MongoDb.Options;
|
2023-06-28 20:44:51 +00:00
|
|
|
using Elsa.MongoDb.Serializers;
|
Add a more generic UIHandler to customize how inputAttributes can be handle by UI (#4688)
* add a more generic UIHandler to customize how inputAttributes can be handle by the ui
* Add IPropertyUIHandlerResolver and update PropertyUIHandlerResolver
Introduced a new interface, IPropertyUIHandlerResolver, to resolve UI options for a property. Refactored PropertyUIHandlerResolver to implement this interface and removed the unnecessary partial class structure. Also, cleaned up some unnecessary usings in various files for better code organization.
* Refactor variable name and description in InputDescriptor
The 'uISpecifications' variable in the InputDescriptor model is renamed to 'uiSpecifications' for better readability. Additionally, the associated comment was revised to explain that the dictionary is used by the UI.
* "Refactor codebase for improved organization and cleaner architecture"
The codebase has been significantly refactored, moving several classes to more appropriate namespaces for improved organization and cleaner architecture. This includes shifting UI hint handlers, activities, and memory-related components, amongst others. The changes should improve code readability and maintainability, but as this is a broad refactoring effort, thorough regression testing is advised.
* Add CheckList UIHint with associated handler and provider
This update introduces a new UIHint called CheckList to the Elsa.Workflows.Core. This includes the necessary handler and provider classes. The handler is registered in the WorkflowsFeature.cs, and the CheckList UIHint key has been added to the InputUIHints.cs. Various associated files have been created in both the Elsa.Api.Client and Elsa.Workflows.Core project to support this new UIHint.
---------
Co-authored-by: Jérémie DEVILLARD <jdevillard@users.noreply.github.com>
Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
2023-12-26 17:56:29 +00:00
|
|
|
using Elsa.Workflows.Memory;
|
2023-08-06 15:03:36 +00:00
|
|
|
using Elsa.Workflows.Runtime.Entities;
|
2023-06-28 20:44:51 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
2023-08-06 15:03:36 +00:00
|
|
|
using MongoDB.Bson;
|
2023-06-28 20:44:51 +00:00
|
|
|
using MongoDB.Bson.Serialization;
|
2023-07-06 13:48:28 +00:00
|
|
|
using MongoDB.Bson.Serialization.Serializers;
|
2023-06-28 20:44:51 +00:00
|
|
|
using MongoDB.Driver;
|
|
|
|
|
using MongoDB.Driver.Core.Extensions.DiagnosticSources;
|
|
|
|
|
|
|
|
|
|
namespace Elsa.MongoDb.Features;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Configures MongoDb.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class MongoDbFeature : FeatureBase
|
|
|
|
|
{
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public MongoDbFeature(IModule module) : base(module)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The MongoDB connection string.
|
|
|
|
|
/// </summary>
|
2023-06-28 20:46:30 +00:00
|
|
|
public string ConnectionString { get; set; } = default!;
|
2023-08-06 15:03:36 +00:00
|
|
|
|
2023-06-28 20:44:51 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// A delegate that configures MongoDb.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Action<MongoDbOptions> Options { get; set; } = _ => { };
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override void Apply()
|
|
|
|
|
{
|
|
|
|
|
Services.Configure(Options);
|
2023-08-06 15:03:36 +00:00
|
|
|
|
2023-06-28 20:44:51 +00:00
|
|
|
Services.AddSingleton(sp => CreateDatabase(sp, ConnectionString));
|
2023-08-06 15:03:36 +00:00
|
|
|
|
2023-06-28 20:44:51 +00:00
|
|
|
RegisterSerializers();
|
2023-08-06 15:03:36 +00:00
|
|
|
RegisterClassMaps();
|
2023-06-28 20:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
2023-08-06 15:03:36 +00:00
|
|
|
private static void RegisterSerializers()
|
2023-06-28 20:44:51 +00:00
|
|
|
{
|
|
|
|
|
BsonSerializer.RegisterSerializer(typeof(object), new PolymorphicSerializer());
|
|
|
|
|
BsonSerializer.RegisterSerializer(typeof(Type), new TypeSerializer());
|
|
|
|
|
BsonSerializer.RegisterSerializer(typeof(Variable), new VariableSerializer());
|
2023-07-06 13:48:28 +00:00
|
|
|
BsonSerializer.RegisterSerializer(typeof(Version), new VersionSerializer());
|
2023-10-15 11:58:44 +00:00
|
|
|
BsonSerializer.RegisterSerializer(typeof(JsonElement), new JsonElementSerializer());
|
2023-06-28 20:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
2023-08-06 15:03:36 +00:00
|
|
|
private static void RegisterClassMaps()
|
|
|
|
|
{
|
|
|
|
|
BsonClassMap.RegisterClassMap<StoredBookmark>(cm =>
|
|
|
|
|
{
|
|
|
|
|
cm.AutoMap(); // Automatically map other properties
|
|
|
|
|
cm
|
|
|
|
|
.MapIdProperty(b => b.BookmarkId)
|
|
|
|
|
.SetSerializer(new StringSerializer(BsonType.String));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-28 20:44:51 +00:00
|
|
|
private static IMongoDatabase CreateDatabase(IServiceProvider sp, string connectionString)
|
|
|
|
|
{
|
|
|
|
|
var options = sp.GetRequiredService<IOptions<MongoDbOptions>>().Value;
|
2023-08-06 15:03:36 +00:00
|
|
|
|
2023-06-28 20:44:51 +00:00
|
|
|
var mongoUrl = new MongoUrl(connectionString);
|
|
|
|
|
var settings = MongoClientSettings.FromUrl(mongoUrl);
|
2023-08-06 15:03:36 +00:00
|
|
|
|
2023-06-28 20:44:51 +00:00
|
|
|
settings.ClusterConfigurator = cb => cb.Subscribe(new DiagnosticsActivityEventSubscriber());
|
|
|
|
|
settings.ApplicationName = GetApplicationName(settings);
|
|
|
|
|
settings.WriteConcern = options.WriteConcern;
|
|
|
|
|
settings.ReadConcern = options.ReadConcern;
|
|
|
|
|
settings.ReadPreference = options.ReadPreference;
|
|
|
|
|
settings.RetryReads = options.RetryReads;
|
|
|
|
|
settings.RetryWrites = options.RetryWrites;
|
|
|
|
|
settings.SslSettings = options.SslSettings;
|
|
|
|
|
|
|
|
|
|
var mongoClient = new MongoClient(settings);
|
|
|
|
|
return mongoClient.GetDatabase(mongoUrl.DatabaseName);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-06 15:03:36 +00:00
|
|
|
private static string GetApplicationName(MongoClientSettings settings) =>
|
2023-06-28 20:44:51 +00:00
|
|
|
string.IsNullOrWhiteSpace(settings.ApplicationName) ? "elsa_workflows" : settings.ApplicationName;
|
|
|
|
|
}
|