Skip to content

Commit fe78b6b

Browse files
authored
Merge pull request #461 from glucaci/dev
Replce mongo obsolate api and add enum to string convetion
2 parents b4dee83 + 1ef942a commit fe78b6b

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/providers/WorkflowCore.Persistence.MongoDB/Services/MongoPersistenceProvider.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using System.Collections.Generic;
66
using System.Linq;
77
using System.Threading.Tasks;
8+
using MongoDB.Bson;
9+
using MongoDB.Bson.Serialization.Conventions;
810
using MongoDB.Driver.Linq;
911
using WorkflowCore.Interface;
1012
using WorkflowCore.Models;
@@ -24,6 +26,13 @@ public MongoPersistenceProvider(IMongoDatabase database)
2426

2527
static MongoPersistenceProvider()
2628
{
29+
ConventionRegistry.Register(
30+
"workflow.conventions",
31+
new ConventionPack
32+
{
33+
new EnumRepresentationConvention(BsonType.String)
34+
}, t => t.FullName?.StartsWith("WorkflowCore") ?? false);
35+
2736
BsonClassMap.RegisterClassMap<WorkflowInstance>(x =>
2837
{
2938
x.MapIdProperty(y => y.Id)
@@ -73,8 +82,14 @@ static void CreateIndexes(MongoPersistenceProvider instance)
7382
{
7483
if (!indexesCreated)
7584
{
76-
instance.WorkflowInstances.Indexes.CreateOne(Builders<WorkflowInstance>.IndexKeys.Ascending(x => x.NextExecution), new CreateIndexOptions() { Background = true, Name = "idx_nextExec" });
77-
instance.Events.Indexes.CreateOne(Builders<Event>.IndexKeys.Ascending(x => x.IsProcessed), new CreateIndexOptions() { Background = true, Name = "idx_processed" });
85+
instance.WorkflowInstances.Indexes.CreateOne(new CreateIndexModel<WorkflowInstance>(
86+
Builders<WorkflowInstance>.IndexKeys.Ascending(x => x.NextExecution),
87+
new CreateIndexOptions {Background = true, Name = "idx_nextExec"}));
88+
89+
instance.Events.Indexes.CreateOne(new CreateIndexModel<Event>(
90+
Builders<Event>.IndexKeys.Ascending(x => x.IsProcessed),
91+
new CreateIndexOptions {Background = true, Name = "idx_processed"}));
92+
7893
indexesCreated = true;
7994
}
8095
}

0 commit comments

Comments
 (0)