From ebf95825152c927607df95c340d4a57580964091 Mon Sep 17 00:00:00 2001
From: cKey <35512826+colinin@users.noreply.github.com>
Date: Fri, 3 Dec 2021 17:49:03 +0800
Subject: [PATCH 1/2] feat(workflow): integrate WorkflowCore to support
workflow
---
...GYUN.Abp.WorkflowCore.Elasticsearch.csproj | 12 +
.../Elasticsearch/AbpElasticsearchIndexer.cs | 140 +++++++
.../AbpWorkflowCoreElasticsearchModule.cs | 24 ++
.../AbpWorkflowCoreElasticsearchOptions.cs | 14 +
.../Models/WorkflowSearchModel.cs | 120 ++++++
...YUN.Abp.WorkflowCore.LifeCycleEvent.csproj | 16 +
.../AbpEventBusLifeCycleEventHub.cs | 51 +++
.../AbpWorkflowCoreLifeCycleEventModule.cs | 24 ++
.../LifeCycleEvent/LifeCycleEventHandler.cs | 45 +++
...ore.Persistence.EntityFrameworkCore.csproj | 16 +
...orePersistenceEntityFrameworkCoreModule.cs | 23 ++
.../EfCoreWorkflowEventRepository.cs | 14 +
...CoreWorkflowEventSubscriptionRepository.cs | 15 +
.../EfCoreWorkflowExecutionErrorRepository.cs | 14 +
.../EfCoreWorkflowRepository.cs | 40 ++
...fCoreWorkflowScheduledCommandRepository.cs | 14 +
.../EntityFrameworkCore/IWorkflowDbContext.cs | 18 +
.../EntityFrameworkCore/WorkflowDbContext.cs | 29 ++
...WorkflowDbContextModelBuilderExtensions.cs | 103 +++++
...INGYUN.Abp.WorkflowCore.Persistence.csproj | 16 +
.../Definitions/WorkflowDefinition.cs | 47 +++
.../WorkflowDefinitionConditionCondition.cs | 30 ++
.../WorkflowDefinitionConditionNode.cs | 37 ++
.../WorkflowDefinitionExtensions.cs | 10 +
.../Definitions/WorkflowDefinitionFormData.cs | 52 +++
.../Definitions/WorkflowDefinitionNode.cs | 47 +++
.../Definitions/WorkflowDefinitionStepBody.cs | 28 ++
.../AbpWorkflowCorePersistenceModule.cs | 9 +
.../AbpWorkflowPersistenceProvider.cs | 354 ++++++++++++++++++
.../Persistence/IWorkflowEventRepository.cs | 9 +
.../IWorkflowEventSubscriptionRepository.cs | 9 +
.../IWorkflowExecutionErrorRepository.cs | 8 +
.../Persistence/IWorkflowRepository.cs | 21 ++
.../IWorkflowScheduledCommandRepository.cs | 8 +
.../Abp/WorkflowCore/Persistence/Workflow.cs | 101 +++++
.../Persistence/WorkflowDbProperties.cs | 9 +
.../WorkflowCore/Persistence/WorkflowEvent.cs | 47 +++
.../Persistence/WorkflowEventSubscription.cs | 73 ++++
.../Persistence/WorkflowExecutionError.cs | 34 ++
.../Persistence/WorkflowExecutionPointer.cs | 162 ++++++++
.../Persistence/WorkflowExtensionAttribute.cs | 31 ++
.../Persistence/WorkflowExtensions.cs | 113 ++++++
.../Persistence/WorkflowScheduledCommand.cs | 29 ++
.../WorkflowCore/Models/WorkflowExtensions.cs | 138 +++++++
.../LINGYUN.Abp.WorkflowCore.RabbitMQ.csproj | 16 +
.../AbpRabbitMQWorkflowCoreOptions.cs | 15 +
.../RabbitMQ/AbpRabbitMqQueueProvider.cs | 135 +++++++
.../RabbitMQ/AbpWorkflowCoreRabbitMQModule.cs | 24 ++
.../RabbitMQ/IQueueNameNormalizer.cs | 9 +
.../RabbitMQ/QueueNameNormalizer.cs | 23 ++
.../RabbitMQ/WorkflowQueueConfiguration.cs | 21 ++
.../LINGYUN.Abp.WorkflowCore.csproj | 14 +
.../AbpWorkflowCoreConventionalRegistrar.cs | 11 +
.../Abp/WorkflowCore/AbpWorkflowCoreModule.cs | 58 +++
.../WorkflowCore/AbpWorkflowCoreOptions.cs | 10 +
.../Abp/WorkflowCore/IWorkflowEnabled.cs | 6 +
.../Abp/WorkflowCore/IWorkflowManager.cs | 10 +
.../LINGYUN/Abp/WorkflowCore/NullStepBody.cs | 14 +
.../LINGYUN/Abp/WorkflowCore/WorkflowBase.cs | 14 +
.../WorkflowConditionCondition.cs | 9 +
.../Abp/WorkflowCore/WorkflowConditionNode.cs | 15 +
.../Abp/WorkflowCore/WorkflowDefinition.cs | 17 +
.../Abp/WorkflowCore/WorkflowFormData.cs | 24 ++
.../Abp/WorkflowCore/WorkflowManager.cs | 105 ++++++
.../LINGYUN/Abp/WorkflowCore/WorkflowNode.cs | 20 +
.../LINGYUN/Abp/WorkflowCore/WorkflowParam.cs | 10 +
.../WorkflowCore/WorkflowParamDictionary.cs | 8 +
.../Abp/WorkflowCore/WorkflowParamInput.cs | 8 +
.../Abp/WorkflowCore/WorkflowStepBody.cs | 17 +
.../System/ObjectSerializerExtensions.cs | 19 +
.../System/UtcDateTimeExtensions.cs | 19 +
.../LINGYUN.Abp.WorkflowCore.Tests.csproj | 17 +
.../WorkflowCore/AbpWorkflowCoreTestBase.cs | 8 +
.../WorkflowCore/AbpWorkflowCoreTestModule.cs | 11 +
74 files changed, 2841 insertions(+)
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Elasticsearch/LINGYUN.Abp.WorkflowCore.Elasticsearch.csproj
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Elasticsearch/LINGYUN/Abp/WorkflowCore/Elasticsearch/AbpElasticsearchIndexer.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Elasticsearch/LINGYUN/Abp/WorkflowCore/Elasticsearch/AbpWorkflowCoreElasticsearchModule.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Elasticsearch/LINGYUN/Abp/WorkflowCore/Elasticsearch/AbpWorkflowCoreElasticsearchOptions.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Elasticsearch/LINGYUN/Abp/WorkflowCore/Elasticsearch/Models/WorkflowSearchModel.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.LifeCycleEvent/LINGYUN.Abp.WorkflowCore.LifeCycleEvent.csproj
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.LifeCycleEvent/LINGYUN/Abp/WorkflowCore/LifeCycleEvent/AbpEventBusLifeCycleEventHub.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.LifeCycleEvent/LINGYUN/Abp/WorkflowCore/LifeCycleEvent/AbpWorkflowCoreLifeCycleEventModule.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.LifeCycleEvent/LINGYUN/Abp/WorkflowCore/LifeCycleEvent/LifeCycleEventHandler.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence.EntityFrameworkCore/LINGYUN.Abp.WorkflowCore.Persistence.EntityFrameworkCore.csproj
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence.EntityFrameworkCore/LINGYUN/Abp/WorkflowCore/Persistence/EntityFrameworkCore/AbpWorkflowCorePersistenceEntityFrameworkCoreModule.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence.EntityFrameworkCore/LINGYUN/Abp/WorkflowCore/Persistence/EntityFrameworkCore/EfCoreWorkflowEventRepository.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence.EntityFrameworkCore/LINGYUN/Abp/WorkflowCore/Persistence/EntityFrameworkCore/EfCoreWorkflowEventSubscriptionRepository.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence.EntityFrameworkCore/LINGYUN/Abp/WorkflowCore/Persistence/EntityFrameworkCore/EfCoreWorkflowExecutionErrorRepository.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence.EntityFrameworkCore/LINGYUN/Abp/WorkflowCore/Persistence/EntityFrameworkCore/EfCoreWorkflowRepository.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence.EntityFrameworkCore/LINGYUN/Abp/WorkflowCore/Persistence/EntityFrameworkCore/EfCoreWorkflowScheduledCommandRepository.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence.EntityFrameworkCore/LINGYUN/Abp/WorkflowCore/Persistence/EntityFrameworkCore/IWorkflowDbContext.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence.EntityFrameworkCore/LINGYUN/Abp/WorkflowCore/Persistence/EntityFrameworkCore/WorkflowDbContext.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence.EntityFrameworkCore/LINGYUN/Abp/WorkflowCore/Persistence/EntityFrameworkCore/WorkflowDbContextModelBuilderExtensions.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN.Abp.WorkflowCore.Persistence.csproj
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Definitions/WorkflowDefinition.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Definitions/WorkflowDefinitionConditionCondition.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Definitions/WorkflowDefinitionConditionNode.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Definitions/WorkflowDefinitionExtensions.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Definitions/WorkflowDefinitionFormData.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Definitions/WorkflowDefinitionNode.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Definitions/WorkflowDefinitionStepBody.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/AbpWorkflowCorePersistenceModule.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/AbpWorkflowPersistenceProvider.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/IWorkflowEventRepository.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/IWorkflowEventSubscriptionRepository.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/IWorkflowExecutionErrorRepository.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/IWorkflowRepository.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/IWorkflowScheduledCommandRepository.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/Workflow.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/WorkflowDbProperties.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/WorkflowEvent.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/WorkflowEventSubscription.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/WorkflowExecutionError.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/WorkflowExecutionPointer.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/WorkflowExtensionAttribute.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/WorkflowExtensions.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/LINGYUN/Abp/WorkflowCore/Persistence/WorkflowScheduledCommand.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Persistence/WorkflowCore/Models/WorkflowExtensions.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.RabbitMQ/LINGYUN.Abp.WorkflowCore.RabbitMQ.csproj
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.RabbitMQ/LINGYUN/Abp/WorkflowCore/RabbitMQ/AbpRabbitMQWorkflowCoreOptions.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.RabbitMQ/LINGYUN/Abp/WorkflowCore/RabbitMQ/AbpRabbitMqQueueProvider.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.RabbitMQ/LINGYUN/Abp/WorkflowCore/RabbitMQ/AbpWorkflowCoreRabbitMQModule.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.RabbitMQ/LINGYUN/Abp/WorkflowCore/RabbitMQ/IQueueNameNormalizer.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.RabbitMQ/LINGYUN/Abp/WorkflowCore/RabbitMQ/QueueNameNormalizer.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.RabbitMQ/LINGYUN/Abp/WorkflowCore/RabbitMQ/WorkflowQueueConfiguration.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore/LINGYUN.Abp.WorkflowCore.csproj
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore/LINGYUN/Abp/WorkflowCore/AbpWorkflowCoreConventionalRegistrar.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore/LINGYUN/Abp/WorkflowCore/AbpWorkflowCoreModule.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore/LINGYUN/Abp/WorkflowCore/AbpWorkflowCoreOptions.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore/LINGYUN/Abp/WorkflowCore/IWorkflowEnabled.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore/LINGYUN/Abp/WorkflowCore/IWorkflowManager.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore/LINGYUN/Abp/WorkflowCore/NullStepBody.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore/LINGYUN/Abp/WorkflowCore/WorkflowBase.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore/LINGYUN/Abp/WorkflowCore/WorkflowConditionCondition.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore/LINGYUN/Abp/WorkflowCore/WorkflowConditionNode.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore/LINGYUN/Abp/WorkflowCore/WorkflowDefinition.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore/LINGYUN/Abp/WorkflowCore/WorkflowFormData.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore/LINGYUN/Abp/WorkflowCore/WorkflowManager.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore/LINGYUN/Abp/WorkflowCore/WorkflowNode.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore/LINGYUN/Abp/WorkflowCore/WorkflowParam.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore/LINGYUN/Abp/WorkflowCore/WorkflowParamDictionary.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore/LINGYUN/Abp/WorkflowCore/WorkflowParamInput.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore/LINGYUN/Abp/WorkflowCore/WorkflowStepBody.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore/System/ObjectSerializerExtensions.cs
create mode 100644 aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore/System/UtcDateTimeExtensions.cs
create mode 100644 aspnet-core/tests/LINGYUN.Abp.WorkflowCore.Tests/LINGYUN.Abp.WorkflowCore.Tests.csproj
create mode 100644 aspnet-core/tests/LINGYUN.Abp.WorkflowCore.Tests/LINGYUN/Abp/WorkflowCore/AbpWorkflowCoreTestBase.cs
create mode 100644 aspnet-core/tests/LINGYUN.Abp.WorkflowCore.Tests/LINGYUN/Abp/WorkflowCore/AbpWorkflowCoreTestModule.cs
diff --git a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Elasticsearch/LINGYUN.Abp.WorkflowCore.Elasticsearch.csproj b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Elasticsearch/LINGYUN.Abp.WorkflowCore.Elasticsearch.csproj
new file mode 100644
index 000000000..21aa9a59f
--- /dev/null
+++ b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Elasticsearch/LINGYUN.Abp.WorkflowCore.Elasticsearch.csproj
@@ -0,0 +1,12 @@
+
+
+
+ netstandard2.0
+
+
+
+
+
+
+
+
diff --git a/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Elasticsearch/LINGYUN/Abp/WorkflowCore/Elasticsearch/AbpElasticsearchIndexer.cs b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Elasticsearch/LINGYUN/Abp/WorkflowCore/Elasticsearch/AbpElasticsearchIndexer.cs
new file mode 100644
index 000000000..81122060e
--- /dev/null
+++ b/aspnet-core/modules/workflow/LINGYUN.Abp.WorkflowCore.Elasticsearch/LINGYUN/Abp/WorkflowCore/Elasticsearch/AbpElasticsearchIndexer.cs
@@ -0,0 +1,140 @@
+using LINGYUN.Abp.Elasticsearch;
+using LINGYUN.Abp.WorkflowCore.Elasticsearch.Models;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
+using Nest;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Threading.Tasks;
+using WorkflowCore.Interface;
+using WorkflowCore.Models;
+using WorkflowCore.Models.Search;
+
+namespace LINGYUN.Abp.WorkflowCore.Elasticsearch
+{
+ public class AbpElasticsearchIndexer : ISearchIndex
+ {
+ private IElasticClient _client;
+
+ private readonly IElasticsearchClientFactory _elasticsearchClientFactory;
+ private readonly AbpWorkflowCoreElasticsearchOptions _options;
+ private readonly ILogger _logger;
+
+ public AbpElasticsearchIndexer(
+ ILogger logger,
+ IOptions options,
+ IElasticsearchClientFactory elasticsearchClientFactory)
+ {
+ _logger = logger;
+ _options = options.Value;
+ _elasticsearchClientFactory = elasticsearchClientFactory;
+ }
+
+ public async Task IndexWorkflow(WorkflowInstance workflow)
+ {
+ if (_client == null)
+ throw new InvalidOperationException("Not started");
+
+ var denormModel = WorkflowSearchModel.FromWorkflowInstance(workflow);
+
+ var result = await _client.IndexAsync(
+ denormModel,
+ idx => idx.Index(_options.IndexFormat));
+
+ if (!result.ApiCall.Success)
+ {
+ _logger.LogError(default(EventId), result.ApiCall.OriginalException, $"Failed to index workflow {workflow.Id}");
+ throw new ApplicationException($"Failed to index workflow {workflow.Id}", result.ApiCall.OriginalException);
+ }
+ }
+
+ public async Task> Search(string terms, int skip, int take, params SearchFilter[] filters)
+ {
+ if (_client == null)
+ throw new InvalidOperationException("Not started");
+
+ var result = await _client.SearchAsync(s => s
+ .Index(_options.IndexFormat)
+ .Skip(skip)
+ .Take(take)
+ .MinScore(!string.IsNullOrEmpty(terms) ? 0.1 : 0)
+ .Query(query => query
+ .Bool(b => b
+ .Filter(BuildFilterQuery(filters))
+ .Should(
+ should => should.Match(t => t.Field(f => f.Reference).Query(terms).Boost(1.2)),
+ should => should.Match(t => t.Field(f => f.DataTokens).Query(terms).Boost(1.1)),
+ should => should.Match(t => t.Field(f => f.WorkflowDefinitionId).Query(terms).Boost(0.9)),
+ should => should.Match(t => t.Field(f => f.Status).Query(terms).Boost(0.9)),
+ should => should.Match(t => t.Field(f => f.Description).Query(terms))
+ )
+ )
+ )
+ );
+
+ return new Page
+ {
+ Total = result.Total,
+ Data = result.Hits.Select(x => x.Source).Select(x => x.ToSearchResult()).ToList()
+ };
+ }
+
+ public async Task Start()
+ {
+ _client = _elasticsearchClientFactory.Create();
+ var nodeInfo = await _client.Nodes.InfoAsync();
+ if (nodeInfo.Nodes.Values.Any(x => Convert.ToUInt32(x.Version.Split('.')[0]) < 6))
+ throw new NotSupportedException("Elasticsearch verison 6 or greater is required");
+
+ var exists = await _client.Indices.ExistsAsync(_options.IndexFormat);
+ if (!exists.Exists)
+ {
+ await _client.Indices.CreateAsync(_options.IndexFormat);
+ }
+ }
+
+ public Task Stop()
+ {
+ return Task.CompletedTask;
+ }
+
+ private List, QueryContainer>> BuildFilterQuery(SearchFilter[] filters)
+ {
+ var result = new List, QueryContainer>>();
+
+ foreach (var filter in filters)
+ {
+ var field = new Field(filter.Property);
+ if (filter.IsData)
+ {
+ Expression> dataExpr = x => x.Data[filter.DataType.FullName];
+ var fieldExpr = Expression.Convert(filter.Property, typeof(Func